storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/objects/ShareObjectModal.js (about) 1 /* 2 * MinIO Cloud Storage (C) 2018 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import React from "react" 18 import { connect } from "react-redux" 19 import { Modal, ModalHeader, ModalBody } from "react-bootstrap" 20 import CopyToClipboard from "react-copy-to-clipboard" 21 import web from "../web" 22 import * as objectsActions from "./actions" 23 import * as alertActions from "../alert/actions" 24 import { 25 SHARE_OBJECT_EXPIRY_DAYS, 26 SHARE_OBJECT_EXPIRY_HOURS, 27 SHARE_OBJECT_EXPIRY_MINUTES 28 } from "../constants" 29 import QRCode from "react-qr-code"; 30 31 export class ShareObjectModal extends React.Component { 32 constructor(props) { 33 super(props) 34 this.state = { 35 expiry: { 36 days: SHARE_OBJECT_EXPIRY_DAYS, 37 hours: SHARE_OBJECT_EXPIRY_HOURS, 38 minutes: SHARE_OBJECT_EXPIRY_MINUTES 39 } 40 } 41 this.expiryRange = { 42 days: { min: 0, max: 7 }, 43 hours: { min: 0, max: 23 }, 44 minutes: { min: 0, max: 59 } 45 } 46 } 47 updateExpireValue(param, inc) { 48 let expiry = Object.assign({}, this.state.expiry) 49 50 // Not allowing any increments if days is already max 51 if (expiry.days == this.expiryRange["days"].max && inc > 0) { 52 return 53 } 54 55 const { min, max } = this.expiryRange[param] 56 expiry[param] = expiry[param] + inc 57 if (expiry[param] < min || expiry[param] > max) { 58 return 59 } 60 61 if (expiry.days == this.expiryRange["days"].max) { 62 expiry.hours = 0 63 expiry.minutes = 0 64 } else if (expiry.days + expiry.hours + expiry.minutes == 0) { 65 expiry.days = this.expiryRange["days"].max 66 } 67 68 this.setState({ 69 expiry 70 }) 71 72 const { object, shareObject } = this.props 73 shareObject(object.name, expiry.days, expiry.hours, expiry.minutes) 74 } 75 onUrlCopied() { 76 const { showCopyAlert, hideShareObject } = this.props 77 showCopyAlert("Link copied to clipboard!") 78 hideShareObject() 79 } 80 render() { 81 const { shareObjectDetails, hideShareObject } = this.props 82 const url = `${window.location.protocol}//${shareObjectDetails.url}` 83 return ( 84 <Modal 85 show={true} 86 animation={false} 87 onHide={hideShareObject} 88 bsSize="small" 89 > 90 <ModalHeader>Share Object</ModalHeader> 91 <ModalBody> 92 <div className="input-group copy-text"> 93 <QRCode value={url} size={128}/> 94 <label>Shareable Link</label> 95 <input 96 type="text" 97 ref={node => (this.copyTextInput = node)} 98 readOnly="readOnly" 99 value={url} 100 onClick={() => this.copyTextInput.select()} 101 /> 102 </div> 103 {shareObjectDetails.showExpiryDate && ( 104 <div 105 className="input-group" 106 style={{ display: web.LoggedIn() ? "block" : "none" }} 107 > 108 <label>Expires in (Max 7 days)</label> 109 <div className="set-expire"> 110 <div className="set-expire-item"> 111 <i 112 id="increase-days" 113 className="set-expire-increase" 114 onClick={() => this.updateExpireValue("days", 1)} 115 /> 116 <div className="set-expire-title">Days</div> 117 <div className="set-expire-value"> 118 <input 119 ref="expireDays" 120 type="number" 121 min={0} 122 max={7} 123 value={this.state.expiry.days} 124 readOnly="readOnly" 125 /> 126 </div> 127 <i 128 id="decrease-days" 129 className="set-expire-decrease" 130 onClick={() => this.updateExpireValue("days", -1)} 131 /> 132 </div> 133 <div className="set-expire-item"> 134 <i 135 id="increase-hours" 136 className="set-expire-increase" 137 onClick={() => this.updateExpireValue("hours", 1)} 138 /> 139 <div className="set-expire-title">Hours</div> 140 <div className="set-expire-value"> 141 <input 142 ref="expireHours" 143 type="number" 144 min={0} 145 max={23} 146 value={this.state.expiry.hours} 147 readOnly="readOnly" 148 /> 149 </div> 150 <i 151 className="set-expire-decrease" 152 id="decrease-hours" 153 onClick={() => this.updateExpireValue("hours", -1)} 154 /> 155 </div> 156 <div className="set-expire-item"> 157 <i 158 id="increase-minutes" 159 className="set-expire-increase" 160 onClick={() => this.updateExpireValue("minutes", 1)} 161 /> 162 <div className="set-expire-title">Minutes</div> 163 <div className="set-expire-value"> 164 <input 165 ref="expireMins" 166 type="number" 167 min={0} 168 max={59} 169 value={this.state.expiry.minutes} 170 readOnly="readOnly" 171 /> 172 </div> 173 <i 174 id="decrease-minutes" 175 className="set-expire-decrease" 176 onClick={() => this.updateExpireValue("minutes", -1)} 177 /> 178 </div> 179 </div> 180 </div> 181 )} 182 </ModalBody> 183 <div className="modal-footer"> 184 <CopyToClipboard 185 text={url} 186 onCopy={this.onUrlCopied.bind(this)} 187 > 188 <button className="btn btn-success">Copy Link</button> 189 </CopyToClipboard> 190 <button className="btn btn-link" onClick={hideShareObject}> 191 Cancel 192 </button> 193 </div> 194 </Modal> 195 ) 196 } 197 } 198 199 const mapStateToProps = (state, ownProps) => { 200 return { 201 object: ownProps.object, 202 shareObjectDetails: state.objects.shareObject 203 } 204 } 205 206 const mapDispatchToProps = dispatch => { 207 return { 208 shareObject: (object, days, hours, minutes) => 209 dispatch(objectsActions.shareObject(object, days, hours, minutes)), 210 hideShareObject: () => dispatch(objectsActions.hideShareObject()), 211 showCopyAlert: message => 212 dispatch(alertActions.set({ type: "success", message: message })) 213 } 214 } 215 216 export default connect(mapStateToProps, mapDispatchToProps)(ShareObjectModal)