conversion inputs to components
This commit is contained in:
@@ -98,55 +98,142 @@ export const LicensedInSchema = z.object({
|
||||
state: z.string().nonempty('State is required'),
|
||||
});
|
||||
|
||||
// export const UserSchema = z
|
||||
// .object({
|
||||
// id: z.string().uuid('Invalid ID format. Must be a valid UUID').optional(),
|
||||
// firstname: z.string().min(2, 'First name must be at least 2 characters long'),
|
||||
// lastname: z.string().min(2, 'Last name must be at least 2 characters long'),
|
||||
// email: z.string().email('Invalid email address'),
|
||||
// phoneNumber: z.string().optional().nullable(),
|
||||
// description: z.string().min(10, 'Description must be at least 10 characters long').optional().nullable(),
|
||||
// companyName: z.string().optional().nullable(),
|
||||
// companyOverview: z.string().min(10, 'Company overview must be at least 10 characters long').optional().nullable(),
|
||||
// companyWebsite: z.string().url('Invalid company website URL').optional().nullable(),
|
||||
// companyLocation: z.string().optional().nullable(), // Additional validation for US locations could be implemented here
|
||||
// offeredServices: z.string().min(10, 'Offered services must be at least 10 characters long').optional().nullable(),
|
||||
// areasServed: z.array(AreasServedSchema).optional().nullable(),
|
||||
// hasProfile: z.boolean().optional().nullable(),
|
||||
// hasCompanyLogo: z.boolean().optional().nullable(),
|
||||
// licensedIn: z.array(LicensedInSchema).optional().nullable(),
|
||||
// gender: GenderEnum.optional().nullable(),
|
||||
// customerType: CustomerTypeEnum.optional().nullable(),
|
||||
// customerSubType: CustomerSubTypeEnum.optional().nullable(),
|
||||
// created: z.date().optional().nullable(),
|
||||
// updated: z.date().optional().nullable(),
|
||||
// latitude: z.number().optional().nullable(),
|
||||
// longitude: z.number().optional().nullable(),
|
||||
// })
|
||||
// .refine(
|
||||
// data => {
|
||||
// if (data.customerType === 'professional') {
|
||||
// return !!data.customerSubType && !!data.phoneNumber && !!data.companyOverview && !!data.description && !!data.offeredServices && !!data.companyLocation && data.areasServed && data.areasServed.length > 0;
|
||||
// }
|
||||
// return true;
|
||||
// },
|
||||
// {
|
||||
// message: 'For professional customers, additional fields are required: customer subtype, phone number, company overview, description, offered services, company location, and at least one area served',
|
||||
// path: ['customerType'],
|
||||
// },
|
||||
// )
|
||||
// .refine(
|
||||
// data => {
|
||||
// if (data.customerType === 'professional') {
|
||||
// return /\(\d{3}\) \d{3}-\d{4}$/.test(data.phoneNumber || '');
|
||||
// }
|
||||
// return true;
|
||||
// },
|
||||
// {
|
||||
// message: 'Phone number must be in US format: +1 (XXX) XXX-XXXX',
|
||||
// path: ['phoneNumber'],
|
||||
// },
|
||||
// );
|
||||
|
||||
const phoneRegex = /^\+1 \(\d{3}\) \d{3}-\d{4}$/;
|
||||
|
||||
export const UserSchema = z
|
||||
.object({
|
||||
id: z.string().uuid('Invalid ID format. Must be a valid UUID').optional(),
|
||||
firstname: z.string().min(2, 'First name must be at least 2 characters long'),
|
||||
lastname: z.string().min(2, 'Last name must be at least 2 characters long'),
|
||||
email: z.string().email('Invalid email address'),
|
||||
id: z.string().uuid(),
|
||||
firstname: z.string().min(2, { message: 'First name must contain at least 2 characters' }),
|
||||
lastname: z.string().min(2, { message: 'Last name must contain at least 2 characters' }),
|
||||
email: z.string().email({ message: 'Invalid email address' }),
|
||||
phoneNumber: z.string().optional().nullable(),
|
||||
description: z.string().min(10, 'Description must be at least 10 characters long').optional().nullable(),
|
||||
description: z.string().optional().nullable(),
|
||||
companyName: z.string().optional().nullable(),
|
||||
companyOverview: z.string().min(10, 'Company overview must be at least 10 characters long').optional().nullable(),
|
||||
companyWebsite: z.string().url('Invalid company website URL').optional().nullable(),
|
||||
companyLocation: z.string().optional().nullable(), // Additional validation for US locations could be implemented here
|
||||
offeredServices: z.string().min(10, 'Offered services must be at least 10 characters long').optional().nullable(),
|
||||
companyOverview: z.string().optional().nullable(),
|
||||
companyWebsite: z.string().url({ message: 'Invalid URL format' }).optional().nullable(),
|
||||
companyLocation: z.string().optional().nullable(),
|
||||
offeredServices: z.string().optional().nullable(),
|
||||
areasServed: z.array(AreasServedSchema).optional().nullable(),
|
||||
hasProfile: z.boolean().optional().nullable(),
|
||||
hasCompanyLogo: z.boolean().optional().nullable(),
|
||||
licensedIn: z.array(LicensedInSchema).optional().nullable(),
|
||||
gender: GenderEnum.optional().nullable(),
|
||||
customerType: CustomerTypeEnum.optional().nullable(),
|
||||
customerType: CustomerTypeEnum,
|
||||
customerSubType: CustomerSubTypeEnum.optional().nullable(),
|
||||
created: z.date().optional().nullable(),
|
||||
updated: z.date().optional().nullable(),
|
||||
latitude: z.number().optional().nullable(),
|
||||
longitude: z.number().optional().nullable(),
|
||||
})
|
||||
.refine(
|
||||
data => {
|
||||
if (data.customerType === 'professional') {
|
||||
return !!data.customerSubType && !!data.phoneNumber && !!data.companyOverview && !!data.description && !!data.offeredServices && !!data.companyLocation && data.areasServed && data.areasServed.length > 0;
|
||||
.superRefine((data, ctx) => {
|
||||
if (data.customerType === 'professional') {
|
||||
if (!data.customerSubType) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Customer subtype is required for professional customers',
|
||||
path: ['customerSubType'],
|
||||
});
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{
|
||||
message: 'For professional customers, additional fields are required: customer subtype, phone number, company overview, description, offered services, company location, and at least one area served',
|
||||
path: ['customerType'],
|
||||
},
|
||||
)
|
||||
.refine(
|
||||
data => {
|
||||
if (data.customerType === 'professional') {
|
||||
return /\(\d{3}\) \d{3}-\d{4}$/.test(data.phoneNumber || '');
|
||||
|
||||
if (!data.phoneNumber || !phoneRegex.test(data.phoneNumber)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Phone number is required and must be in US format (+1 (XXX) XXX-XXXX) for professional customers',
|
||||
path: ['phoneNumber'],
|
||||
});
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{
|
||||
message: 'Phone number must be in US format: +1 (XXX) XXX-XXXX',
|
||||
path: ['phoneNumber'],
|
||||
},
|
||||
);
|
||||
|
||||
if (!data.companyOverview || data.companyOverview.length < 10) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Company overview must contain at least 10 characters for professional customers',
|
||||
path: ['companyOverview'],
|
||||
});
|
||||
}
|
||||
|
||||
if (!data.description || data.description.length < 10) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Description must contain at least 10 characters for professional customers',
|
||||
path: ['description'],
|
||||
});
|
||||
}
|
||||
|
||||
if (!data.offeredServices || data.offeredServices.length < 10) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Offered services must contain at least 10 characters for professional customers',
|
||||
path: ['offeredServices'],
|
||||
});
|
||||
}
|
||||
|
||||
if (!data.companyLocation) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Company location is required for professional customers',
|
||||
path: ['companyLocation'],
|
||||
});
|
||||
}
|
||||
|
||||
if (!data.areasServed || data.areasServed.length < 1) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'At least one area served is required for professional customers',
|
||||
path: ['areasServed'],
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export type AreasServed = z.infer<typeof AreasServedSchema>;
|
||||
export type LicensedIn = z.infer<typeof LicensedInSchema>;
|
||||
|
||||
Reference in New Issue
Block a user