order create

This commit is contained in:
Samandar Turgunboyev
2026-01-23 19:29:04 +05:00
parent a5e100ed90
commit c2a2c2b09b
11 changed files with 187 additions and 60 deletions

View File

@@ -95,10 +95,19 @@ const OrderPage = () => {
const { mutate, isPending } = useMutation({
mutationFn: (body: OrderCreateBody) => cart_api.createOrder(body),
onSuccess: () => {
setOrderSuccess(true);
setCart(cart_id);
queryClinet.refetchQueries({ queryKey: ['cart_items'] });
onSuccess: (res) => {
const message = JSON.parse(res.data.response);
if (message.successes.length > 0) {
setOrderSuccess(true);
setCart(cart_id);
queryClinet.refetchQueries({ queryKey: ['cart_items'] });
} else {
toast.error('Xatolik yuz berdi', {
richColors: true,
position: 'top-center',
});
}
},
onError: (error: AxiosError) => {
(
@@ -123,7 +132,10 @@ const OrderPage = () => {
const [selectedTimeSlot, setSelectedTimeSlot] = useState<string>('');
const subtotal = cartItems?.reduce(
(sum, item) => sum + item.product_price * item.quantity,
(sum, item) =>
sum +
Math.max(...item.product.prices.map((e) => Number(e.price))) *
item.quantity,
0,
);
@@ -247,18 +259,45 @@ const OrderPage = () => {
return;
}
const items = cartItems.map((item) => ({
product_id: Number(item.product_id),
quantity: item.quantity,
}));
const order_products: {
inventory_kind: sting;
product_code: sting;
on_balance: sting;
order_quant: number;
price_type_code: sting;
product_price: sting;
warehouse_code: sting;
}[] = [];
cartItems.forEach((e) => {
order_products.push({
inventory_kind: 'G',
product_code: e.product.code,
on_balance: 'Y',
order_quant: e.quantity,
price_type_code: e.product.prices[0].price_type.code,
product_price: e.product.prices[0].price,
warehouse_code: 'wh1',
});
});
mutate({
comment: value.comment,
items: items,
long: Number(value.long),
lat: Number(value.lat),
date: formatDate.format(deliveryDate, 'YYYY-MM-DD'),
time: selectedTimeSlot,
order: [
{
filial_code: 'dodge',
delivery_date: formatDate.format(deliveryDate, 'DD.MM.YYYY'),
room_code: '100',
deal_time: formatDate.format(deliveryDate, 'DD.MM.YYYY'),
robot_code: 'r2',
status: 'B#N',
sales_manager_code: '1',
person_code: '12345678',
currency_code: '860',
owner_person_code: '1234567',
note: value.comment,
order_products: order_products,
},
],
});
}