From b5d53e08317bee2ee460d4c78e3add435cf91c79 Mon Sep 17 00:00:00 2001 From: smanylov Date: Thu, 19 Feb 2026 18:37:49 +0700 Subject: [PATCH] do refCode save after register form validation --- src/app/actions/auth.ts | 41 +++++++++++++++++------------- src/app/ui/forms/register-form.tsx | 2 +- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/app/actions/auth.ts b/src/app/actions/auth.ts index 97e8055..35428ac 100644 --- a/src/app/actions/auth.ts +++ b/src/app/actions/auth.ts @@ -152,6 +152,7 @@ export async function registration( ): Promise { const accountType = formData.get('accountType') as 'b2b' | 'b2c'; + const mail_verified = true; const fullName = formData.get('fullName') as string || ''; const email = formData.get('email') as string || ''; const password = formData.get('password') as string || ''; @@ -159,7 +160,7 @@ export async function registration( const phone = formData.get('phone') as string || ''; const companyName = formData.get('companyName') as string || ''; const agree = formData.get('agree') as string || ''; - const referralCode = formData.get('referralCode'); + const referralCode = formData.get('referralCode') as string || ''; const inn = formData.get('inn') as string || ''; const SignupFormSchema = await getSignupFormSchema(accountType); @@ -215,6 +216,7 @@ export async function registration( confirm_password, phone, agree, + ...(referralCode !== '' && { referralCode }), ...(accountType === 'b2b' && { companyName, inn }) }, error: errors @@ -234,7 +236,7 @@ export async function registration( phone: phone, password, accountType, - mail_verified: true, + mail_verified: mail_verified, ...(accountType === 'b2b' && { companyName: companyName, inn: inn }), ...(referralCode !== '' && { referralLink: referralCode }) } @@ -273,23 +275,26 @@ export async function registration( ...(referralCode !== '' && { referralLink: referralCode }), ...(accountType === 'b2b' && { companyName: companyName, inn: inn }) }); - /* await createSession(parsed.message_body.token, email as string); */ - return { - previousState: { - fullName, - email, - password, - confirm_password, - phone, - agree, - ...(referralCode !== '' && { referralLink: referralCode }), - ...(accountType === 'b2b' && { companyName: companyName, inn: inn }) - }, - mailConfirm: true, - userId: parsed.message_body.userId, - error: null - }; + if (mail_verified) { + return { + previousState: { + fullName, + email, + password, + confirm_password, + phone, + agree, + ...(referralCode !== '' && { referralLink: referralCode }), + ...(accountType === 'b2b' && { companyName: companyName, inn: inn }) + }, + mailConfirm: true, + userId: parsed.message_body.userId, + error: null + }; + } else { + await createSession(parsed.message_body.token, email as string); + } } else { console.log(parsed); diff --git a/src/app/ui/forms/register-form.tsx b/src/app/ui/forms/register-form.tsx index 7b189ec..ff1f4a7 100644 --- a/src/app/ui/forms/register-form.tsx +++ b/src/app/ui/forms/register-form.tsx @@ -391,7 +391,7 @@ export default function RegisterForm() { name="referralCode" className={`${styles['form-input']}`} placeholder={t('referal-code')} - defaultValue={referralCode ? referralCode : ''} + defaultValue={referralCode ? referralCode : formState?.previousState?.referralCode ?? ''} onChange={(e) => { e.target.value = e.target.value.toLocaleLowerCase(); onChangeHandler(e)