f210d274bf
Various fixes from fast follows - Sort roles by alphabetical order - Change some tooltips - During role creation, role should have all permissions enabled by default - Changed Permission icons design and refactored duplicating logic in a dedicated component - Changed "Revoked by" design - Display role icon in default role picker - Workspace member avatar was missing in role list and member picker - Set "seeded" member role as editable for new workspaces - Various css fixes
93 lines
2.4 KiB
TypeScript
93 lines
2.4 KiB
TypeScript
import {
|
|
CurrentWorkspace,
|
|
currentWorkspaceState,
|
|
} from '@/auth/states/currentWorkspaceState';
|
|
import { SettingsOptionCardContentSelect } from '@/settings/components/SettingsOptions/SettingsOptionCardContentSelect';
|
|
import { Select } from '@/ui/input/components/Select';
|
|
import { t } from '@lingui/core/macro';
|
|
import { useRecoilState } from 'recoil';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { H2Title, IconUserPin, useIcons } from 'twenty-ui/display';
|
|
import { Card, Section } from 'twenty-ui/layout';
|
|
import {
|
|
Role,
|
|
UpdateWorkspaceMutation,
|
|
useUpdateWorkspaceMutation,
|
|
} from '~/generated/graphql';
|
|
|
|
type SettingsRoleDefaultRoleProps = {
|
|
roles: Role[];
|
|
};
|
|
|
|
export const SettingsRoleDefaultRole = ({
|
|
roles,
|
|
}: SettingsRoleDefaultRoleProps) => {
|
|
const [updateWorkspace] = useUpdateWorkspaceMutation();
|
|
|
|
const [currentWorkspace, setCurrentWorkspace] = useRecoilState(
|
|
currentWorkspaceState,
|
|
);
|
|
|
|
const defaultRole = currentWorkspace?.defaultRole;
|
|
|
|
const updateDefaultRole = (
|
|
defaultRoleId: string | null,
|
|
currentWorkspace: CurrentWorkspace,
|
|
) => {
|
|
updateWorkspace({
|
|
variables: {
|
|
input: {
|
|
defaultRoleId: isDefined(defaultRoleId) ? defaultRoleId : null,
|
|
},
|
|
},
|
|
onCompleted: (data: UpdateWorkspaceMutation) => {
|
|
const defaultRole = data.updateWorkspace.defaultRole;
|
|
|
|
setCurrentWorkspace({
|
|
...currentWorkspace,
|
|
defaultRole: isDefined(defaultRole) ? defaultRole : null,
|
|
});
|
|
},
|
|
});
|
|
};
|
|
|
|
const { getIcon } = useIcons();
|
|
|
|
if (!currentWorkspace || !defaultRole) {
|
|
return null;
|
|
}
|
|
|
|
const options = roles.map((role) => ({
|
|
label: role.label,
|
|
value: role.id,
|
|
Icon: getIcon(role.icon),
|
|
}));
|
|
|
|
return (
|
|
<Section>
|
|
<H2Title
|
|
title={t`Options`}
|
|
description={t`Adjust the role-related settings`}
|
|
/>
|
|
<Card rounded>
|
|
<SettingsOptionCardContentSelect
|
|
Icon={IconUserPin}
|
|
title="Default Role"
|
|
description={t`Set a default role for this workspace`}
|
|
>
|
|
<Select
|
|
selectSizeVariant="small"
|
|
withSearchInput
|
|
dropdownId="default-role-select"
|
|
options={options}
|
|
value={defaultRole?.id ?? ''}
|
|
onChange={(value) =>
|
|
updateDefaultRole(value as string, currentWorkspace)
|
|
}
|
|
/>
|
|
</SettingsOptionCardContentSelect>
|
|
</Card>
|
|
</Section>
|
|
);
|
|
};
|