feat: generování mock dat ve vývoji pro objednávky
CI / Generate TypeScript types (push) Successful in 11s
CI / Server unit tests (push) Successful in 27s
CI / Build server (push) Successful in 29s
CI / Build client (push) Successful in 42s
CI / Playwright E2E tests (push) Successful in 1m43s
CI / Build and push Docker image (push) Successful in 46s
CI / Notify (push) Successful in 2s
CI / Generate TypeScript types (push) Successful in 11s
CI / Server unit tests (push) Successful in 27s
CI / Build server (push) Successful in 29s
CI / Build client (push) Successful in 42s
CI / Playwright E2E tests (push) Successful in 1m43s
CI / Build and push Docker image (push) Successful in 46s
CI / Notify (push) Successful in 2s
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
import { useState } from "react";
|
||||
import { Modal, Button, Form, Alert } from "react-bootstrap";
|
||||
import { generateMockOrders } from "../../../../types";
|
||||
|
||||
type Props = {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
/** Příznak, zda je pro dnešní den založena alespoň jedna skupina objednávky. */
|
||||
hasGroups: boolean;
|
||||
/** Příznak, zda je nadefinován alespoň jeden obchod (bez něj nelze generovat). */
|
||||
hasStores: boolean;
|
||||
};
|
||||
|
||||
const DEFAULT_COUNT = '3';
|
||||
const DEFAULT_MIN_AMOUNT = '100';
|
||||
const DEFAULT_MAX_AMOUNT = '1000';
|
||||
|
||||
/** Vybere český tvar slova podle počtu (1 osoba / 2 osoby / 5 osob). */
|
||||
function plural(count: number, one: string, few: string, many: string): string {
|
||||
if (count === 1) return one;
|
||||
if (count >= 2 && count <= 4) return few;
|
||||
return many;
|
||||
}
|
||||
|
||||
/** Modální dialog pro generování mock dat sekce Objednání (pouze DEV). */
|
||||
export default function GenerateMockOrdersModal({ isOpen, onClose, hasGroups, hasStores }: Readonly<Props>) {
|
||||
const [count, setCount] = useState<string>(DEFAULT_COUNT);
|
||||
const [minAmount, setMinAmount] = useState<string>(DEFAULT_MIN_AMOUNT);
|
||||
const [maxAmount, setMaxAmount] = useState<string>(DEFAULT_MAX_AMOUNT);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [success, setSuccess] = useState<string | null>(null);
|
||||
|
||||
const handleGenerate = async () => {
|
||||
setError(null);
|
||||
|
||||
const countNum = parseInt(count, 10);
|
||||
if (isNaN(countNum) || countNum < 1 || countNum > 50) {
|
||||
setError('Počet osob musí být číslo mezi 1 a 50');
|
||||
return;
|
||||
}
|
||||
const minNum = parseInt(minAmount, 10);
|
||||
const maxNum = parseInt(maxAmount, 10);
|
||||
if (isNaN(minNum) || isNaN(maxNum) || minNum < 0 || maxNum < minNum) {
|
||||
setError('Zadejte platný rozsah částek (od ≤ do)');
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await generateMockOrders({
|
||||
body: { count: countNum, minAmount: minNum, maxAmount: maxNum },
|
||||
});
|
||||
if (response.error) {
|
||||
setError((response.error as any).error || 'Nastala chyba při generování dat');
|
||||
} else {
|
||||
const groups = response.data?.groups ?? [];
|
||||
const total = response.data?.count ?? 0;
|
||||
const created = groups.find(g => g.created);
|
||||
setSuccess(
|
||||
`Doplněno: ${total} ${plural(total, 'osoba', 'osoby', 'osob')}`
|
||||
+ ` / ${groups.length} ${plural(groups.length, 'skupina', 'skupiny', 'skupin')}`
|
||||
+ (created ? ` (skupina „${created.name}“ byla nově založena).` : '.')
|
||||
);
|
||||
setTimeout(() => {
|
||||
onClose();
|
||||
setSuccess(null);
|
||||
}, 2000);
|
||||
}
|
||||
} catch (e: any) {
|
||||
setError(e.message || 'Nastala chyba při generování dat');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setError(null);
|
||||
setSuccess(null);
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={isOpen} onHide={handleClose}>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title><h2>Generovat mock objednávky</h2></Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
{success ? (
|
||||
<Alert variant="success">{success}</Alert>
|
||||
) : (
|
||||
<>
|
||||
<Alert variant="warning">
|
||||
<strong>DEV režim</strong> - Tato funkce je dostupná pouze ve vývojovém prostředí.
|
||||
Data se generují vždy jen pro aktuální den.
|
||||
</Alert>
|
||||
|
||||
{error && (
|
||||
<Alert variant="danger" onClose={() => setError(null)} dismissible>
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{hasStores ? (
|
||||
<>
|
||||
<Form.Group className="mb-3">
|
||||
<Form.Label>Počet osob</Form.Label>
|
||||
<Form.Control
|
||||
type="number"
|
||||
value={count}
|
||||
onChange={e => setCount(e.target.value)}
|
||||
min={1}
|
||||
max={50}
|
||||
onKeyDown={e => e.stopPropagation()}
|
||||
/>
|
||||
<Form.Text className="text-muted">
|
||||
{hasGroups
|
||||
? 'Zadaný počet osob se doplní do každé existující skupiny.'
|
||||
: 'Není založena žádná skupina — jedna se založí z náhodně vybraného obchodu a doplní se do ní zadaný počet osob.'}
|
||||
</Form.Text>
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group className="mb-3">
|
||||
<Form.Label>Rozsah částek (Kč)</Form.Label>
|
||||
<div className="d-flex gap-2 align-items-center">
|
||||
<Form.Control
|
||||
type="number"
|
||||
value={minAmount}
|
||||
onChange={e => setMinAmount(e.target.value)}
|
||||
min={0}
|
||||
onKeyDown={e => e.stopPropagation()}
|
||||
/>
|
||||
<span>—</span>
|
||||
<Form.Control
|
||||
type="number"
|
||||
value={maxAmount}
|
||||
onChange={e => setMaxAmount(e.target.value)}
|
||||
min={0}
|
||||
onKeyDown={e => e.stopPropagation()}
|
||||
/>
|
||||
</div>
|
||||
<Form.Text className="text-muted">
|
||||
Každé osobě se nastaví náhodná částka z tohoto rozmezí a do poznámky náhodné jídlo.
|
||||
</Form.Text>
|
||||
</Form.Group>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-muted mb-0">
|
||||
Není nadefinován žádný obchod — mock objednávky nelze vygenerovat.
|
||||
Nejprve přidejte obchod ve správě obchodů.
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
{!success && (
|
||||
<>
|
||||
<Button variant="secondary" onClick={handleClose} disabled={loading}>
|
||||
Storno
|
||||
</Button>
|
||||
<Button variant="primary" onClick={handleGenerate} disabled={loading || !hasStores}>
|
||||
{loading ? 'Generuji...' : 'Generovat'}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{success && (
|
||||
<Button variant="secondary" onClick={handleClose}>
|
||||
Zavřít
|
||||
</Button>
|
||||
)}
|
||||
</Modal.Footer>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import StoreAdminModal from '../components/modals/StoreAdminModal';
|
||||
import PayForGroupModal from '../components/modals/PayForGroupModal';
|
||||
import EditGroupFeesModal from '../components/modals/EditGroupFeesModal';
|
||||
import BoltSimulationModal from '../components/modals/BoltSimulationModal';
|
||||
import GenerateMockOrdersModal from '../components/modals/GenerateMockOrdersModal';
|
||||
import PendingPayments from '../components/PendingPayments';
|
||||
import OrderProgress, { PROVIDER_LABEL } from '../components/OrderProgress';
|
||||
|
||||
@@ -137,6 +138,7 @@ export default function OrderGroupsPage() {
|
||||
const [payModal, setPayModal] = useState<OrderGroup | null>(null);
|
||||
const [feesModal, setFeesModal] = useState<OrderGroup | null>(null);
|
||||
const [boltSimModal, setBoltSimModal] = useState<OrderGroup | null>(null);
|
||||
const [mockOrdersModalOpen, setMockOrdersModalOpen] = useState(false);
|
||||
const [confirmOrderGroup, setConfirmOrderGroup] = useState<OrderGroup | null>(null);
|
||||
const [pageError, setPageError] = useState<string | null>(null);
|
||||
|
||||
@@ -401,10 +403,17 @@ export default function OrderGroupsPage() {
|
||||
<div className="wrapper">
|
||||
<div className="d-flex align-items-center justify-content-between mb-1">
|
||||
<h1 className="title mb-0">Objednání</h1>
|
||||
<Button variant="outline-primary" size="sm" onClick={() => setAdminModalOpen(true)} title="Správa obchodů">
|
||||
<FontAwesomeIcon icon={faGear} className="me-1" />
|
||||
Obchody
|
||||
</Button>
|
||||
<div className="d-flex gap-2">
|
||||
{IS_DEV && !isReadOnly && (
|
||||
<Button variant="outline-warning" size="sm" onClick={() => setMockOrdersModalOpen(true)} title="Generovat mock objednávky (DEV)">
|
||||
🔧 Mock objednávky
|
||||
</Button>
|
||||
)}
|
||||
<Button variant="outline-primary" size="sm" onClick={() => setAdminModalOpen(true)} title="Správa obchodů">
|
||||
<FontAwesomeIcon icon={faGear} className="me-1" />
|
||||
Obchody
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p style={{ color: 'var(--luncher-text-muted)' }}>Skupinové objednávky z obchodů a restaurací</p>
|
||||
|
||||
@@ -955,6 +964,19 @@ export default function OrderGroupsPage() {
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{IS_DEV && (
|
||||
<GenerateMockOrdersModal
|
||||
isOpen={mockOrdersModalOpen}
|
||||
onClose={() => {
|
||||
setMockOrdersModalOpen(false);
|
||||
// Data přijdou i websocketem, po založení skupiny se ale mění i dny s objednávkou
|
||||
fetchData();
|
||||
fetchOrderDates();
|
||||
}}
|
||||
hasGroups={groups.length > 0}
|
||||
hasStores={stores.length > 0}
|
||||
/>
|
||||
)}
|
||||
{IS_DEV && boltSimModal && (
|
||||
<BoltSimulationModal
|
||||
isOpen={!!boltSimModal}
|
||||
|
||||
Reference in New Issue
Block a user