Add team member invitation success and error messages
The code now includes success and error messages for team member invitation completion. It validates entered email addresses for duplicates and sets a limit on the number of invitations that can be sent at once to avoid server spam. Also, visual changes have been made to the form - label placement, form message, button types, etc.
This commit is contained in:
@@ -2,30 +2,25 @@ import { z } from 'zod';
|
||||
|
||||
const InviteSchema = z.object({
|
||||
email: z.string().email(),
|
||||
role: z.string().min(1),
|
||||
role: z.string().min(1).max(100),
|
||||
});
|
||||
|
||||
export const InviteMembersSchema = z
|
||||
.object({
|
||||
invitations: InviteSchema.array(),
|
||||
invitations: InviteSchema.array().min(1).max(5),
|
||||
})
|
||||
.refine((data) => {
|
||||
if (!data.invitations.length) {
|
||||
return {
|
||||
message: 'At least one invite is required',
|
||||
path: ['invites'],
|
||||
};
|
||||
}
|
||||
.refine(
|
||||
(data) => {
|
||||
const emails = data.invitations.map((member) =>
|
||||
member.email.toLowerCase(),
|
||||
);
|
||||
|
||||
const emails = data.invitations.map((member) => member.email.toLowerCase());
|
||||
const uniqueEmails = new Set(emails);
|
||||
const uniqueEmails = new Set(emails);
|
||||
|
||||
if (emails.length !== uniqueEmails.size) {
|
||||
return {
|
||||
message: 'Duplicate emails are not allowed',
|
||||
path: ['invites'],
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
return emails.length === uniqueEmails.size;
|
||||
},
|
||||
{
|
||||
message: 'Duplicate emails are not allowed',
|
||||
path: ['invitations'],
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user