This commit is contained in:
Veronika Smirnova
2025-07-28 16:15:55 +03:00

View File

@ -180,7 +180,6 @@ export function RealSupplyOrdersTab() {
onCompleted: (data) => {
if (data.updateSupplyOrderStatus.success) {
toast.success(data.updateSupplyOrderStatus.message);
refetch();
} else {
toast.error(data.updateSupplyOrderStatus.message);
}
@ -189,6 +188,45 @@ export function RealSupplyOrdersTab() {
console.error("Error updating supply order status:", error);
toast.error("Ошибка при обновлении статуса заказа");
},
update: (cache, { data }) => {
if (data?.updateSupplyOrderStatus?.success && data?.updateSupplyOrderStatus?.order) {
console.log(`✅ Обновляем кэш для заказа ${data.updateSupplyOrderStatus.order.id} на статус ${data.updateSupplyOrderStatus.order.status}`);
// Точечно обновляем кэш для конкретного заказа
cache.modify({
id: cache.identify(data.updateSupplyOrderStatus.order),
fields: {
status() {
console.log(`📝 Обновляем поле status для заказа ${data.updateSupplyOrderStatus.order.id}`);
return data.updateSupplyOrderStatus.order.status;
},
},
});
// Также обновляем данные в запросе GET_SUPPLY_ORDERS если нужно
try {
const existingData = cache.readQuery({ query: GET_SUPPLY_ORDERS }) as any;
if (existingData?.supplyOrders) {
console.log(`📋 Обновляем список заказов в кэше, всего заказов: ${existingData.supplyOrders.length}`);
cache.writeQuery({
query: GET_SUPPLY_ORDERS,
data: {
...existingData,
supplyOrders: existingData.supplyOrders.map((order: any) => {
if (order.id === data.updateSupplyOrderStatus.order.id) {
console.log(`🎯 Найден и обновлен заказ ${order.id}`);
return { ...order, status: data.updateSupplyOrderStatus.order.status };
}
return order;
}),
},
});
}
} catch (error) {
console.log("Cache update fallback - data not in cache yet", error);
}
}
},
}
);
@ -202,6 +240,20 @@ export function RealSupplyOrdersTab() {
}
);
// Отладочное логирование для проверки дублирующихся ID
React.useEffect(() => {
if (incomingSupplyOrders.length > 0) {
const ids = incomingSupplyOrders.map(order => order.id);
const uniqueIds = new Set(ids);
if (ids.length !== uniqueIds.size) {
console.warn(`⚠️ Обнаружены дублирующиеся ID заказов! Всего: ${ids.length}, уникальных: ${uniqueIds.size}`);
console.warn('Дублирующиеся ID:', ids.filter((id, index) => ids.indexOf(id) !== index));
} else {
console.log(`Все ID заказов уникальны: ${ids.length} заказов`);
}
}
}, [incomingSupplyOrders]);
// Функции для работы с таблицей
const toggleOrderExpansion = (orderId: string) => {
const newExpanded = new Set(expandedOrders);
@ -223,6 +275,8 @@ export function RealSupplyOrdersTab() {
};
const handleStatusUpdate = async (orderId: string, status: string) => {
console.log(`🔄 Обновляем статус заказа ${orderId} на ${status}`);
try {
await updateSupplyOrderStatus({
variables: {