Settings refactor.

This commit is contained in:
Mike Cao 2025-07-11 22:55:30 -07:00
parent 1b81074752
commit c98f324c22
56 changed files with 706 additions and 348 deletions

View file

@ -0,0 +1,65 @@
import { useApi, useMessages } from '@/components/hooks';
import { ROLES } from '@/lib/constants';
import {
Button,
Select,
Form,
FormButtons,
FormField,
ListItem,
FormSubmitButton,
} from '@umami/react-zen';
export function TeamMemberEditForm({
teamId,
userId,
role,
onSave,
onClose,
}: {
teamId: string;
userId: string;
role: string;
onSave?: () => void;
onClose?: () => void;
}) {
const { post, useMutation } = useApi();
const { mutate, error, isPending } = useMutation({
mutationFn: (data: any) => post(`/teams/${teamId}/users/${userId}`, data),
});
const { formatMessage, labels } = useMessages();
const handleSubmit = async (data: any) => {
mutate(data, {
onSuccess: async () => {
onSave();
onClose();
},
});
};
return (
<Form onSubmit={handleSubmit} error={error} defaultValues={{ role }} style={{ minWidth: 400 }}>
<FormField
name="role"
rules={{ required: formatMessage(labels.required) }}
label={formatMessage(labels.role)}
>
<Select>
<ListItem id={ROLES.teamManager}>{formatMessage(labels.manager)}</ListItem>
<ListItem id={ROLES.teamMember}>{formatMessage(labels.member)}</ListItem>
<ListItem id={ROLES.teamViewOnly}>{formatMessage(labels.viewOnly)}</ListItem>
</Select>
</FormField>
<FormButtons>
<Button isDisabled={isPending} onPress={onClose}>
{formatMessage(labels.cancel)}
</Button>
<FormSubmitButton variant="primary" isDisabled={false}>
{formatMessage(labels.save)}
</FormSubmitButton>
</FormButtons>
</Form>
);
}