From f6ca797802673926d1f2e07a395dd2bae75857ba Mon Sep 17 00:00:00 2001 From: smanylov Date: Fri, 6 Feb 2026 13:13:29 +0700 Subject: [PATCH] add referal code for registration --- src/app/actions/auth.ts | 2 ++ src/app/ui/forms/register-form.tsx | 51 ++++++++++++++++++++++++++++-- src/i18n/messages/en.json | 3 +- src/i18n/messages/ru.json | 3 +- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/app/actions/auth.ts b/src/app/actions/auth.ts index 417c54d..5d73ed9 100644 --- a/src/app/actions/auth.ts +++ b/src/app/actions/auth.ts @@ -137,6 +137,7 @@ export type FormState = { phone: string; companyName?: string; agree: string; + referralCode?: string }, mailConfirm?: boolean, error: Record | null @@ -155,6 +156,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 SignupFormSchema = await getSignupFormSchema(accountType); diff --git a/src/app/ui/forms/register-form.tsx b/src/app/ui/forms/register-form.tsx index c554719..19a49ef 100644 --- a/src/app/ui/forms/register-form.tsx +++ b/src/app/ui/forms/register-form.tsx @@ -8,9 +8,13 @@ import Link from 'next/link'; import { useTranslations } from 'next-intl'; import { IconEye } from '@/app/ui/icons/icons'; import { SignupFormSchema } from '@/app/actions/definitions'; +import { useSearchParams } from 'next/navigation'; import * as z from 'zod' export default function RegisterForm() { + const searchParams = useSearchParams(); + const referralCode = searchParams.get('referralCode'); + const [state, formAction, isPending] = useActionState( registration, undefined, @@ -37,6 +41,10 @@ export default function RegisterForm() { }, [state]) + useEffect(() => { + console.log(referralCode); + }, [referralCode]); + function showPassowrd(target: 'password' | 'confirm-password') { if (target === 'password') { setShowPassword(!showPassword); @@ -77,6 +85,7 @@ export default function RegisterForm() { case 'email': case 'fullName': case 'phone': + case 'referralCode': case 'password': case 'companyName': case 'agree': @@ -87,6 +96,9 @@ export default function RegisterForm() { if (fieldName === 'companyName' && accountType === 'b2c') { return { success: true, data: value }; } + if (fieldName === 'referralCode') { + return { success: true, data: value }; + } return schema.safeParse(value); default: @@ -242,7 +254,7 @@ export default function RegisterForm() { )} - {accountType === 'b2b' && ( + {accountType === 'b2b' ? (
- )} + ) : ( +
+ + { + e.target.value = e.target.value.toLocaleLowerCase(); + onChangeHandler(e) + }} + /> + {formState?.error?.referralCode && ( +

+ { + formState?.error?.referralCode.split('&').map((e, index) => { + return ( + + {t(e)} +
+
+ ) + }) + } +

+ )} +
+ ) + }
+
+