task-e
This commit is contained in:
103
src/features/crm/quotations/schemas/quotation.schema.ts
Normal file
103
src/features/crm/quotations/schemas/quotation.schema.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import * as z from 'zod';
|
||||
|
||||
export const quotationSchema = z.object({
|
||||
enquiryId: z.string().optional().nullable(),
|
||||
customerId: z.string().min(1, 'Please select a customer'),
|
||||
contactId: z.string().optional().nullable(),
|
||||
quotationDate: z.string().min(1, 'Quotation date is required'),
|
||||
validUntil: z.string().optional().nullable(),
|
||||
quotationType: z.string().min(1, 'Please select a quotation type'),
|
||||
projectName: z.string().optional(),
|
||||
projectLocation: z.string().optional(),
|
||||
attention: z.string().optional(),
|
||||
branchId: z.string().optional().nullable(),
|
||||
currency: z.string().min(1, 'Please select a currency'),
|
||||
exchangeRate: z.number().nullable().optional(),
|
||||
status: z.string().min(1, 'Please select a status'),
|
||||
chancePercent: z
|
||||
.number()
|
||||
.nullable()
|
||||
.optional()
|
||||
.refine(
|
||||
(value) => value === null || value === undefined || (value >= 0 && value <= 100),
|
||||
'Chance percent must be between 0 and 100'
|
||||
),
|
||||
isHotProject: z.boolean().default(false),
|
||||
competitor: z.string().optional(),
|
||||
reference: z.string().optional(),
|
||||
notes: z.string().optional(),
|
||||
salesmanId: z.string().optional().nullable(),
|
||||
discount: z.number().nullable().optional(),
|
||||
discountType: z.string().optional().nullable(),
|
||||
taxRate: z.number().nullable().optional(),
|
||||
isActive: z.boolean().default(true),
|
||||
sentVia: z.string().optional().nullable(),
|
||||
revisionRemark: z.string().optional().nullable()
|
||||
});
|
||||
|
||||
export const quotationItemSchema = z.object({
|
||||
productType: z.string().min(1, 'Please select a product type'),
|
||||
description: z.string().min(2, 'Description must be at least 2 characters'),
|
||||
quantity: z.number().positive('Quantity must be greater than 0'),
|
||||
unit: z.string().optional(),
|
||||
unitPrice: z.number().min(0, 'Unit price must be 0 or greater'),
|
||||
discount: z.number().min(0).nullable().optional(),
|
||||
discountType: z.string().nullable().optional(),
|
||||
taxRate: z.number().min(0).nullable().optional(),
|
||||
notes: z.string().optional(),
|
||||
sortOrder: z.number().nullable().optional()
|
||||
});
|
||||
|
||||
export const quotationCustomerSchema = z.object({
|
||||
customerId: z.string().min(1, 'Please select a customer'),
|
||||
role: z.string().min(1, 'Please select a role'),
|
||||
isPrimary: z.boolean().default(false)
|
||||
});
|
||||
|
||||
export const quotationTopicSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
topicType: z.string().min(1, 'Please select a topic type'),
|
||||
title: z.string().min(2, 'Title must be at least 2 characters'),
|
||||
sortOrder: z.number().nullable().optional(),
|
||||
items: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.string().optional(),
|
||||
content: z.string().min(1, 'Topic item content is required'),
|
||||
sortOrder: z.number().nullable().optional()
|
||||
})
|
||||
)
|
||||
.min(1, 'At least one topic item is required')
|
||||
});
|
||||
|
||||
export const quotationFollowupSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
followupDate: z.string().min(1, 'Follow-up date is required'),
|
||||
followupType: z.string().min(1, 'Please select a follow-up type'),
|
||||
contactId: z.string().optional().nullable(),
|
||||
outcome: z.string().optional(),
|
||||
notes: z.string().optional(),
|
||||
nextFollowupDate: z.string().optional().nullable(),
|
||||
nextAction: z.string().optional()
|
||||
});
|
||||
|
||||
export const quotationAttachmentSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
fileName: z.string().min(1, 'Stored file name is required'),
|
||||
originalFileName: z.string().min(1, 'Original file name is required'),
|
||||
filePath: z.string().min(1, 'File path is required'),
|
||||
fileSize: z.number().nullable().optional(),
|
||||
fileType: z.string().nullable().optional(),
|
||||
description: z.string().optional()
|
||||
});
|
||||
|
||||
export const quotationRevisionSchema = z.object({
|
||||
revisionRemark: z.string().optional()
|
||||
});
|
||||
|
||||
export type QuotationFormValues = z.input<typeof quotationSchema>;
|
||||
export type QuotationItemFormValues = z.input<typeof quotationItemSchema>;
|
||||
export type QuotationCustomerFormValues = z.input<typeof quotationCustomerSchema>;
|
||||
export type QuotationTopicFormValues = z.input<typeof quotationTopicSchema>;
|
||||
export type QuotationFollowupFormValues = z.input<typeof quotationFollowupSchema>;
|
||||
export type QuotationAttachmentFormValues = z.input<typeof quotationAttachmentSchema>;
|
||||
Reference in New Issue
Block a user