add referal code for registration
This commit is contained in:
@@ -137,6 +137,7 @@ export type FormState = {
|
|||||||
phone: string;
|
phone: string;
|
||||||
companyName?: string;
|
companyName?: string;
|
||||||
agree: string;
|
agree: string;
|
||||||
|
referralCode?: string
|
||||||
},
|
},
|
||||||
mailConfirm?: boolean,
|
mailConfirm?: boolean,
|
||||||
error: Record<string, string> | null
|
error: Record<string, string> | null
|
||||||
@@ -155,6 +156,7 @@ export async function registration(
|
|||||||
const phone = formData.get('phone') as string || '';
|
const phone = formData.get('phone') as string || '';
|
||||||
const companyName = formData.get('companyName') as string || '';
|
const companyName = formData.get('companyName') as string || '';
|
||||||
const agree = formData.get('agree') as string || '';
|
const agree = formData.get('agree') as string || '';
|
||||||
|
const referralCode = formData.get('referralCode');
|
||||||
|
|
||||||
const SignupFormSchema = await getSignupFormSchema(accountType);
|
const SignupFormSchema = await getSignupFormSchema(accountType);
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,13 @@ import Link from 'next/link';
|
|||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { IconEye } from '@/app/ui/icons/icons';
|
import { IconEye } from '@/app/ui/icons/icons';
|
||||||
import { SignupFormSchema } from '@/app/actions/definitions';
|
import { SignupFormSchema } from '@/app/actions/definitions';
|
||||||
|
import { useSearchParams } from 'next/navigation';
|
||||||
import * as z from 'zod'
|
import * as z from 'zod'
|
||||||
|
|
||||||
export default function RegisterForm() {
|
export default function RegisterForm() {
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const referralCode = searchParams.get('referralCode');
|
||||||
|
|
||||||
const [state, formAction, isPending] = useActionState(
|
const [state, formAction, isPending] = useActionState(
|
||||||
registration,
|
registration,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -37,6 +41,10 @@ export default function RegisterForm() {
|
|||||||
|
|
||||||
}, [state])
|
}, [state])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(referralCode);
|
||||||
|
}, [referralCode]);
|
||||||
|
|
||||||
function showPassowrd(target: 'password' | 'confirm-password') {
|
function showPassowrd(target: 'password' | 'confirm-password') {
|
||||||
if (target === 'password') {
|
if (target === 'password') {
|
||||||
setShowPassword(!showPassword);
|
setShowPassword(!showPassword);
|
||||||
@@ -77,6 +85,7 @@ export default function RegisterForm() {
|
|||||||
case 'email':
|
case 'email':
|
||||||
case 'fullName':
|
case 'fullName':
|
||||||
case 'phone':
|
case 'phone':
|
||||||
|
case 'referralCode':
|
||||||
case 'password':
|
case 'password':
|
||||||
case 'companyName':
|
case 'companyName':
|
||||||
case 'agree':
|
case 'agree':
|
||||||
@@ -87,6 +96,9 @@ export default function RegisterForm() {
|
|||||||
if (fieldName === 'companyName' && accountType === 'b2c') {
|
if (fieldName === 'companyName' && accountType === 'b2c') {
|
||||||
return { success: true, data: value };
|
return { success: true, data: value };
|
||||||
}
|
}
|
||||||
|
if (fieldName === 'referralCode') {
|
||||||
|
return { success: true, data: value };
|
||||||
|
}
|
||||||
return schema.safeParse(value);
|
return schema.safeParse(value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -242,7 +254,7 @@ export default function RegisterForm() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{accountType === 'b2b' && (
|
{accountType === 'b2b' ? (
|
||||||
<div className={`${styles['form-group']}`}>
|
<div className={`${styles['form-group']}`}>
|
||||||
<label
|
<label
|
||||||
className={`${styles['form-label']} ${styles['required']}`}
|
className={`${styles['form-label']} ${styles['required']}`}
|
||||||
@@ -273,7 +285,40 @@ export default function RegisterForm() {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
) : (
|
||||||
|
<div className={`${styles['form-group']}`}>
|
||||||
|
<label className={`${styles['form-label']}`}>
|
||||||
|
{t('referal-code')}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="referralCode"
|
||||||
|
name="referralCode"
|
||||||
|
className={`${styles['form-input']}`}
|
||||||
|
placeholder={t('referal-code')}
|
||||||
|
defaultValue={referralCode ? referralCode : ''}
|
||||||
|
onChange={(e) => {
|
||||||
|
e.target.value = e.target.value.toLocaleLowerCase();
|
||||||
|
onChangeHandler(e)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{formState?.error?.referralCode && (
|
||||||
|
<p className="text-sm text-red-500">
|
||||||
|
{
|
||||||
|
formState?.error?.referralCode.split('&').map((e, index) => {
|
||||||
|
return (
|
||||||
|
<span key={index}>
|
||||||
|
{t(e)}
|
||||||
|
<br />
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
<div className={`${styles['form-group']}`}>
|
<div className={`${styles['form-group']}`}>
|
||||||
<label className={`${styles['form-label']} ${styles['required']}`}>
|
<label className={`${styles['form-label']} ${styles['required']}`}>
|
||||||
@@ -306,6 +351,7 @@ export default function RegisterForm() {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={`${styles['form-group']}`}>
|
<div className={`${styles['form-group']}`}>
|
||||||
<label className={`${styles['form-label']} ${styles['required']}`}>
|
<label className={`${styles['form-label']} ${styles['required']}`}>
|
||||||
{t('phone')}
|
{t('phone')}
|
||||||
@@ -369,6 +415,7 @@ export default function RegisterForm() {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={`${styles['form-group']}`}>
|
<div className={`${styles['form-group']}`}>
|
||||||
<label className={`${styles['form-label']} ${styles['required']}`}>
|
<label className={`${styles['form-label']} ${styles['required']}`}>
|
||||||
{t('confirm-password')}
|
{t('confirm-password')}
|
||||||
|
|||||||
@@ -279,6 +279,7 @@
|
|||||||
"personal": "Personal",
|
"personal": "Personal",
|
||||||
"unknown-error": "Unknown error",
|
"unknown-error": "Unknown error",
|
||||||
"change-password": "Change Password",
|
"change-password": "Change Password",
|
||||||
"recovery-code": "Recovery code"
|
"recovery-code": "Recovery code",
|
||||||
|
"referal-code": "Referal code"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,6 +279,7 @@
|
|||||||
"personal": "Личный",
|
"personal": "Личный",
|
||||||
"unknown-error": "Неизвестная ошибка",
|
"unknown-error": "Неизвестная ошибка",
|
||||||
"change-password": "Изменить пароль",
|
"change-password": "Изменить пароль",
|
||||||
"recovery-code": "Код восстановления"
|
"recovery-code": "Код восстановления",
|
||||||
|
"referal-code": "Реферальный код"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user