mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-30 14:57:59 +00:00
Radix was leaking out of the primitive layer into application code. Thirty dialog components under apps/remix imported `@radix-ui/react-dialog` purely to spell `Omit<DialogPrimitive.DialogProps, 'children'>`, and two more imported `TooltipArrow` directly. Each of those is a place the UI substrate has to be swapped when it changes, for no gain — the app never touched Radix behaviour, only a type and one arrow element. `packages/ui/primitives/dialog.tsx` now exports `DialogProps` and `tooltip.tsx` exports `TooltipArrow`, so callers name the primitive, not the library behind it. Radix imports outside packages/ui: 32 -> 0. Eleven vendored shadcn primitives had no importers at all — aspect-ratio, auto-sized-text, calendar, collapsible, context-menu, menubar, navigation-menu, slider, toggle, a stray document-flow dialog and a signature-pad Canvas class shadowed by skia-canvas. Dead component code reads as supported API in review, so it is deleted rather than carried. That retires eight Radix packages plus react-day-picker from packages/ui and @radix-ui/react-tabs from apps/docs, which was declared and never imported: 28 declared Radix packages -> 19. The embedding doc taught Tailwind classes in a snippet third parties copy into their own apps; it now uses the same inline styles as the plain-HTML example directly above it. `.cursorrules` told every AI touching this repo to write "Shadcn UI, Radix, and Tailwind Aria" — it now points at @hanzo/gui and says the inherited layer is to be replaced, not extended. Verified: apps/remix typecheck 0 errors, client+server build green, prisma 38/38.
205 lines
5.9 KiB
TypeScript
205 lines
5.9 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
import { msg } from '@lingui/core/macro';
|
|
import { useLingui } from '@lingui/react';
|
|
import { Trans } from '@lingui/react/macro';
|
|
import { TeamMemberRole } from '@prisma/client';
|
|
import { useForm } from 'react-hook-form';
|
|
import { z } from 'zod';
|
|
|
|
import { TEAM_MEMBER_ROLE_HIERARCHY } from '@hanzo/esign-lib/constants/teams';
|
|
import { EXTENDED_TEAM_MEMBER_ROLE_MAP } from '@hanzo/esign-lib/constants/teams-translations';
|
|
import { isTeamRoleWithinUserHierarchy } from '@hanzo/esign-lib/utils/teams';
|
|
import type { ZUpdateTeamMemberRequestSchema } from '@hanzo/esign-trpc/server/team-router/update-team-member.types';
|
|
import { useZapMutation } from '@hanzo/esign-trpc/zap/react';
|
|
import { Button } from '@hanzo/esign-ui/primitives/button';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
type DialogProps,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from '@hanzo/esign-ui/primitives/dialog';
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from '@hanzo/esign-ui/primitives/form/form';
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from '@hanzo/esign-ui/primitives/select';
|
|
import { useToast } from '@hanzo/esign-ui/primitives/use-toast';
|
|
|
|
export type TeamMemberUpdateDialogProps = {
|
|
currentUserTeamRole: TeamMemberRole;
|
|
trigger?: React.ReactNode;
|
|
teamId: number;
|
|
memberId: string;
|
|
memberName: string;
|
|
memberTeamRole: TeamMemberRole;
|
|
} & Omit<DialogProps, 'children'>;
|
|
|
|
const ZUpdateTeamMemberFormSchema = z.object({
|
|
role: z.nativeEnum(TeamMemberRole),
|
|
});
|
|
|
|
type ZUpdateTeamMemberSchema = z.infer<typeof ZUpdateTeamMemberFormSchema>;
|
|
|
|
export const TeamMemberUpdateDialog = ({
|
|
currentUserTeamRole,
|
|
trigger,
|
|
teamId,
|
|
memberId,
|
|
memberName,
|
|
memberTeamRole,
|
|
...props
|
|
}: TeamMemberUpdateDialogProps) => {
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const { _ } = useLingui();
|
|
const { toast } = useToast();
|
|
|
|
const form = useForm<ZUpdateTeamMemberSchema>({
|
|
resolver: zodResolver(ZUpdateTeamMemberFormSchema),
|
|
defaultValues: {
|
|
role: memberTeamRole,
|
|
},
|
|
});
|
|
|
|
const { mutateAsync: updateTeamMember } = useZapMutation<
|
|
void,
|
|
z.infer<typeof ZUpdateTeamMemberRequestSchema>
|
|
>('team.member.update');
|
|
|
|
const onFormSubmit = async ({ role }: ZUpdateTeamMemberSchema) => {
|
|
try {
|
|
await updateTeamMember({
|
|
teamId,
|
|
memberId,
|
|
data: {
|
|
role,
|
|
},
|
|
});
|
|
|
|
toast({
|
|
title: _(msg`Success`),
|
|
description: _(msg`You have updated ${memberName}.`),
|
|
duration: 5000,
|
|
});
|
|
|
|
setOpen(false);
|
|
} catch {
|
|
toast({
|
|
title: _(msg`An unknown error occurred`),
|
|
description: _(
|
|
msg`We encountered an unknown error while attempting to update this team member. Please try again later.`,
|
|
),
|
|
variant: 'destructive',
|
|
});
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (!open) {
|
|
return;
|
|
}
|
|
|
|
form.reset();
|
|
|
|
if (!isTeamRoleWithinUserHierarchy(currentUserTeamRole, memberTeamRole)) {
|
|
setOpen(false);
|
|
|
|
toast({
|
|
title: _(msg`You cannot modify a team member who has a higher role than you.`),
|
|
variant: 'destructive',
|
|
});
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [open, currentUserTeamRole, memberTeamRole, form, toast]);
|
|
|
|
return (
|
|
<Dialog
|
|
{...props}
|
|
open={open}
|
|
onOpenChange={(value) => !form.formState.isSubmitting && setOpen(value)}
|
|
>
|
|
<DialogTrigger onClick={(e) => e.stopPropagation()} asChild>
|
|
{trigger ?? (
|
|
<Button variant="secondary">
|
|
<Trans>Update team member</Trans>
|
|
</Button>
|
|
)}
|
|
</DialogTrigger>
|
|
|
|
<DialogContent position="center">
|
|
<DialogHeader>
|
|
<DialogTitle>
|
|
<Trans>Update team member</Trans>
|
|
</DialogTitle>
|
|
|
|
<DialogDescription>
|
|
<Trans>
|
|
You are currently updating <span className="font-bold">{memberName}</span>.
|
|
</Trans>
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(onFormSubmit)}>
|
|
<fieldset className="flex h-full flex-col" disabled={form.formState.isSubmitting}>
|
|
<FormField
|
|
control={form.control}
|
|
name="role"
|
|
render={({ field }) => (
|
|
<FormItem className="w-full">
|
|
<FormLabel required>
|
|
<Trans>Role</Trans>
|
|
</FormLabel>
|
|
<FormControl>
|
|
<Select {...field} onValueChange={field.onChange}>
|
|
<SelectTrigger className="text-muted-foreground">
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
|
|
<SelectContent className="w-full" position="popper">
|
|
{TEAM_MEMBER_ROLE_HIERARCHY[currentUserTeamRole].map((role) => (
|
|
<SelectItem key={role} value={role}>
|
|
{_(EXTENDED_TEAM_MEMBER_ROLE_MAP[role]) ?? role}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<DialogFooter className="mt-4">
|
|
<Button type="button" variant="secondary" onClick={() => setOpen(false)}>
|
|
<Trans>Cancel</Trans>
|
|
</Button>
|
|
|
|
<Button type="submit" loading={form.formState.isSubmitting}>
|
|
<Trans>Update</Trans>
|
|
</Button>
|
|
</DialogFooter>
|
|
</fieldset>
|
|
</form>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|