@@ -15,7 +15,7 @@ import { ChainIcon, DeleteIcon, LockIcon, PublicIcon } from '../../icons';
1515import { useTheme } from '../../theme' ;
1616import { BLACK , WHITE } from '../../theme/colors' ;
1717import { CustomTooltip } from '../CustomTooltip' ;
18- import { Modal , ModalBody , ModalButtonPrimary , ModalButtonSecondary , ModalFooter } from '../Modal' ;
18+ import { Modal , ModalBody , ModalButtonSecondary , ModalFooter } from '../Modal' ;
1919import UserShareSearch from '../UserSearchField/UserSearchField' ;
2020import {
2121 CustomDialogContentText ,
@@ -26,27 +26,14 @@ import {
2626 ListWrapper ,
2727 VisibilityIconWrapper
2828} from './style' ;
29- import { TypedMutationTrigger , TypedUseQuery } from '@reduxjs/toolkit/dist/query/react' ;
3029
3130const options = {
3231 PUBLIC : 'Anyone with the link can edit' ,
3332 PRIVATE : 'Only people with access can open with the link'
3433} ;
3534
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' ;
5037
5138interface AccessListProps {
5239 accessList : User [ ] ;
@@ -170,8 +157,8 @@ type ResourceAccessArg = {
170157} ;
171158
172159
173- import type { MutationTrigger } from '@reduxjs/toolkit/query/react' ;
174160import { startCase } from 'lodash' ;
161+ import { VISIBILITY } from '../../constants/constants' ;
175162
176163interface ShareModalProps {
177164 /** Function to close the share modal */
@@ -186,28 +173,17 @@ interface ShareModalProps {
186173 fetchAccessActors : ( ) => Promise < User [ ] > ;
187174 /** Optional URL of the host application. Defaults to `null` if not provided */
188175 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 ;
203176 handleUpdateVisibility : ( value : string ) => Promise < { error : string } > ,
204177 handleShareWithNewUsers : ( newUsers : User [ ] ) => Promise < { error : string } > ,
205178 canShareWithNewUsers : boolean ,
206179 handleRevokeAccess : ( revokedUsser : User [ ] ) => Promise < { error : string } >
207180 canRevokeAccess : boolean ,
208- resourceAccessMutator : MutationTrigger < ResourceAccessArg > ,
181+ resourceAccessMutator : any ,
209182 notify : ( { message, event_type } : { message : string , event_type : "success" | "error" } ) => void ,
210183 useGetAllUsersQuery : any ,
184+ shareableLink :string ,
185+ mesheryURL : string , // url to hosted meshery
186+ currentUser : User ,
211187}
212188
213189/**
@@ -221,14 +197,12 @@ const ShareModal: React.FC<ShareModalProps> = ({
221197 ownerData,
222198 fetchAccessActors,
223199 hostURL = null ,
224- handleCopy ,
200+ currentUser ,
225201 handleUpdateVisibility,
226- canShareWithNewUsers,
227- isVisibilitySelectorDisabled = false ,
228- fetchSuggestions,
229202 resourceAccessMutator,
230203 notify,
231204 useGetAllUsersQuery,
205+ shareableLink
232206
233207} : ShareModalProps ) : JSX . Element => {
234208 const theme = useTheme ( ) ;
@@ -237,9 +211,21 @@ const ShareModal: React.FC<ShareModalProps> = ({
237211 const [ resourceVisibility , setVisibility ] = useState ( selectedResource . visibility )
238212 const [ isUpdatingVisibility , setUpdatingVisibility ] = useState ( false )
239213
214+ const userCanUpdateVisibility = canUpdateResourceVisibility ( selectedResource , currentUser , ownerData )
215+ const userCanShareWithNewUsers = canShareResourceWithNewUsers ( selectedResource , currentUser , ownerData )
240216
241217
242218
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+
243229 const resourceType = dataName === "design" ? "pattern" : dataName ;
244230
245231
@@ -397,22 +383,10 @@ const ShareModal: React.FC<ShareModalProps> = ({
397383 >
398384 < ModalBody >
399385 < UserShareSearch
400- setUsersData = { setShareUserData }
401386 usersData = { shareUserData }
402- label = "Search Users"
403387 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 }
414389 useGetAllUsersQuery = { useGetAllUsersQuery }
415- fetchSuggestions = { fetchSuggestions }
416390 />
417391
418392 < AccessList
@@ -463,7 +437,7 @@ const ShareModal: React.FC<ShareModalProps> = ({
463437 onClose = { handleMenuClose }
464438 onOpen = { ( ) => setMenu ( true ) }
465439 onChange = { updateVisisbility }
466- disabled = { isVisibilitySelectorDisabled || isUpdatingVisibility }
440+ disabled = { ! userCanUpdateVisibility || isUpdatingVisibility }
467441 >
468442 { Object . values ( SHARE_MODE ) . map ( ( option ) => (
469443 < MenuItem
@@ -513,15 +487,7 @@ const ShareModal: React.FC<ShareModalProps> = ({
513487 </ IconButtonWrapper >
514488 < Typography > Copy Link</ Typography >
515489 </ 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 >
525491 </ ModalFooter >
526492 </ Modal >
527493 </ div >
0 commit comments