Remove Participant Method added

This commit is contained in:
jubitjohn 2023-07-05 15:57:59 +05:30
parent 5a2a46a153
commit 4db32e1a1d
4 changed files with 44 additions and 16 deletions

View file

@ -24,13 +24,11 @@ export function CollaboratorParticipants({ collection, onRootClose }: Iprops) {
const [collaborators, setCollaborators] = useState([]); const [collaborators, setCollaborators] = useState([]);
useEffect(() => { useEffect(() => {
collection.sharees?.map((sharee) => { const collaboratorEmails =
if (sharee.role === 'COLLABORATOR') collection.sharees
setCollaborators((prevViewers) => [ ?.filter((sharee) => sharee.role === 'COLLABORATOR')
...prevViewers, .map((sharee) => sharee.email) || [];
sharee.email, setCollaborators(collaboratorEmails);
]);
});
}, [collection.sharees]); }, [collection.sharees]);
return ( return (

View file

@ -1,11 +1,13 @@
import { Box } from '@mui/material'; import { Box } from '@mui/material';
import React, { useContext } from 'react';
import React from 'react';
// import { t } from 'i18next'; // import { t } from 'i18next';
import { Collection } from 'types/collection'; import { Collection } from 'types/collection';
import { OwnerParticipant } from './OwnerParticipant'; import { OwnerParticipant } from './OwnerParticipant';
import { ViewerParticipants } from './ViewerParticipants'; import { ViewerParticipants } from './ViewerParticipants';
import { CollaboratorParticipants } from './CollaboratorParticipants'; import { CollaboratorParticipants } from './CollaboratorParticipants';
import { unshareCollection } from 'services/collectionService';
import { AppContext } from 'pages/_app';
import { GalleryContext } from 'pages/gallery';
interface Iprops { interface Iprops {
collection: Collection; collection: Collection;
@ -16,6 +18,18 @@ export function ManageParticipantsList({ collection, onRootClose }: Iprops) {
if (!collection.sharees?.length) { if (!collection.sharees?.length) {
return <></>; return <></>;
} }
const appContext = useContext(AppContext);
const galleryContext = useContext(GalleryContext);
const collectionUnshare = async (email: string) => {
try {
appContext.startLoading();
await unshareCollection(collection, email);
await galleryContext.syncWithRemote(false, true);
} finally {
appContext.finishLoading();
}
};
return ( return (
<Box mb={3}> <Box mb={3}>
@ -25,7 +39,8 @@ export function ManageParticipantsList({ collection, onRootClose }: Iprops) {
onRootClose={onRootClose}></CollaboratorParticipants> onRootClose={onRootClose}></CollaboratorParticipants>
<ViewerParticipants <ViewerParticipants
collection={collection} collection={collection}
onRootClose={onRootClose}></ViewerParticipants> onRootClose={onRootClose}
collectionUnshare={collectionUnshare}></ViewerParticipants>
</Box> </Box>
); );
} }

View file

@ -18,6 +18,7 @@ interface Iprops {
onClose: () => void; onClose: () => void;
onRootClose: () => void; onRootClose: () => void;
selectedEmail: string; selectedEmail: string;
collectionUnshare: (email: string) => Promise<void>;
} }
export default function ManageParticipantsRole({ export default function ManageParticipantsRole({
@ -26,6 +27,7 @@ export default function ManageParticipantsRole({
onClose, onClose,
onRootClose, onRootClose,
selectedEmail, selectedEmail,
collectionUnshare,
}: Iprops) { }: Iprops) {
const handleDrawerClose: DialogProps['onClose'] = (_, reason) => { const handleDrawerClose: DialogProps['onClose'] = (_, reason) => {
if (reason === 'backdropClick') { if (reason === 'backdropClick') {
@ -34,6 +36,12 @@ export default function ManageParticipantsRole({
onClose(); onClose();
} }
}; };
const handleClick = () => {
collectionUnshare(selectedEmail);
onClose();
};
console.log('collection Clicked', collection, selectedEmail); console.log('collection Clicked', collection, selectedEmail);
return ( return (
<> <>
@ -88,7 +96,7 @@ export default function ManageParticipantsRole({
// //
color="error" color="error"
fontWeight="normal" fontWeight="normal"
onClick={() => console.log('clicked')} onClick={handleClick}
label={'Remove'} label={'Remove'}
startIcon={ startIcon={
<BlockIcon <BlockIcon

View file

@ -14,9 +14,14 @@ import ManageParticipantsRole from './ManageParticipantsRole';
interface Iprops { interface Iprops {
collection: Collection; collection: Collection;
onRootClose: () => void; onRootClose: () => void;
collectionUnshare: (email: string) => Promise<void>;
} }
export function ViewerParticipants({ collection, onRootClose }: Iprops) { export function ViewerParticipants({
collection,
onRootClose,
collectionUnshare,
}: Iprops) {
if (!collection.sharees?.length) { if (!collection.sharees?.length) {
return <></>; return <></>;
} }
@ -34,10 +39,11 @@ export function ViewerParticipants({ collection, onRootClose }: Iprops) {
}; };
useEffect(() => { useEffect(() => {
collection.sharees?.map((sharee) => { const viewersEmails =
if (sharee.role === 'VIEWER') collection.sharees
setViewers((prevViewers) => [...prevViewers, sharee.email]); ?.filter((sharee) => sharee.role === 'VIEWER')
}); .map((sharee) => sharee.email) || [];
setViewers(viewersEmails);
}, [collection.sharees]); }, [collection.sharees]);
return ( return (
@ -80,6 +86,7 @@ export function ViewerParticipants({ collection, onRootClose }: Iprops) {
</Box> </Box>
</Stack> </Stack>
<ManageParticipantsRole <ManageParticipantsRole
collectionUnshare={collectionUnshare}
open={participantRoleView} open={participantRoleView}
collection={collection} collection={collection}
onRootClose={onRootClose} onRootClose={onRootClose}