mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-14 02:38:58 +02:00
Fix client order validation errors for production
Update Zod schemas and frontend form handling to correctly coerce string inputs to numbers for fields like supplierId and deposit, resolving server-side validation errors and improving data integrity. Replit-Commit-Author: Agent Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/W2tfZav
This commit is contained in:
1 parent
632eb8dd82
commit
4abe7f8cd1
5 files changed
+62
-108
No files matched your search
@@ -26,8 +26,7 @@ import { insertCustomerOrderFrontendSchema, type CustomerOrderWithRelations, typ
|
||||
import { useStore } from "@/components/Layout";
|
||||
|
||||
const customerOrderFormSchema = insertCustomerOrderFrontendSchema.extend({
|
||||
deposit: z.number().optional().default(0),
|
||||
groupId: z.number().int().positive().optional(),
|
||||
groupId: z.coerce.number().int().positive().optional(),
|
||||
createdBy: z.string().optional(),
|
||||
});
|
||||
|
||||
@@ -72,14 +71,14 @@ export function CustomerOrderForm({
|
||||
defaultValues: {
|
||||
orderTaker: order?.orderTaker || user?.name || "",
|
||||
customerName: order?.customerName || "",
|
||||
customerPhone: order?.customerPhone || "",
|
||||
productDesignation: order?.productDesignation || "",
|
||||
contactNumber: order?.customerPhone || "",
|
||||
productName: order?.productDesignation || "",
|
||||
productReference: order?.productReference || "",
|
||||
gencode: order?.gencode || "",
|
||||
quantity: order?.quantity || 1,
|
||||
supplierId: order?.supplierId || undefined,
|
||||
status: "En attente de Commande", // Statut fixe
|
||||
deposit: order?.deposit ? order.deposit.toString() : "0",
|
||||
deposit: order?.deposit || 0,
|
||||
isPromotionalPrice: order?.isPromotionalPrice || false,
|
||||
customerNotified: order?.customerNotified || false,
|
||||
groupId: order?.groupId || (user?.role === 'admin' && selectedStoreId ? selectedStoreId : user?.userGroups?.[0]?.groupId) || undefined, // Respect admin store selection
|
||||
@@ -119,17 +118,17 @@ export function CustomerOrderForm({
|
||||
// Prepare data with proper types for frontend schema
|
||||
const submitData = {
|
||||
customerName: data.customerName.trim(),
|
||||
contactNumber: (data as any).customerPhone || (data as any).contactNumber || '',
|
||||
productName: (data as any).productDesignation || (data as any).productName || '',
|
||||
contactNumber: data.contactNumber || '',
|
||||
productName: data.productName || '',
|
||||
quantity: data.quantity,
|
||||
groupId: typeof groupId === 'number' ? groupId : parseInt(groupId.toString()),
|
||||
isPickup: false,
|
||||
notes: (data as any).notes,
|
||||
notes: data.notes,
|
||||
deposit: data.deposit || 0,
|
||||
isPromotionalPrice: (data as any).isPromotionalPrice || false,
|
||||
customerEmail: (data as any).customerEmail,
|
||||
gencode: (data as any).gencode || '',
|
||||
supplierId: (data as any).supplierId || 1,
|
||||
isPromotionalPrice: data.isPromotionalPrice || false,
|
||||
customerEmail: data.customerEmail,
|
||||
gencode: data.gencode || '',
|
||||
supplierId: data.supplierId || 1,
|
||||
};
|
||||
console.log("🔍 Frontend submit data:", submitData);
|
||||
onSubmit(submitData);
|
||||
@@ -193,7 +192,7 @@ export function CustomerOrderForm({
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="customerPhone"
|
||||
name="contactNumber"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>N° de téléphone</FormLabel>
|
||||
@@ -236,7 +235,7 @@ export function CustomerOrderForm({
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="productDesignation"
|
||||
name="productName"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Désignation du produit</FormLabel>
|
||||
|
||||
Reference in new issue
Block a user