fix: resolve invitation select synchronization and error handling - #5502
rubenspezzoli-pz wants to merge 1 commit into
Conversation
| interface AddInvitationProps { | ||
| organizationId: string | ||
| onSuccess?: () => void | ||
| } | ||
|
|
||
| export function AddInvitation({ organizationId, onSuccess }: AddInvitationProps) { | ||
| const [isOpen, setIsOpen] = useState(false) | ||
| const [isLoading, setIsLoading] = useState(false) | ||
| const utils = api.useUtils() | ||
|
|
||
| const form = useForm<AddInvitationValues>({ | ||
| resolver: zodResolver(addInvitationSchema), | ||
| defaultValues: { | ||
| email: "", | ||
| role: "member", | ||
| }, | ||
| }) | ||
|
|
||
| const { mutateAsync: createInvitation } = api.organization.createInvitation.useMutation({ | ||
| onSuccess: () => { | ||
| toast.success("Invito inviato con successo") | ||
| utils.organization.getInvitations.invalidate() |
There was a problem hiding this comment.
The rewritten component requires an organizationId, but both existing call sites render <AddInvitation /> without it. It also calls api.organization.createInvitation and invalidates utils.organization.getInvitations, while the organization router exposes inviteMember and allInvitations instead. These mismatches prevent the dashboard from type-checking and building.
Knowledge Base Used: Web control plane
| const addInvitationSchema = z.object({ | ||
| email: z.string().email("Email non valida"), | ||
| role: z.enum(["owner", "admin", "member"]), | ||
| }) |
There was a problem hiding this comment.
Role Choices Break Invitations
This allowlist offers owner, even though the server always rejects owner invitations as non-delegable. It also excludes the custom roles supported by the server and ignores the organization's configured default role. As a result, users can select an invitation that is guaranteed to fail, while enterprise organizations can no longer invite members with their intended roles.
Knowledge Base Used:
| const addInvitationSchema = z.object({ | ||
| email: z.string().email("Email non valida"), | ||
| role: z.enum(["owner", "admin", "member"]), | ||
| }) | ||
|
|
||
| type AddInvitationValues = z.infer<typeof addInvitationSchema> | ||
|
|
||
| interface AddInvitationProps { | ||
| organizationId: string | ||
| onSuccess?: () => void | ||
| } | ||
|
|
||
| export function AddInvitation({ organizationId, onSuccess }: AddInvitationProps) { |
There was a problem hiding this comment.
Supported Workflows Were Removed
The replacement schema models only an email and role, removing the self-hosted initial-credentials flow and the email-provider invitation flow that this dialog previously exposed. Administrators can therefore no longer provision a user with a password or select a configured provider from the users screen, even though the corresponding backend capabilities remain available.
Knowledge Base Used: Web control plane
| async function onSubmit(values: AddInvitationValues) { | ||
| try { | ||
| setIsLoading(true) | ||
| await createInvitation({ | ||
| organizationId, | ||
| email: values.email, | ||
| role: values.role, | ||
| }) | ||
| } finally { | ||
| setIsLoading(false) | ||
| } | ||
| } |
There was a problem hiding this comment.
mutateAsync still rejects after its onError callback runs, but this submit handler uses only try/finally. When an invitation fails, the toast appears and the rejected promise then escapes through handleSubmit, producing an unhandled submit-handler rejection. Catch the error after displaying it or otherwise handle the rejection in onSubmit.
| <Button>Invita membro</Button> | ||
| </DialogTrigger> | ||
| <DialogContent className="sm:max-w-[425px]"> | ||
| <DialogHeader> | ||
| <DialogTitle>Invita un nuovo utente</DialogTitle> | ||
| <DialogDescription> | ||
| Inserisci l'indirizzo email e seleziona il ruolo per l'invito. |
There was a problem hiding this comment.
Dialog Language Is Inconsistent
This rewrite changes the dialog's labels, validation messages, and notifications to Italian while the surrounding users interface remains English. That makes the actions and errors difficult to understand for users relying on the application's established language. Keep the existing English copy or route these strings through the application's localization system.
Knowledge Base Used: Web control plane
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
What is this PR about?
Please describe in a short paragraph what this PR is about.
Checklist
Before submitting this PR, please make sure that:
canarybranch.Issues related (if applicable)
closes #5497
Screenshots (if applicable)
This PR is not safe to merge because the rewritten invitation component does not type-check against its callers or the organization router and also removes supported administrative workflows.
Summary
This PR rewrites the invitation dialog in an attempt to synchronize its role select and revise error handling, but the replacement is incompatible with the existing component and API contracts.
Reviews (1) · Last reviewed commit: "fix: resolve invitation select synchroni..."