Expired links (#94)
1. Handle expired links on signup 2.Reject invitations when user is already a member 3. Make sure not to display errors due to Next.js redirection during team creation 4. Fix documentation sidebar
This commit is contained in:
committed by
GitHub
parent
ae9c33aea4
commit
97d2cf9f85
@@ -2,6 +2,8 @@
|
||||
|
||||
import { useState, useTransition } from 'react';
|
||||
|
||||
import { isRedirectError } from 'next/dist/client/components/redirect-error';
|
||||
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { z } from 'zod';
|
||||
@@ -76,10 +78,16 @@ function CreateOrganizationAccountForm(props: { onClose: () => void }) {
|
||||
data-test={'create-team-form'}
|
||||
onSubmit={form.handleSubmit((data) => {
|
||||
startTransition(async () => {
|
||||
const { error } = await createTeamAccountAction(data);
|
||||
try {
|
||||
const { error } = await createTeamAccountAction(data);
|
||||
|
||||
if (error) {
|
||||
setError(true);
|
||||
if (error) {
|
||||
setError(true);
|
||||
}
|
||||
} catch (error) {
|
||||
if (!isRedirectError(error)) {
|
||||
setError(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
})}
|
||||
|
||||
@@ -101,6 +101,30 @@ class AccountInvitationsService {
|
||||
return data;
|
||||
}
|
||||
|
||||
async validateInvitation(
|
||||
invitation: z.infer<typeof InviteMembersSchema>['invitations'][number],
|
||||
accountSlug: string,
|
||||
) {
|
||||
const { data: members, error } = await this.client.rpc(
|
||||
'get_account_members',
|
||||
{
|
||||
account_slug: accountSlug,
|
||||
},
|
||||
);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const isUserAlreadyMember = members.find((member) => {
|
||||
return member.email === invitation.email;
|
||||
});
|
||||
|
||||
if (isUserAlreadyMember) {
|
||||
throw new Error('User already member of the team');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name sendInvitations
|
||||
* @description Sends invitations to join a team.
|
||||
@@ -123,6 +147,24 @@ class AccountInvitationsService {
|
||||
|
||||
logger.info(ctx, 'Storing invitations...');
|
||||
|
||||
try {
|
||||
await Promise.all(
|
||||
invitations.map((invitation) =>
|
||||
this.validateInvitation(invitation, accountSlug),
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
{
|
||||
...ctx,
|
||||
error: (error as Error).message,
|
||||
},
|
||||
'Error validating invitations',
|
||||
);
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
const accountResponse = await this.client
|
||||
.from('accounts')
|
||||
.select('name')
|
||||
|
||||
Reference in New Issue
Block a user