1+ import { ContentCopy , Visibility , VisibilityOff } from "@mui/icons-material" ;
12import {
23 Box ,
34 Dialog ,
45 DialogContent ,
56 DialogContentText ,
67 DialogTitle ,
8+ FormControl ,
9+ Grid ,
10+ IconButton ,
11+ InputAdornment ,
12+ InputLabel ,
13+ OutlinedInput ,
14+ Popover ,
715 Typography ,
816} from "@mui/material" ;
17+ import MyButton from "components/common/MyButton" ;
18+ import { useMemo , useState } from "react" ;
919import { useSelector } from "react-redux" ;
20+ import { toast } from "react-toastify" ;
1021import { selectorUserInfo } from "reduxes/auth/selector" ;
22+ import {
23+ selectorCurrentProjectId ,
24+ selectorCurrentProjectName ,
25+ } from "reduxes/project/selector" ;
26+ import { projectApi } from "services" ;
27+ import { copy } from "utils/clipboard" ;
28+
29+ const DEFAULT_UPLOAD_TOKEN_VALUE = "Get your upload token now!" ;
30+
31+ const copyPopoverTextId = "copy-popover-text" ;
1132
1233const UploadGuideDialog = function ( {
1334 isOpen,
@@ -20,6 +41,61 @@ const UploadGuideDialog = function ({
2041 const generalStyle = { margin : 0 } ;
2142 const commentStyle = { ...generalStyle , color : "#858e93" } ;
2243 const colorStringStyle = { color : "#98cae8" } ;
44+
45+ const [ isShowToken , setIsShowToken ] = useState ( false ) ;
46+ const [ uploadTokenValue , setUploadTokenValue ] = useState (
47+ DEFAULT_UPLOAD_TOKEN_VALUE
48+ ) ;
49+
50+ const [ isGettingToken , setIsGettingToken ] = useState ( false ) ;
51+
52+ const currentProjectId = useSelector ( selectorCurrentProjectId ) ;
53+ const currentProjectName = useSelector ( selectorCurrentProjectName ) ;
54+
55+ const [ copiedPopoverAnchorEl , setCopiedPopoverAnchorEl ] =
56+ useState < HTMLButtonElement | null > ( null ) ;
57+ const isShowCopiedPopover = useMemo (
58+ ( ) => Boolean ( copiedPopoverAnchorEl ) ,
59+ [ copiedPopoverAnchorEl ]
60+ ) ;
61+ const handleCloseCopiedPopover = ( ) => {
62+ setCopiedPopoverAnchorEl ( null ) ;
63+ } ;
64+
65+ const handleClickShowToken = ( ) => {
66+ setIsShowToken ( ! isShowToken ) ;
67+ } ;
68+
69+ const handleClickCopy = async (
70+ event : React . MouseEvent < HTMLButtonElement >
71+ ) => {
72+ const isCopied = await copy ( uploadTokenValue ) ;
73+
74+ if ( isCopied ) {
75+ setCopiedPopoverAnchorEl ( event . target as HTMLButtonElement ) ;
76+ setTimeout ( handleCloseCopiedPopover , 3000 ) ;
77+ } else {
78+ toast . error ( "Unable to copy." ) ;
79+ }
80+ } ;
81+
82+ const handleGetUploadToken = ( ) => {
83+ setIsGettingToken ( true ) ;
84+ projectApi
85+ . getUploadToken ( {
86+ projectId : currentProjectId ,
87+ projectName : currentProjectName ,
88+ } )
89+ . then ( ( getUploadTokenResponse : any ) => {
90+ setIsGettingToken ( false ) ;
91+ if ( getUploadTokenResponse && getUploadTokenResponse . error === false ) {
92+ setUploadTokenValue ( getUploadTokenResponse . data . token ) ;
93+ } else {
94+ toast . error ( "Unable to get upload token. Please try again later!" ) ;
95+ }
96+ } ) ;
97+ } ;
98+
2399 return (
24100 < Dialog fullWidth maxWidth = "md" open = { isOpen } onClose = { onClose } >
25101 < DialogTitle sx = { { p : 4 } } >
@@ -53,23 +129,79 @@ const UploadGuideDialog = function ({
53129 # upload your dataset using the following command
54130 </ p >
55131 < p style = { commentStyle } >
56- # (don't forget to set `path_to_your_dataset`)
132+ # (don't forget to set `path_to_your_dataset`) daita
133+ my-folder
57134 </ p >
58135 < p style = { { ...generalStyle , whiteSpace : "nowrap" } } >
59- daita token=
60- < span style = { colorStringStyle } >
61- 'd478a...'
62- </ span > { " " }
63- dataset_id=
64- < span style = { colorStringStyle } >
65- '6225d1...'
66- </ span > { " " }
67- input_dir='path_to_your_dataset'
136+ daita --dir{ " " }
137+ < span style = { colorStringStyle } > path_to_your_dataset</ span > { " " }
138+ --daita_token{ " " }
139+ < span style = { colorStringStyle } > your_upload_token</ span >
68140 </ p >
69141 </ Box >
70142 </ Typography >
71143 </ Typography >
72144 </ DialogContentText >
145+ < Box mt = { 4 } >
146+ < Grid container columnSpacing = { 1 } alignItems = "center" >
147+ < Grid item xs = { 9 } >
148+ < FormControl variant = "outlined" fullWidth >
149+ < InputLabel > Upload Token</ InputLabel >
150+ < OutlinedInput
151+ type = { isShowToken ? "text" : "password" }
152+ value = { uploadTokenValue }
153+ readOnly
154+ disabled = { isGettingToken }
155+ fullWidth
156+ endAdornment = {
157+ < InputAdornment position = "end" >
158+ < IconButton
159+ id = "copyPopoverTextId"
160+ sx = { { mr : 1 } }
161+ onClick = { handleClickCopy }
162+ edge = "end"
163+ >
164+ < ContentCopy />
165+ </ IconButton >
166+ < Popover
167+ id = { copyPopoverTextId }
168+ open = { isShowCopiedPopover }
169+ anchorEl = { copiedPopoverAnchorEl }
170+ onClose = { handleCloseCopiedPopover }
171+ anchorOrigin = { {
172+ vertical : "bottom" ,
173+ horizontal : "left" ,
174+ } }
175+ >
176+ < Typography sx = { { p : 1 } } variant = "subtitle2" >
177+ Copied!
178+ </ Typography >
179+ </ Popover >
180+ < IconButton
181+ onClick = { handleClickShowToken }
182+ onMouseDown = { handleClickShowToken }
183+ edge = "end"
184+ >
185+ { isShowToken ? < VisibilityOff /> : < Visibility /> }
186+ </ IconButton >
187+ </ InputAdornment >
188+ }
189+ label = "Upload Token"
190+ />
191+ </ FormControl >
192+ </ Grid >
193+ < Grid item xs = { 3 } >
194+ < MyButton
195+ fullWidth
196+ variant = "contained"
197+ isLoading = { isGettingToken }
198+ onClick = { handleGetUploadToken }
199+ >
200+ Get Upload Token
201+ </ MyButton >
202+ </ Grid >
203+ </ Grid >
204+ </ Box >
73205 </ DialogContent >
74206 </ Dialog >
75207 ) ;
0 commit comments