update account form for email login

This commit is contained in:
2025-09-10 06:34:05 +03:00
parent e3cdba6a7c
commit fa0bbe64fb
13 changed files with 102 additions and 46 deletions

View File

@@ -12,7 +12,9 @@ const updateAccountSchema = {
.string({
error: 'Last name is required',
})
.nonempty(),
.nonempty({
error: 'common:formFieldError.stringNonEmpty',
}),
personalCode: z.string().refine(
(val) => {
try {
@@ -30,7 +32,7 @@ const updateAccountSchema = {
}),
phone: z
.string({
error: 'Phone number is required',
error: 'error:invalidPhone',
})
.nonempty()
.refine(
@@ -75,18 +77,26 @@ export const UpdateAccountSchemaServer = z.object({
email: updateAccountSchema.email,
phone: updateAccountSchema.phone,
city: updateAccountSchema.city,
weight: updateAccountSchema.weight,
height: updateAccountSchema.height,
weight: updateAccountSchema.weight.nullable(),
height: updateAccountSchema.height.nullable(),
userConsent: updateAccountSchema.userConsent,
});
export const UpdateAccountSchemaClient = z.object({
export const UpdateAccountSchemaClient = ({ isEmailUser }: { isEmailUser: boolean }) => z.object({
firstName: updateAccountSchema.firstName,
lastName: updateAccountSchema.lastName,
personalCode: updateAccountSchema.personalCode,
email: updateAccountSchema.email,
phone: updateAccountSchema.phone,
city: updateAccountSchema.city,
weight: updateAccountSchema.weight.gt(-1).gte(0).nullable(),
height: updateAccountSchema.height.gt(-1).gte(0).nullable(),
...(isEmailUser
? {
city: z.string().optional(),
weight: z.number().optional(),
height: z.number().optional(),
}
: {
city: updateAccountSchema.city,
weight: updateAccountSchema.weight,
height: updateAccountSchema.height,
}),
userConsent: updateAccountSchema.userConsent,
});

View File

@@ -1,7 +1,5 @@
'use server';
import { redirect } from 'next/navigation';
import { updateCustomer } from '@lib/data/customer';
import { AccountSubmitData, createAuthApi } from '@kit/auth/api';
@@ -39,11 +37,8 @@ export const onUpdateAccount = enhanceAction(
const hasUnseenMembershipConfirmation =
await api.hasUnseenMembershipConfirmation();
if (hasUnseenMembershipConfirmation) {
redirect(pathsConfig.auth.membershipConfirmation);
} else {
redirect(pathsConfig.app.selectPackage);
return {
hasUnseenMembershipConfirmation,
}
},
{