do refCode save after register form validation

This commit is contained in:
smanylov
2026-02-19 18:37:49 +07:00
parent 22bc8fdcbe
commit b5d53e0831
2 changed files with 24 additions and 19 deletions
+23 -18
View File
@@ -152,6 +152,7 @@ export async function registration(
): Promise<FormState> { ): Promise<FormState> {
const accountType = formData.get('accountType') as 'b2b' | 'b2c'; const accountType = formData.get('accountType') as 'b2b' | 'b2c';
const mail_verified = true;
const fullName = formData.get('fullName') as string || ''; const fullName = formData.get('fullName') as string || '';
const email = formData.get('email') as string || ''; const email = formData.get('email') as string || '';
const password = formData.get('password') 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 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 referralCode = formData.get('referralCode') as string || '';
const inn = formData.get('inn') as string || ''; const inn = formData.get('inn') as string || '';
const SignupFormSchema = await getSignupFormSchema(accountType); const SignupFormSchema = await getSignupFormSchema(accountType);
@@ -215,6 +216,7 @@ export async function registration(
confirm_password, confirm_password,
phone, phone,
agree, agree,
...(referralCode !== '' && { referralCode }),
...(accountType === 'b2b' && { companyName, inn }) ...(accountType === 'b2b' && { companyName, inn })
}, },
error: errors error: errors
@@ -234,7 +236,7 @@ export async function registration(
phone: phone, phone: phone,
password, password,
accountType, accountType,
mail_verified: true, mail_verified: mail_verified,
...(accountType === 'b2b' && { companyName: companyName, inn: inn }), ...(accountType === 'b2b' && { companyName: companyName, inn: inn }),
...(referralCode !== '' && { referralLink: referralCode }) ...(referralCode !== '' && { referralLink: referralCode })
} }
@@ -273,23 +275,26 @@ export async function registration(
...(referralCode !== '' && { referralLink: referralCode }), ...(referralCode !== '' && { referralLink: referralCode }),
...(accountType === 'b2b' && { companyName: companyName, inn: inn }) ...(accountType === 'b2b' && { companyName: companyName, inn: inn })
}); });
/* await createSession(parsed.message_body.token, email as string); */
return { if (mail_verified) {
previousState: { return {
fullName, previousState: {
email, fullName,
password, email,
confirm_password, password,
phone, confirm_password,
agree, phone,
...(referralCode !== '' && { referralLink: referralCode }), agree,
...(accountType === 'b2b' && { companyName: companyName, inn: inn }) ...(referralCode !== '' && { referralLink: referralCode }),
}, ...(accountType === 'b2b' && { companyName: companyName, inn: inn })
mailConfirm: true, },
userId: parsed.message_body.userId, mailConfirm: true,
error: null userId: parsed.message_body.userId,
}; error: null
};
} else {
await createSession(parsed.message_body.token, email as string);
}
} else { } else {
console.log(parsed); console.log(parsed);
+1 -1
View File
@@ -391,7 +391,7 @@ export default function RegisterForm() {
name="referralCode" name="referralCode"
className={`${styles['form-input']}`} className={`${styles['form-input']}`}
placeholder={t('referal-code')} placeholder={t('referal-code')}
defaultValue={referralCode ? referralCode : ''} defaultValue={referralCode ? referralCode : formState?.previousState?.referralCode ?? ''}
onChange={(e) => { onChange={(e) => {
e.target.value = e.target.value.toLocaleLowerCase(); e.target.value = e.target.value.toLocaleLowerCase();
onChangeHandler(e) onChangeHandler(e)