Compare commits

...

1 Commits

Author SHA1 Message Date
Vivian Phung
69cb63acc5 Collaborators cleanup 2024-05-22 18:56:42 +00:00
2 changed files with 40 additions and 35 deletions

View File

@ -1,13 +1,13 @@
import { useCallback } from 'react';
import { useForm } from 'react-hook-form';
import { AddProjectMemberInput, Permission } from 'gql-client';
import { Typography } from '@snowballtools/material-tailwind-react-fork';
import { Button } from 'components/shared/Button';
import { Modal } from 'components/shared/Modal';
import { Input } from 'components/shared/Input';
import { Checkbox } from 'components/shared/Checkbox';
import { Select, SelectOption } from 'components/shared/Select';
import { AddProjectMemberInput, Permission } from 'gql-client';
interface AddMemberDialogProp {
open: boolean;
@ -17,18 +17,30 @@ interface AddMemberDialogProp {
interface formData {
emailAddress: string;
permissions: {
view: boolean;
edit: boolean;
};
canEdit: boolean;
}
const permissionViewOptions: SelectOption = {
value: Permission.View,
label: Permission.View,
};
const permissionEditOptions: SelectOption = {
value: Permission.Edit,
label: Permission.Edit,
};
const permissionsDropdownOptions: SelectOption[] = [
permissionViewOptions,
permissionEditOptions,
];
const AddMemberDialog = ({
open,
handleOpen,
handleAddMember,
}: AddMemberDialogProp) => {
const {
watch,
setValue,
handleSubmit,
register,
reset,
@ -36,10 +48,7 @@ const AddMemberDialog = ({
} = useForm({
defaultValues: {
emailAddress: '',
permissions: {
view: true,
edit: false,
},
canEdit: false,
},
});
@ -47,11 +56,7 @@ const AddMemberDialog = ({
reset();
handleOpen();
const permissions = Object.entries(data.permissions)
.filter(([, value]) => value)
.map(
([key]) => key.charAt(0).toUpperCase() + key.slice(1),
) as Permission[];
const permissions = [data.canEdit ? Permission.Edit : Permission.View];
await handleAddMember({ email: data.emailAddress, permissions });
}, []);
@ -72,19 +77,19 @@ const AddMemberDialog = ({
required: 'email field cannot be empty',
})}
/>
<Typography variant="small">Permissions</Typography>
<Typography variant="small">
You can change this later if required.
</Typography>
<Checkbox
label={Permission.View}
{...register(`permissions.view`)}
color="blue"
/>
<Checkbox
label={Permission.Edit}
{...register(`permissions.edit`)}
color="blue"
<Select
label="Permissions"
description="You can change this later if required."
options={permissionsDropdownOptions}
value={
watch('canEdit') ? permissionEditOptions : permissionViewOptions
}
onChange={(value) =>
setValue(
'canEdit',
(value as SelectOption)!.value === Permission.Edit,
)
}
/>
</Modal.Body>
<Modal.Footer>

View File

@ -16,7 +16,7 @@ const FIRST_MEMBER_CARD = 0;
const CollaboratorsTabPanel = () => {
const client = useGQLClient();
const { toast } = useToast();
const { toast, dismiss } = useToast();
const { project } = useOutletContext<OutletContextType>();
const [addmemberDialogOpen, setAddMemberDialogOpen] = useState(false);
@ -39,14 +39,14 @@ const CollaboratorsTabPanel = () => {
id: 'member_added',
title: 'Member added to project',
variant: 'success',
onDismiss() {},
onDismiss: dismiss,
});
} else {
toast({
id: 'member_not_added',
title: 'Invitation not sent',
variant: 'error',
onDismiss() {},
onDismiss: dismiss,
});
}
},
@ -63,14 +63,14 @@ const CollaboratorsTabPanel = () => {
id: 'member_removed',
title: 'Member removed from project',
variant: 'success',
onDismiss() {},
onDismiss: dismiss,
});
} else {
toast({
id: 'member_not_removed',
title: 'Not able to remove member',
variant: 'error',
onDismiss() {},
onDismiss: dismiss,
});
}
};
@ -86,14 +86,14 @@ const CollaboratorsTabPanel = () => {
id: 'member_permission_updated',
title: 'Project member permission updated',
variant: 'success',
onDismiss() {},
onDismiss: dismiss,
});
} else {
toast({
id: 'member_permission_not_updated',
title: 'Project member permission not updated',
variant: 'error',
onDismiss() {},
onDismiss: dismiss,
});
}
},