From 58068b34bf5bf6d679776a5133bf84f7a543e215 Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Thu, 14 Nov 2024 11:55:11 +0100 Subject: [PATCH] feat: invitations are working - first iteration --- actions/auth/auth.ts | 5 ++++- app/(auth)/sign-up/page.tsx | 10 ++++++++-- components/auth/oss/auth-form.tsx | 25 ++++++++++++++++++++++++- types/authFormSchema.ts | 2 ++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/actions/auth/auth.ts b/actions/auth/auth.ts index e0de4422b6..4973e3f8e2 100644 --- a/actions/auth/auth.ts +++ b/actions/auth/auth.ts @@ -56,6 +56,10 @@ export const createNewUser = async ( const keyServer = process.env.API_BASE_URL; const url = new URL(`${keyServer}/users`); + if (formData.invitationToken) { + url.searchParams.append("invitation_token", formData.invitationToken); + } + const bodyData = { data: { type: "User", @@ -79,7 +83,6 @@ export const createNewUser = async ( }); const parsedResponse = await response.json(); - if (!response.ok) { return parsedResponse; } diff --git a/app/(auth)/sign-up/page.tsx b/app/(auth)/sign-up/page.tsx index 8e525507b8..28149bb200 100644 --- a/app/(auth)/sign-up/page.tsx +++ b/app/(auth)/sign-up/page.tsx @@ -1,7 +1,13 @@ import { AuthForm } from "@/components/auth/oss"; +import { SearchParamsProps } from "@/types"; -const SignUp = () => { - return ; +const SignUp = ({ searchParams }: { searchParams: SearchParamsProps }) => { + const invitationToken = + typeof searchParams?.invitation_token === "string" + ? searchParams.invitation_token + : null; + + return ; }; export default SignUp; diff --git a/components/auth/oss/auth-form.tsx b/components/auth/oss/auth-form.tsx index 2afe281f2a..1be8e9e5e5 100644 --- a/components/auth/oss/auth-form.tsx +++ b/components/auth/oss/auth-form.tsx @@ -20,7 +20,13 @@ import { } from "@/components/ui/form"; import { ApiError, authFormSchema } from "@/types"; -export const AuthForm = ({ type }: { type: string }) => { +export const AuthForm = ({ + type, + invitationToken, +}: { + type: string; + invitationToken?: string | null; +}) => { const formSchema = authFormSchema(type); const router = useRouter(); @@ -96,6 +102,12 @@ export const AuthForm = ({ type }: { type: string }) => { message: errorMessage, }); break; + case "/data/attributes/invitation_token": + form.setError("invitationToken", { + type: "server", + message: errorMessage, + }); + break; default: toast({ variant: "destructive", @@ -186,6 +198,17 @@ export const AuthForm = ({ type }: { type: string }) => { name="confirmPassword" confirmPassword /> + {invitationToken && ( + + )} : z.string().min(12, { message: "It must contain at least 12 characters.", }), + invitationToken: + type === "sign-in" ? z.string().optional() : z.string().optional(), termsAndConditions: type === "sign-in" ? z.boolean().optional()