@@ -15,7 +15,7 @@ import { ChainIcon, DeleteIcon, LockIcon, PublicIcon } from '../../icons';
15
15
import { useTheme } from '../../theme' ;
16
16
import { BLACK , WHITE } from '../../theme/colors' ;
17
17
import { CustomTooltip } from '../CustomTooltip' ;
18
- import { Modal , ModalBody , ModalButtonPrimary , ModalButtonSecondary , ModalFooter } from '../Modal' ;
18
+ import { Modal , ModalBody , ModalButtonSecondary , ModalFooter } from '../Modal' ;
19
19
import UserShareSearch from '../UserSearchField/UserSearchField' ;
20
20
import {
21
21
CustomDialogContentText ,
@@ -26,27 +26,14 @@ import {
26
26
ListWrapper ,
27
27
VisibilityIconWrapper
28
28
} from './style' ;
29
- import { TypedMutationTrigger , TypedUseQuery } from '@reduxjs/toolkit/dist/query/react' ;
30
29
31
30
const options = {
32
31
PUBLIC : 'Anyone with the link can edit' ,
33
32
PRIVATE : 'Only people with access can open with the link'
34
33
} ;
35
34
36
- const SHARE_MODE = {
37
- PRIVATE : 'private' ,
38
- PUBLIC : 'public'
39
- } ;
40
-
41
- interface User {
42
- id : string ;
43
- user_id : string ;
44
- first_name : string ;
45
- last_name : string ;
46
- email : string ;
47
- avatar_url ?: string ;
48
- deleted_at ?: { Valid : boolean } ;
49
- }
35
+ const SHARE_MODE = VISIBILITY
36
+ import { canShareResourceWithNewUsers , canUpdateResourceVisibility , User } from '../../utils/permissions' ;
50
37
51
38
interface AccessListProps {
52
39
accessList : User [ ] ;
@@ -170,8 +157,8 @@ type ResourceAccessArg = {
170
157
} ;
171
158
172
159
173
- import type { MutationTrigger } from '@reduxjs/toolkit/query/react' ;
174
160
import { startCase } from 'lodash' ;
161
+ import { VISIBILITY } from '../../constants/constants' ;
175
162
176
163
interface ShareModalProps {
177
164
/** Function to close the share modal */
@@ -186,28 +173,17 @@ interface ShareModalProps {
186
173
fetchAccessActors : ( ) => Promise < User [ ] > ;
187
174
/** Optional URL of the host application. Defaults to `null` if not provided */
188
175
hostURL ?: string | null ;
189
- /**
190
- * Optional URL of the resource. Defaults to empty string if not provided
191
- * Resource URL will be the URL which user will copy with Copy Link Button
192
- */
193
- resourceURL ?: string ;
194
- /** Optional flag to disable the visibility selector. Defaults to `false` if not provided */
195
- isVisibilitySelectorDisabled ?: boolean ;
196
- /**
197
- * Function to fetch user suggestions based on the input value.
198
- * @param {string } value - The input value for which suggestions are to be fetched.
199
- * @returns {Promise<User[]> } A promise that resolves to an array of user suggestions.
200
- */
201
- fetchSuggestions : ( value : string ) => Promise < User [ ] > ;
202
- handleCopy : ( ) => void ;
203
176
handleUpdateVisibility : ( value : string ) => Promise < { error : string } > ,
204
177
handleShareWithNewUsers : ( newUsers : User [ ] ) => Promise < { error : string } > ,
205
178
canShareWithNewUsers : boolean ,
206
179
handleRevokeAccess : ( revokedUsser : User [ ] ) => Promise < { error : string } >
207
180
canRevokeAccess : boolean ,
208
- resourceAccessMutator : MutationTrigger < ResourceAccessArg > ,
181
+ resourceAccessMutator : any ,
209
182
notify : ( { message, event_type } : { message : string , event_type : "success" | "error" } ) => void ,
210
183
useGetAllUsersQuery : any ,
184
+ shareableLink :string ,
185
+ mesheryURL : string , // url to hosted meshery
186
+ currentUser : User ,
211
187
}
212
188
213
189
/**
@@ -221,14 +197,12 @@ const ShareModal: React.FC<ShareModalProps> = ({
221
197
ownerData,
222
198
fetchAccessActors,
223
199
hostURL = null ,
224
- handleCopy ,
200
+ currentUser ,
225
201
handleUpdateVisibility,
226
- canShareWithNewUsers,
227
- isVisibilitySelectorDisabled = false ,
228
- fetchSuggestions,
229
202
resourceAccessMutator,
230
203
notify,
231
204
useGetAllUsersQuery,
205
+ shareableLink
232
206
233
207
} : ShareModalProps ) : JSX . Element => {
234
208
const theme = useTheme ( ) ;
@@ -237,9 +211,21 @@ const ShareModal: React.FC<ShareModalProps> = ({
237
211
const [ resourceVisibility , setVisibility ] = useState ( selectedResource . visibility )
238
212
const [ isUpdatingVisibility , setUpdatingVisibility ] = useState ( false )
239
213
214
+ const userCanUpdateVisibility = canUpdateResourceVisibility ( selectedResource , currentUser , ownerData )
215
+ const userCanShareWithNewUsers = canShareResourceWithNewUsers ( selectedResource , currentUser , ownerData )
240
216
241
217
242
218
219
+ const handleCopy = ( ) => {
220
+ // const shareableLink = getShareableResourceRoute(dataName,selectedResource.id,selectedResource.name)
221
+ console . log ( "shareableLink" , shareableLink )
222
+ navigator . clipboard . writeText ( shareableLink ) ;
223
+ notify ( {
224
+ message : "Link copied to clipboard" ,
225
+ event_type : "success"
226
+ } ) ;
227
+ } ;
228
+
243
229
const resourceType = dataName === "design" ? "pattern" : dataName ;
244
230
245
231
@@ -397,22 +383,10 @@ const ShareModal: React.FC<ShareModalProps> = ({
397
383
>
398
384
< ModalBody >
399
385
< UserShareSearch
400
- setUsersData = { setShareUserData }
401
386
usersData = { shareUserData }
402
- label = "Search Users"
403
387
shareWithNewUsers = { handleShareWithNewUsers }
404
- // isSharing={isSharing}
405
- disabled = { canShareWithNewUsers }
406
- customUsersList = {
407
- < AccessList
408
- accessList = { shareUserData }
409
- ownerData = { ownerData }
410
- handleDelete = { handleDelete }
411
- hostURL = { hostURL }
412
- />
413
- }
388
+ disabled = { ! userCanShareWithNewUsers }
414
389
useGetAllUsersQuery = { useGetAllUsersQuery }
415
- fetchSuggestions = { fetchSuggestions }
416
390
/>
417
391
418
392
< AccessList
@@ -463,7 +437,7 @@ const ShareModal: React.FC<ShareModalProps> = ({
463
437
onClose = { handleMenuClose }
464
438
onOpen = { ( ) => setMenu ( true ) }
465
439
onChange = { updateVisisbility }
466
- disabled = { isVisibilitySelectorDisabled || isUpdatingVisibility }
440
+ disabled = { ! userCanUpdateVisibility || isUpdatingVisibility }
467
441
>
468
442
{ Object . values ( SHARE_MODE ) . map ( ( option ) => (
469
443
< MenuItem
@@ -513,15 +487,7 @@ const ShareModal: React.FC<ShareModalProps> = ({
513
487
</ IconButtonWrapper >
514
488
< Typography > Copy Link</ Typography >
515
489
</ ModalButtonSecondary >
516
- { /* <ModalButtonPrimary
517
- disabled={isShareDisabled()}
518
- variant="contained"
519
- color="primary"
520
- onClick={() => handleShare(shareUserData, selectedOption)}
521
- >
522
- Share
523
- </ModalButtonPrimary> */ }
524
- </ div >
490
+ </ div >
525
491
</ ModalFooter >
526
492
</ Modal >
527
493
</ div >
0 commit comments