show less update-account fields on email login

This commit is contained in:
2025-09-10 06:33:56 +03:00
parent 312027b9ed
commit e3cdba6a7c
4 changed files with 127 additions and 90 deletions

View File

@@ -1,7 +1,8 @@
import { z } from 'zod';
import Isikukood from 'isikukood';
import parsePhoneNumber from 'libphonenumber-js/min';
export const UpdateAccountSchema = z.object({
const updateAccountSchema = {
firstName: z
.string({
error: 'First name is required',
@@ -12,11 +13,18 @@ export const UpdateAccountSchema = z.object({
error: 'Last name is required',
})
.nonempty(),
personalCode: z
.string({
error: 'Personal code is required',
})
.nonempty(),
personalCode: z.string().refine(
(val) => {
try {
return new Isikukood(val).validate();
} catch {
return false;
}
},
{
message: 'common:formFieldError.invalidPersonalCode',
},
),
email: z.string().email({
message: 'Email is required',
}),
@@ -59,4 +67,26 @@ export const UpdateAccountSchema = z.object({
userConsent: z.boolean().refine((val) => val === true, {
message: 'Must be true',
}),
} as const;
export const UpdateAccountSchemaServer = z.object({
firstName: updateAccountSchema.firstName,
lastName: updateAccountSchema.lastName,
personalCode: updateAccountSchema.personalCode,
email: updateAccountSchema.email,
phone: updateAccountSchema.phone,
city: updateAccountSchema.city,
weight: updateAccountSchema.weight,
height: updateAccountSchema.height,
userConsent: updateAccountSchema.userConsent,
});
export const UpdateAccountSchemaClient = 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(),
userConsent: updateAccountSchema.userConsent,
});

View File

@@ -10,7 +10,7 @@ import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { pathsConfig } from '@kit/shared/config';
import { UpdateAccountSchema } from '../schemas/update-account.schema';
import { UpdateAccountSchemaServer } from '../schemas/update-account.schema';
export const onUpdateAccount = enhanceAction(
async (params: AccountSubmitData) => {
@@ -47,6 +47,6 @@ export const onUpdateAccount = enhanceAction(
}
},
{
schema: UpdateAccountSchema,
schema: UpdateAccountSchemaServer,
},
);