This commit is contained in:
Samandar Turgunboyev
2026-01-24 16:46:02 +05:00
parent 1f77cc360d
commit ecc0029322
24 changed files with 632 additions and 563 deletions

View File

@@ -73,15 +73,12 @@ const RefreshOrder = () => {
const t = useTranslations();
const queryClient = useQueryClient();
const initialCartItems = initialValues?.items.map((item) => ({
const initialCartItems = initialValues?.cart_item.map((item) => ({
id: item.id,
product_id: item.product.id,
product_name: item.product.name,
product_price: item.price,
product_image:
item.product.image ||
item.product.images?.[0]?.image ||
'/placeholder.svg',
product_price: item.product.prices[0].price,
product_image: item.product.images[0].image || '/placeholder.svg',
quantity: item.quantity,
}));
@@ -90,7 +87,7 @@ const RefreshOrder = () => {
const form = useForm<z.infer<typeof orderForm>>({
resolver: zodResolver(orderForm),
defaultValues: {
comment: initialValues?.comment,
comment: '',
lat: '41.311081',
long: '69.240562',
},
@@ -100,7 +97,7 @@ const RefreshOrder = () => {
const subtotal = cartItems
? cartItems.reduce(
(sum, item) => sum + item.product_price * item.quantity,
(sum, item) => sum + Number(item.product_price) * item.quantity,
0,
)
: 0;
@@ -114,7 +111,7 @@ const RefreshOrder = () => {
queryClient.refetchQueries({ queryKey: ['cart_items'] });
},
onError: () => {
toast.error('Xatolik yuz berdi', {
toast.error(t('Xatolik yuz berdi'), {
richColors: true,
position: 'top-center',
});
@@ -205,7 +202,7 @@ const RefreshOrder = () => {
const onSubmit = (value: z.infer<typeof orderForm>) => {
if (!deliveryDate) {
toast.error('Yetkazib berish sanasini tanlang', {
toast.error(t('Yetkazib berish sanasini tanlang'), {
richColors: true,
position: 'top-center',
});
@@ -213,7 +210,7 @@ const RefreshOrder = () => {
}
if (!selectedTimeSlot) {
toast.error('Yetkazib berish vaqtini tanlang', {
toast.error(t('Yetkazib berish vaqtini tanlang'), {
richColors: true,
position: 'top-center',
});
@@ -221,25 +218,48 @@ const RefreshOrder = () => {
}
if (initialValues === null) {
toast.error('Savatcha bosh', {
toast.error(t('Savatcha bosh'), {
richColors: true,
position: 'top-center',
});
return;
}
const items = initialValues.items.map((item) => ({
product_id: Number(item.product.id),
quantity: item.quantity,
}));
const order_products = initialValues.cart_item
.filter(
(item) =>
item.product.prices &&
item.product.prices.length > 0 &&
item.product.prices[0].price_type?.code &&
item.product.prices[0].price,
)
.map((item) => ({
inventory_kind: 'G',
product_code: item.product.code,
on_balance: 'Y',
order_quant: item.quantity,
price_type_code: item.product.prices![0].price_type.code,
product_price: item.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,
},
],
});
};
@@ -513,7 +533,7 @@ const RefreshOrder = () => {
</p>
<p className="font-semibold text-sm">
{formatPrice(
item.product_price * item.quantity,
Number(item.product_price) * item.quantity,
true,
)}
</p>