Updated several components within the team accounts feature to use more specific schema definitions and provide clearer form validation. Several schema files were renamed to better reflect their usage and additional properties were included. The commit also introduces handling for a new accountId property, which provides more accurate user account tracking. Autocomplete was turned off on deletion actions for better security. Changes related to account ownership transfer were also made, including transaction logging and error handling improvements.
32 lines
685 B
TypeScript
32 lines
685 B
TypeScript
import { z } from 'zod';
|
|
|
|
const InviteSchema = z.object({
|
|
email: z.string().email(),
|
|
role: z.string().min(1),
|
|
});
|
|
|
|
export const InviteMembersSchema = z
|
|
.object({
|
|
invitations: InviteSchema.array(),
|
|
})
|
|
.refine((data) => {
|
|
if (!data.invitations.length) {
|
|
return {
|
|
message: 'At least one invite is required',
|
|
path: ['invites'],
|
|
};
|
|
}
|
|
|
|
const emails = data.invitations.map((member) => member.email.toLowerCase());
|
|
const uniqueEmails = new Set(emails);
|
|
|
|
if (emails.length !== uniqueEmails.size) {
|
|
return {
|
|
message: 'Duplicate emails are not allowed',
|
|
path: ['invites'],
|
|
};
|
|
}
|
|
|
|
return true;
|
|
});
|