do refCode save after register form validation
This commit is contained in:
+23
-18
@@ -152,6 +152,7 @@ export async function registration(
|
||||
): Promise<FormState> {
|
||||
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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user