mirror of
https://github.com/snowball-tools/snowballtools-base.git
synced 2024-12-22 20:47:44 +00:00
Refactor: Collaborator Project Settings (#197)
### TL;DR AddMemberDialog component now uses a Select dropdown for permissions instead of Checkboxes. CollaboratorsTabPanel now includes dismiss functionality for toasts. ### What changed? - Updated AddMemberDialog to use a Select dropdown for permissions - Added dismiss functionality for toasts in CollaboratorsTabPanel ### How to test? Test the functionality of selecting permissions using the dropdown and toast dismissal in CollaboratorsTabPanel. ### Why make this change? To improve user experience and UI consistency in permissions selection and toast management.
This commit is contained in:
parent
306d3235b3
commit
b35f4033c5
@ -1,13 +1,13 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { AddProjectMemberInput, Permission } from 'gql-client';
|
|
||||||
|
|
||||||
import { Typography } from '@snowballtools/material-tailwind-react-fork';
|
import { Typography } from '@snowballtools/material-tailwind-react-fork';
|
||||||
|
|
||||||
import { Button } from 'components/shared/Button';
|
import { Button } from 'components/shared/Button';
|
||||||
import { Modal } from 'components/shared/Modal';
|
import { Modal } from 'components/shared/Modal';
|
||||||
import { Input } from 'components/shared/Input';
|
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 {
|
interface AddMemberDialogProp {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@ -17,18 +17,30 @@ interface AddMemberDialogProp {
|
|||||||
|
|
||||||
interface formData {
|
interface formData {
|
||||||
emailAddress: string;
|
emailAddress: string;
|
||||||
permissions: {
|
canEdit: boolean;
|
||||||
view: boolean;
|
|
||||||
edit: 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 = ({
|
const AddMemberDialog = ({
|
||||||
open,
|
open,
|
||||||
handleOpen,
|
handleOpen,
|
||||||
handleAddMember,
|
handleAddMember,
|
||||||
}: AddMemberDialogProp) => {
|
}: AddMemberDialogProp) => {
|
||||||
const {
|
const {
|
||||||
|
watch,
|
||||||
|
setValue,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
register,
|
register,
|
||||||
reset,
|
reset,
|
||||||
@ -36,10 +48,7 @@ const AddMemberDialog = ({
|
|||||||
} = useForm({
|
} = useForm({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
emailAddress: '',
|
emailAddress: '',
|
||||||
permissions: {
|
canEdit: false,
|
||||||
view: true,
|
|
||||||
edit: false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -47,11 +56,7 @@ const AddMemberDialog = ({
|
|||||||
reset();
|
reset();
|
||||||
handleOpen();
|
handleOpen();
|
||||||
|
|
||||||
const permissions = Object.entries(data.permissions)
|
const permissions = [data.canEdit ? Permission.Edit : Permission.View];
|
||||||
.filter(([, value]) => value)
|
|
||||||
.map(
|
|
||||||
([key]) => key.charAt(0).toUpperCase() + key.slice(1),
|
|
||||||
) as Permission[];
|
|
||||||
|
|
||||||
await handleAddMember({ email: data.emailAddress, permissions });
|
await handleAddMember({ email: data.emailAddress, permissions });
|
||||||
}, []);
|
}, []);
|
||||||
@ -72,19 +77,19 @@ const AddMemberDialog = ({
|
|||||||
required: 'email field cannot be empty',
|
required: 'email field cannot be empty',
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<Typography variant="small">Permissions</Typography>
|
<Select
|
||||||
<Typography variant="small">
|
label="Permissions"
|
||||||
You can change this later if required.
|
description="You can change this later if required."
|
||||||
</Typography>
|
options={permissionsDropdownOptions}
|
||||||
<Checkbox
|
value={
|
||||||
label={Permission.View}
|
watch('canEdit') ? permissionEditOptions : permissionViewOptions
|
||||||
{...register(`permissions.view`)}
|
}
|
||||||
color="blue"
|
onChange={(value) =>
|
||||||
/>
|
setValue(
|
||||||
<Checkbox
|
'canEdit',
|
||||||
label={Permission.Edit}
|
(value as SelectOption)!.value === Permission.Edit,
|
||||||
{...register(`permissions.edit`)}
|
)
|
||||||
color="blue"
|
}
|
||||||
/>
|
/>
|
||||||
</Modal.Body>
|
</Modal.Body>
|
||||||
<Modal.Footer>
|
<Modal.Footer>
|
||||||
|
@ -16,7 +16,7 @@ const FIRST_MEMBER_CARD = 0;
|
|||||||
|
|
||||||
const CollaboratorsTabPanel = () => {
|
const CollaboratorsTabPanel = () => {
|
||||||
const client = useGQLClient();
|
const client = useGQLClient();
|
||||||
const { toast } = useToast();
|
const { toast, dismiss } = useToast();
|
||||||
const { project } = useOutletContext<OutletContextType>();
|
const { project } = useOutletContext<OutletContextType>();
|
||||||
|
|
||||||
const [addmemberDialogOpen, setAddMemberDialogOpen] = useState(false);
|
const [addmemberDialogOpen, setAddMemberDialogOpen] = useState(false);
|
||||||
@ -39,14 +39,14 @@ const CollaboratorsTabPanel = () => {
|
|||||||
id: 'member_added',
|
id: 'member_added',
|
||||||
title: 'Member added to project',
|
title: 'Member added to project',
|
||||||
variant: 'success',
|
variant: 'success',
|
||||||
onDismiss() {},
|
onDismiss: dismiss,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
toast({
|
toast({
|
||||||
id: 'member_not_added',
|
id: 'member_not_added',
|
||||||
title: 'Invitation not sent',
|
title: 'Invitation not sent',
|
||||||
variant: 'error',
|
variant: 'error',
|
||||||
onDismiss() {},
|
onDismiss: dismiss,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -63,14 +63,14 @@ const CollaboratorsTabPanel = () => {
|
|||||||
id: 'member_removed',
|
id: 'member_removed',
|
||||||
title: 'Member removed from project',
|
title: 'Member removed from project',
|
||||||
variant: 'success',
|
variant: 'success',
|
||||||
onDismiss() {},
|
onDismiss: dismiss,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
toast({
|
toast({
|
||||||
id: 'member_not_removed',
|
id: 'member_not_removed',
|
||||||
title: 'Not able to remove member',
|
title: 'Not able to remove member',
|
||||||
variant: 'error',
|
variant: 'error',
|
||||||
onDismiss() {},
|
onDismiss: dismiss,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -86,14 +86,14 @@ const CollaboratorsTabPanel = () => {
|
|||||||
id: 'member_permission_updated',
|
id: 'member_permission_updated',
|
||||||
title: 'Project member permission updated',
|
title: 'Project member permission updated',
|
||||||
variant: 'success',
|
variant: 'success',
|
||||||
onDismiss() {},
|
onDismiss: dismiss,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
toast({
|
toast({
|
||||||
id: 'member_permission_not_updated',
|
id: 'member_permission_not_updated',
|
||||||
title: 'Project member permission not updated',
|
title: 'Project member permission not updated',
|
||||||
variant: 'error',
|
variant: 'error',
|
||||||
onDismiss() {},
|
onDismiss: dismiss,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user