[5/n][project setting ui] MembersTabPanel cleanip (#27)

This commit is contained in:
Vivian Phung 2024-05-14 15:53:52 -04:00 committed by GitHub
commit cdfc72a5a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,23 +1,22 @@
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { useOutletContext } from 'react-router-dom'; import { useOutletContext } from 'react-router-dom';
import toast from 'react-hot-toast';
import { Permission, AddProjectMemberInput, ProjectMember } from 'gql-client'; import { Permission, AddProjectMemberInput, ProjectMember } from 'gql-client';
import {
Chip,
Button,
Typography,
} from '@snowballtools/material-tailwind-react-fork';
import MemberCard from '../../../../../components/projects/project/settings/MemberCard'; import MemberCard from '../../../../../components/projects/project/settings/MemberCard';
import AddMemberDialog from '../../../../../components/projects/project/settings/AddMemberDialog'; import AddMemberDialog from '../../../../../components/projects/project/settings/AddMemberDialog';
import { useGQLClient } from '../../../../../context/GQLClientContext'; import { useGQLClient } from '../../../../../context/GQLClientContext';
import { OutletContextType } from '../../../../../types/types'; import { OutletContextType } from '../../../../../types';
import { useToast } from '../../../../../components/shared/Toast';
import { Button } from 'components/shared/Button';
import { PlusIcon } from 'components/shared/CustomIcon';
import { Badge } from 'components/shared/Badge';
import { Heading } from 'components/shared/Heading';
const FIRST_MEMBER_CARD = 0; const FIRST_MEMBER_CARD = 0;
const MembersTabPanel = () => { const MembersTabPanel = () => {
const client = useGQLClient(); const client = useGQLClient();
const { toast } = useToast();
const { project } = useOutletContext<OutletContextType>(); const { project } = useOutletContext<OutletContextType>();
const [addmemberDialogOpen, setAddMemberDialogOpen] = useState(false); const [addmemberDialogOpen, setAddMemberDialogOpen] = useState(false);
@ -36,9 +35,19 @@ const MembersTabPanel = () => {
if (isProjectMemberAdded) { if (isProjectMemberAdded) {
await fetchProjectMembers(); await fetchProjectMembers();
toast.success('Invitation sent'); toast({
id: 'member_added',
title: 'Member added to project',
variant: 'success',
onDismiss() {},
});
} else { } else {
toast.error('Invitation not sent'); toast({
id: 'member_not_added',
title: 'Invitation not sent',
variant: 'error',
onDismiss() {},
});
} }
}, },
[project], [project],
@ -50,9 +59,19 @@ const MembersTabPanel = () => {
if (isMemberRemoved) { if (isMemberRemoved) {
await fetchProjectMembers(); await fetchProjectMembers();
toast.success('Member removed from project'); toast({
id: 'member_removed',
title: 'Member removed from project',
variant: 'success',
onDismiss() {},
});
} else { } else {
toast.error('Not able to remove member'); toast({
id: 'member_not_removed',
title: 'Not able to remove member',
variant: 'error',
onDismiss() {},
});
} }
}; };
@ -63,9 +82,19 @@ const MembersTabPanel = () => {
if (isProjectMemberUpdated) { if (isProjectMemberUpdated) {
await fetchProjectMembers(); await fetchProjectMembers();
toast.success('Project member permission updated'); toast({
id: 'member_permission_updated',
title: 'Project member permission updated',
variant: 'success',
onDismiss() {},
});
} else { } else {
toast.error('Project member permission not updated'); toast({
id: 'member_permission_not_updated',
title: 'Project member permission not updated',
variant: 'error',
onDismiss() {},
});
} }
}, },
[], [],
@ -76,27 +105,25 @@ const MembersTabPanel = () => {
}, [project.id, fetchProjectMembers]); }, [project.id, fetchProjectMembers]);
return ( return (
<div className="p-2 mb-20"> <div className="space-y-3 px-2">
<div className="flex justify-between mb-2"> <div className="flex justify-between">
<div className="flex"> <div className="flex space-x-2">
<Typography variant="h6">Members</Typography> <Heading className="text-sky-950 text-lg font-medium leading-normal">
<div> Collaborators
<Chip </Heading>
className="normal-case ml-3 font-normal" <Badge size="sm" variant="inset">
size="sm" {projectMembers.length + 1}
value={projectMembers.length + 1} </Badge>
/>
</div> </div>
</div>
<div>
<Button <Button
size="sm" size="md"
onClick={() => setAddMemberDialogOpen((preVal) => !preVal)} onClick={() => setAddMemberDialogOpen((preVal) => !preVal)}
leftIcon={<PlusIcon />}
variant="secondary"
> >
+ Add member Add member
</Button> </Button>
</div> </div>
</div>
<MemberCard <MemberCard
member={project.owner} member={project.owner}
isFirstCard={true} isFirstCard={true}