fix(web,prisma): fix TypeScript errors in transfer wizard and schema
- Fix Zod v4 enum API: replace deprecated `required_error` with `error` - Create missing TransferWizardClient component (4-step wizard: category, items, AI estimate, submit) - Add CANCELLED status to TransferListingStatus enum for soft-delete support Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
76
apps/web/lib/validations/transfer.ts
Normal file
76
apps/web/lib/validations/transfer.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// ─── Step 1: Category Selection ─────────────────────────
|
||||
|
||||
export const TRANSFER_CATEGORIES = [
|
||||
{ value: 'FURNITURE', label: 'Nội thất', icon: '🛋️' },
|
||||
{ value: 'APPLIANCE', label: 'Thiết bị gia dụng', icon: '🧊' },
|
||||
{ value: 'OFFICE_EQUIPMENT', label: 'Thiết bị văn phòng', icon: '🖥️' },
|
||||
{ value: 'KITCHEN', label: 'Bếp & thiết bị', icon: '🍳' },
|
||||
{ value: 'PREMISES', label: 'Mặt bằng', icon: '🏪' },
|
||||
{ value: 'FULL_UNIT', label: 'Trọn bộ', icon: '🏠' },
|
||||
] as const;
|
||||
|
||||
export const TRANSFER_CONDITIONS = [
|
||||
{ value: 'NEW', label: 'Mới' },
|
||||
{ value: 'LIKE_NEW', label: 'Như mới' },
|
||||
{ value: 'GOOD', label: 'Tốt' },
|
||||
{ value: 'FAIR', label: 'Khá' },
|
||||
{ value: 'WORN', label: 'Cũ' },
|
||||
] as const;
|
||||
|
||||
export const transferCategorySchema = z.object({
|
||||
category: z.enum(['FURNITURE', 'APPLIANCE', 'OFFICE_EQUIPMENT', 'KITCHEN', 'PREMISES', 'FULL_UNIT'], {
|
||||
error: 'Vui lòng chọn danh mục',
|
||||
}),
|
||||
});
|
||||
|
||||
// ─── Step 2: Items ──────────────────────────────────────
|
||||
|
||||
export const transferItemSchema = z.object({
|
||||
name: z.string().min(1, 'Tên sản phẩm là bắt buộc'),
|
||||
brand: z.string().optional(),
|
||||
modelName: z.string().optional(),
|
||||
condition: z.enum(['NEW', 'LIKE_NEW', 'GOOD', 'FAIR', 'WORN'], {
|
||||
error: 'Vui lòng chọn tình trạng',
|
||||
}),
|
||||
purchaseYear: z.coerce.number().int().min(2000).max(new Date().getFullYear()).optional(),
|
||||
originalPriceVND: z.coerce.number().positive('Giá phải lớn hơn 0').optional(),
|
||||
askingPriceVND: z.coerce.number().positive('Giá phải lớn hơn 0'),
|
||||
quantity: z.coerce.number().int().min(1).default(1),
|
||||
notes: z.string().optional(),
|
||||
});
|
||||
|
||||
export type TransferItemFormData = z.infer<typeof transferItemSchema>;
|
||||
|
||||
// For premises-specific fields
|
||||
export const premisesFieldsSchema = z.object({
|
||||
areaM2: z.coerce.number().positive('Diện tích phải lớn hơn 0').optional(),
|
||||
monthlyRentVND: z.coerce.number().positive().optional(),
|
||||
depositMonths: z.coerce.number().int().min(0).optional(),
|
||||
remainingLeaseMo: z.coerce.number().int().min(0).optional(),
|
||||
businessType: z.string().optional(),
|
||||
footTraffic: z.string().optional(),
|
||||
});
|
||||
|
||||
// ─── Step 3: Location & Contact ─────────────────────────
|
||||
|
||||
export const transferLocationSchema = z.object({
|
||||
title: z.string().min(5, 'Tiêu đề tối thiểu 5 ký tự').max(200, 'Tiêu đề tối đa 200 ký tự'),
|
||||
description: z.string().optional(),
|
||||
address: z.string().min(1, 'Địa chỉ là bắt buộc'),
|
||||
ward: z.string().optional(),
|
||||
district: z.string().min(1, 'Quận/Huyện là bắt buộc'),
|
||||
city: z.string().min(1, 'Thành phố là bắt buộc').default('Hồ Chí Minh'),
|
||||
contactName: z.string().optional(),
|
||||
contactPhone: z.string().optional(),
|
||||
isNegotiable: z.boolean().default(true),
|
||||
});
|
||||
|
||||
// ─── Full form schema ───────────────────────────────────
|
||||
|
||||
export const createTransferListingSchema = transferCategorySchema
|
||||
.merge(transferLocationSchema)
|
||||
.merge(premisesFieldsSchema);
|
||||
|
||||
export type CreateTransferFormData = z.infer<typeof createTransferListingSchema>;
|
||||
Reference in New Issue
Block a user