mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-16 19:56:32 +02:00
Fix customer order creation for employees by updating the schema
Update the customer order schema and data mapping in the frontend to correctly handle employee role permissions when creating customer orders. 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/qPpS8VH
This commit is contained in:
1 parent
cf738cc49a
commit
fcad53ae1d
5 files changed
+296
-16
No files matched your search
@@ -22,17 +22,13 @@ import {
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { insertCustomerOrderSchema, type CustomerOrderWithRelations, type Group, type Supplier } from "@shared/schema";
|
||||
import { insertCustomerOrderFrontendSchema, type CustomerOrderWithRelations, type Group, type Supplier } from "@shared/schema";
|
||||
import { useStore } from "@/components/Layout";
|
||||
|
||||
const customerOrderFormSchema = insertCustomerOrderSchema.extend({
|
||||
deposit: z.string().optional(),
|
||||
gencode: z.string().min(1, "Le gencode est obligatoire"),
|
||||
customerName: z.string().min(1, "Le nom du client est obligatoire"),
|
||||
quantity: z.union([z.string(), z.number()]).transform(val => typeof val === 'string' ? parseInt(val) || 1 : val),
|
||||
supplierId: z.union([z.string(), z.number()]).transform(val => typeof val === 'string' ? parseInt(val) : val),
|
||||
groupId: z.union([z.string(), z.number()]).transform(val => typeof val === 'string' ? parseInt(val) : val).optional(),
|
||||
createdBy: z.string().optional(), // Will be set automatically
|
||||
const customerOrderFormSchema = insertCustomerOrderFrontendSchema.extend({
|
||||
deposit: z.number().optional().default(0),
|
||||
groupId: z.number().int().positive().optional(),
|
||||
createdBy: z.string().optional(),
|
||||
});
|
||||
|
||||
type CustomerOrderFormData = z.infer<typeof customerOrderFormSchema>;
|
||||
@@ -120,15 +116,22 @@ export function CustomerOrderForm({
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare data with proper types
|
||||
// Prepare data with proper types for frontend schema
|
||||
const submitData = {
|
||||
...data,
|
||||
customerName: data.customerName.trim(), // Clean the customer name
|
||||
deposit: data.deposit || "0.00", // Keep as string for decimal field
|
||||
customerName: data.customerName.trim(),
|
||||
contactNumber: (data as any).customerPhone || (data as any).contactNumber || '',
|
||||
productName: (data as any).productDesignation || (data as any).productName || '',
|
||||
quantity: data.quantity,
|
||||
groupId: typeof groupId === 'number' ? groupId : parseInt(groupId.toString()),
|
||||
createdBy: user?.id || '', // Add the current user ID
|
||||
isPickup: false,
|
||||
notes: (data as any).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,
|
||||
};
|
||||
console.log("Processed submit data:", submitData);
|
||||
console.log("🔍 Frontend submit data:", submitData);
|
||||
onSubmit(submitData);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user