fix: zobrazení QR kódu k úhradě bez obnovení stránky
CI / Generate TypeScript types (push) Successful in 11s
CI / Server unit tests (push) Successful in 31s
CI / Build server (push) Successful in 29s
CI / Build client (push) Successful in 40s
CI / Playwright E2E tests (push) Successful in 1m41s
CI / Build and push Docker image (push) Successful in 48s
CI / Notify (push) Successful in 2s
CI / Generate TypeScript types (push) Successful in 11s
CI / Server unit tests (push) Successful in 31s
CI / Build server (push) Successful in 29s
CI / Build client (push) Successful in 40s
CI / Playwright E2E tests (push) Successful in 1m41s
CI / Build and push Docker image (push) Successful in 48s
CI / Notify (push) Successful in 2s
Server po vygenerování QR kódů nejdřív pošle příjemci událost pendingQr a hned poté všem rozešle data skupiny ve stavu Doručeno. Sdílená data nevyřízené platby neobsahují (jsou per-uživatel, jen v GET /api/data), klient jimi ale přepsal celý stav, takže čerstvý QR kód i jeho dialog hned zmizely a objevily se až po F5. Na hlavní stránce QR mizel při každé změně volby oběda kohokoli. Při převzetí dat z websocketu i z odpovědí na úpravy se nevyřízené platby ponechávají z předchozího stavu. QR kódy skupiny vrácené před objednání (server je při tom maže) se z nich odeberou a příchozí QR se nepřidá dvakrát.
This commit is contained in:
4 files changed
+53
-7
No files matched your search
+8
-3
@@ -46,6 +46,7 @@ import { useEasterEgg } from './context/eggs';
|
||||
import { ClientData, Food, MealSlot, PendingQr, PizzaOrder, DepartureTime, PizzaDayState, Restaurant, RestaurantDayMenu, RestaurantDayMenuMap, LunchChoice, LocationLunchChoicesMap, UserLunchChoice, PizzaVariant, getData, getEasterEggImage, addPizza, removePizza, updatePizzaDayNote, deletePizzaDay, lockPizzaDay, unlockPizzaDay, finishOrder, finishDelivery, addChoice, removeChoices, removeChoice, updateNote, updatePrice, changeDepartureTime, setBuyer, generateQr } from '../../types';
|
||||
import { CHOICES_WITHOUT_PRICE, getLunchChoiceName } from './enums';
|
||||
import { isArrowNavigationBlocked } from './utils/arrowNavigation';
|
||||
import { appendPendingQr, pruneRevertedGroupQrs, withPendingQrsFrom } from './utils/pendingQrs';
|
||||
// import FallingLeaves, { LEAF_PRESETS, LEAF_COLOR_THEMES } from './FallingLeaves';
|
||||
// import './FallingLeaves.scss';
|
||||
|
||||
@@ -157,14 +158,18 @@ function App() {
|
||||
});
|
||||
socket.on(EVENT_MESSAGE, (newData: ClientData) => {
|
||||
// console.log("Přijata nová data ze socketu", newData);
|
||||
if (newData.slot === MealSlot.EXTRA) return;
|
||||
if (newData.slot === MealSlot.EXTRA) {
|
||||
// Objednávky hlavní stránka nezobrazuje, jen podle nich uklidí QR kódy vrácených skupin
|
||||
setData(prev => pruneRevertedGroupQrs(prev, newData.groups));
|
||||
return;
|
||||
}
|
||||
// Aktualizujeme pouze, pokud jsme dostali data pro den, který máme aktuálně zobrazený
|
||||
if (dayIndexRef.current == null || newData.dayIndex === dayIndexRef.current) {
|
||||
setData(newData);
|
||||
setData(prev => withPendingQrsFrom(prev, newData));
|
||||
}
|
||||
});
|
||||
socket.on(EVENT_PENDING_QR, (pendingQr: PendingQr) => {
|
||||
setData(prev => prev ? { ...prev, pendingQrs: [...(prev.pendingQrs ?? []), pendingQr] } : prev);
|
||||
setData(prev => appendPendingQr(prev, pendingQr));
|
||||
});
|
||||
|
||||
return () => {
|
||||
|
||||
@@ -31,6 +31,7 @@ import GenerateMockOrdersModal from '../components/modals/GenerateMockOrdersModa
|
||||
import PendingPayments from '../components/PendingPayments';
|
||||
import OrderProgress, { PROVIDER_LABEL } from '../components/OrderProgress';
|
||||
import { isArrowNavigationBlocked } from '../utils/arrowNavigation';
|
||||
import { appendPendingQr, withPendingQrsFrom } from '../utils/pendingQrs';
|
||||
|
||||
const SLOT = MealSlot.EXTRA;
|
||||
const TIME_REGEX = /^([01]\d|2[0-3]):[0-5]\d$/;
|
||||
@@ -192,14 +193,14 @@ export default function OrderGroupsPage() {
|
||||
// Živé aktualizace se týkají vždy dneška – při zobrazení historie je ignorujeme
|
||||
if (selectedDateRef.current) return;
|
||||
if (newData.slot === SLOT) setData(prev => ({
|
||||
...newData,
|
||||
...withPendingQrsFrom(prev, newData),
|
||||
stores: newData.stores ?? prev?.stores,
|
||||
}));
|
||||
});
|
||||
// Nová nevyřízená platba (QR kód) – připojíme do dat, aby se zobrazila i bez znovunačtení stránky
|
||||
socket.on(EVENT_PENDING_QR, (pendingQr: PendingQr) => {
|
||||
if (selectedDateRef.current) return;
|
||||
setData(prev => prev ? { ...prev, pendingQrs: [...(prev.pendingQrs ?? []), pendingQr] } : prev);
|
||||
setData(prev => appendPendingQr(prev, pendingQr));
|
||||
});
|
||||
return () => { socket.off(EVENT_MESSAGE); socket.off(EVENT_PENDING_QR); };
|
||||
}, [socket]);
|
||||
@@ -253,7 +254,7 @@ export default function OrderGroupsPage() {
|
||||
return false;
|
||||
}
|
||||
if (result?.data) {
|
||||
setData(result.data);
|
||||
setData(prev => withPendingQrsFrom(prev, result.data));
|
||||
socket.emit?.('message', result.data as ClientData);
|
||||
}
|
||||
// Sada dnů s objednávkou se mohla změnit (vytvoření/smazání skupiny)
|
||||
@@ -1067,7 +1068,7 @@ export default function OrderGroupsPage() {
|
||||
group={feesModal}
|
||||
onSaved={newData => {
|
||||
if (newData) {
|
||||
setData(newData);
|
||||
setData(prev => withPendingQrsFrom(prev, newData));
|
||||
socket.emit?.('message', newData as ClientData);
|
||||
}
|
||||
setFeesModal(null);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { ClientData, GroupState, OrderGroup, PendingQr } from '../../../types';
|
||||
|
||||
// Nevyřízené platby (QR kódy) jsou per-uživatel a server je přidává jen do odpovědi GET /api/data.
|
||||
// Sdílená data z websocketu ani odpovědi na úpravy je neobsahují, proto se při jejich převzetí
|
||||
// musí ponechat dosavadní QR kódy – jinak by právě doručený QR kód (a jeho dialog) hned zmizel.
|
||||
|
||||
/** QR kód skupiny, která se vrátila před objednání – server její QR kódy při tom smazal. */
|
||||
function isRevertedGroupQr(qr: PendingQr, groups: OrderGroup[]): boolean {
|
||||
if (!qr.groupId) return false;
|
||||
const group = groups.find(g => g.id === qr.groupId);
|
||||
return group?.state === GroupState.OPEN || group?.state === GroupState.LOCKED;
|
||||
}
|
||||
|
||||
function withoutRevertedGroupQrs(qrs: PendingQr[] | undefined, groups: OrderGroup[] | undefined): PendingQr[] | undefined {
|
||||
if (!qrs || !groups) return qrs;
|
||||
const kept = qrs.filter(qr => !isRevertedGroupQr(qr, groups));
|
||||
return kept.length === qrs.length ? qrs : kept;
|
||||
}
|
||||
|
||||
/** Převezme nová data, ale nevyřízené platby ponechá z předchozího stavu. */
|
||||
export function withPendingQrsFrom(prev: ClientData | undefined, next: ClientData): ClientData {
|
||||
return { ...next, pendingQrs: withoutRevertedGroupQrs(prev?.pendingQrs, next.groups) };
|
||||
}
|
||||
|
||||
/** Odebere QR kódy skupin, které se podle `groups` vrátily před objednání (jinak data nemění). */
|
||||
export function pruneRevertedGroupQrs(data: ClientData | undefined, groups: OrderGroup[] | undefined): ClientData | undefined {
|
||||
const kept = withoutRevertedGroupQrs(data?.pendingQrs, groups);
|
||||
return !data || kept === data.pendingQrs ? data : { ...data, pendingQrs: kept };
|
||||
}
|
||||
|
||||
/** Přidá nově doručený QR kód (bez duplicit, pokud už dorazil i s načtením dat). */
|
||||
export function appendPendingQr(data: ClientData | undefined, qr: PendingQr): ClientData | undefined {
|
||||
if (!data) return data;
|
||||
const existing = data.pendingQrs ?? [];
|
||||
if (existing.some(q => q.id === qr.id)) return data;
|
||||
return { ...data, pendingQrs: [...existing, qr] };
|
||||
}
|
||||
Reference in new issue
Block a user