chore(release): v2.4.35 — lint cleanup (68→0) + duplicate-Zavřít modal fix
UI fix:
- Close-only modals showing a redundant second close button now use
hideCancel: ReceivedInvoices paid-detail modal (was two identical "Zavřít"
buttons) and PlanCellModal "Den je součástí rozsahu".
- Add modal-duplicate-close test enforcing close-only modals set hideCancel.
Lint: cleared all 68 warnings → 0.
- preserve-caught-error: attach { cause } in ai.service / exchange-rates.
- no-require-imports: package.json version read via fs (APP_VERSION) instead
of require(), avoiding a rootDir-expanding static JSON import.
- react-hooks/exhaustive-deps (11): ref-in-cleanup copies, derived-value
useMemo wrapping, PlanGrid field extraction, stable nextKey useCallback,
AuthContext documented cycle-break.
- no-explicit-any (53): precise route param/Prisma types, generic enrich*()
preserving payload shape, minimal vite module type, frontend body/query-key
types, SystemInfo for Settings.
Refactor (test enablement): shift-form types moved to dependency-free
shiftFormTypes.ts so the print-HTML builders are unit-testable without the
component graph; characterization test pins their output.
Gates: 649 tests pass, tsc -b clean, lint 0. Verified touched flows live
via Playwright (PlanWork CRUD + optimistic cache, warehouse form keys,
Settings system info, invoice detail).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -488,6 +488,7 @@ function DayInRangeModal(
|
||||
onClose={onClose}
|
||||
onSubmit={onClose}
|
||||
submitText="Zavřít — ponechat rozsah beze změny"
|
||||
hideCancel
|
||||
maxWidth="md"
|
||||
>
|
||||
<Typography variant="body2" sx={{ mb: 2 }}>
|
||||
|
||||
@@ -491,9 +491,11 @@ export default function PlanGrid({
|
||||
}, [projects]);
|
||||
// Memoize the day list so it isn't rebuilt on every render (only when the
|
||||
// visible range changes). Stable identity also keeps the row map cheap.
|
||||
const dateFrom = data?.date_from;
|
||||
const dateTo = data?.date_to;
|
||||
const days = useMemo(
|
||||
() => (data ? eachDay(data.date_from, data.date_to) : []),
|
||||
[data?.date_from, data?.date_to],
|
||||
() => (dateFrom && dateTo ? eachDay(dateFrom, dateTo) : []),
|
||||
[dateFrom, dateTo],
|
||||
);
|
||||
|
||||
if (!data) return <LoadingState />;
|
||||
|
||||
@@ -19,46 +19,22 @@ import {
|
||||
} from "../utils/attendanceHelpers";
|
||||
|
||||
// ---------- Shared types ----------
|
||||
|
||||
export interface ShiftFormData {
|
||||
user_id: string;
|
||||
shift_date: string;
|
||||
leave_type: string;
|
||||
leave_hours: number;
|
||||
arrival_date: string;
|
||||
arrival_time: string;
|
||||
break_start_date: string;
|
||||
break_start_time: string;
|
||||
break_end_date: string;
|
||||
break_end_time: string;
|
||||
departure_date: string;
|
||||
departure_time: string;
|
||||
notes: string;
|
||||
}
|
||||
|
||||
export interface ProjectLog {
|
||||
_key?: string;
|
||||
id?: number;
|
||||
project_id: string | number;
|
||||
hours: string | number;
|
||||
minutes: string | number;
|
||||
}
|
||||
|
||||
export interface Project {
|
||||
id: number | string;
|
||||
project_number: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: number | string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface EditingRecord {
|
||||
user_name: string;
|
||||
shift_date: string;
|
||||
}
|
||||
// Definitions live in the dependency-free ./shiftFormTypes module; re-exported
|
||||
// here so existing importers of ShiftFormModal keep working.
|
||||
export type {
|
||||
ShiftFormData,
|
||||
ProjectLog,
|
||||
Project,
|
||||
User,
|
||||
EditingRecord,
|
||||
} from "./shiftFormTypes";
|
||||
import type {
|
||||
ShiftFormData,
|
||||
ProjectLog,
|
||||
Project,
|
||||
User,
|
||||
EditingRecord,
|
||||
} from "./shiftFormTypes";
|
||||
|
||||
// ---------- Sub-component props ----------
|
||||
|
||||
|
||||
44
src/admin/components/shiftFormTypes.ts
Normal file
44
src/admin/components/shiftFormTypes.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
// Shared attendance shift-form types, kept in a dependency-free module so they
|
||||
// can be imported without pulling in the ShiftFormModal component graph (which
|
||||
// reaches MUI/import.meta files that don't compile under the CommonJS test
|
||||
// project). ShiftFormModal re-exports these for backward compatibility.
|
||||
|
||||
export interface ShiftFormData {
|
||||
user_id: string;
|
||||
shift_date: string;
|
||||
leave_type: string;
|
||||
leave_hours: number;
|
||||
arrival_date: string;
|
||||
arrival_time: string;
|
||||
break_start_date: string;
|
||||
break_start_time: string;
|
||||
break_end_date: string;
|
||||
break_end_time: string;
|
||||
departure_date: string;
|
||||
departure_time: string;
|
||||
notes: string;
|
||||
}
|
||||
|
||||
export interface ProjectLog {
|
||||
_key?: string;
|
||||
id?: number;
|
||||
project_id: string | number;
|
||||
hours: string | number;
|
||||
minutes: string | number;
|
||||
}
|
||||
|
||||
export interface Project {
|
||||
id: number | string;
|
||||
project_number: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: number | string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface EditingRecord {
|
||||
user_name: string;
|
||||
shift_date: string;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import { Select } from "../../ui";
|
||||
@@ -26,7 +26,7 @@ export default function ReservationPicker({
|
||||
}),
|
||||
);
|
||||
|
||||
const reservations = result?.data ?? [];
|
||||
const reservations = useMemo(() => result?.data ?? [], [result?.data]);
|
||||
|
||||
// When item/project change, the loaded reservation list changes. If the
|
||||
// currently-selected reservation is no longer available, clear it and notify
|
||||
|
||||
@@ -43,9 +43,10 @@ export function AlertProvider({ children }: { children: ReactNode }) {
|
||||
const timeoutsRef = useRef<Set<ReturnType<typeof setTimeout>>>(new Set());
|
||||
|
||||
useEffect(() => {
|
||||
const timeouts = timeoutsRef.current;
|
||||
return () => {
|
||||
timeoutsRef.current.forEach(clearTimeout);
|
||||
timeoutsRef.current.clear();
|
||||
timeouts.forEach(clearTimeout);
|
||||
timeouts.clear();
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -122,6 +122,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
);
|
||||
}
|
||||
},
|
||||
// silentRefresh and setAccessTokenFn reference each other; listing
|
||||
// silentRefresh here would recreate both callbacks on every render. The
|
||||
// scheduled silentRefresh is safe to call as a stable closure because all
|
||||
// of its state lives in refs.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[],
|
||||
);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import type {
|
||||
ProjectLog,
|
||||
Project,
|
||||
User,
|
||||
} from "../components/ShiftFormModal";
|
||||
} from "../components/shiftFormTypes";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Types
|
||||
@@ -344,14 +344,25 @@ function escapeHtml(str: string): string {
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function buildProjectLogsHtml(record: Record<string, any>): string {
|
||||
/** Shape of the print endpoint payload consumed by the HTML builders. */
|
||||
interface PrintData {
|
||||
month: string;
|
||||
month_name: string;
|
||||
selected_user_name?: string | null;
|
||||
user_totals: Record<string, UserTotal>;
|
||||
}
|
||||
|
||||
export function buildProjectLogsHtml(record: AttendanceRecord): string {
|
||||
if (record.project_logs && record.project_logs.length > 0) {
|
||||
return record.project_logs
|
||||
.map((log: any) => {
|
||||
.map((log) => {
|
||||
let h: number, m: number;
|
||||
if (log.hours !== null && log.hours !== undefined) {
|
||||
h = parseInt(log.hours) || 0;
|
||||
m = parseInt(log.minutes) || 0;
|
||||
// hours/minutes arrive as string or number — String() before parseInt
|
||||
// (parseInt already coerces to string internally, so this is a no-op
|
||||
// at runtime, it just satisfies parseInt's string parameter type).
|
||||
h = parseInt(String(log.hours)) || 0;
|
||||
m = parseInt(String(log.minutes)) || 0;
|
||||
} else if (log.started_at && log.ended_at) {
|
||||
const mins = Math.max(
|
||||
0,
|
||||
@@ -374,13 +385,13 @@ function buildProjectLogsHtml(record: Record<string, any>): string {
|
||||
return escapeHtml(record.project_name || "—");
|
||||
}
|
||||
|
||||
function buildUserSectionHtml(
|
||||
export function buildUserSectionHtml(
|
||||
userId: string,
|
||||
userData: Record<string, any>,
|
||||
printData: Record<string, any>,
|
||||
userData: UserTotal,
|
||||
printData: PrintData,
|
||||
): string {
|
||||
// Build a date-keyed lookup of the user's records.
|
||||
const recordsByDate = new Map<string, Record<string, any>>();
|
||||
const recordsByDate = new Map<string, AttendanceRecord>();
|
||||
for (const r of userData.records || []) {
|
||||
recordsByDate.set(normalizeDateStr(r.shift_date), r);
|
||||
}
|
||||
@@ -391,7 +402,7 @@ function buildUserSectionHtml(
|
||||
const mo = parseInt(monthStr, 10);
|
||||
const daysInMonth = getDaysInMonth(yr, mo);
|
||||
|
||||
const userRecords = (userData.records || []) as Record<string, any>[];
|
||||
const userRecords = userData.records ?? [];
|
||||
|
||||
const rows: string[] = [];
|
||||
for (let d = 1; d <= daysInMonth; d++) {
|
||||
@@ -588,8 +599,8 @@ function buildUserSectionHtml(
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function buildPrintHtml(
|
||||
pData: Record<string, any>,
|
||||
export function buildPrintHtml(
|
||||
pData: PrintData,
|
||||
userSections: string,
|
||||
emptyMsg: string,
|
||||
filterNote: string,
|
||||
@@ -1330,7 +1341,7 @@ export default function useAttendanceAdmin({ alert }: AlertContext) {
|
||||
const pData = result.data;
|
||||
const userSections = Object.entries(pData.user_totals)
|
||||
.map(([uid, uData]) =>
|
||||
buildUserSectionHtml(uid, uData as Record<string, any>, pData),
|
||||
buildUserSectionHtml(uid, uData as UserTotal, pData),
|
||||
)
|
||||
.join("");
|
||||
const emptyMsg =
|
||||
|
||||
@@ -200,7 +200,7 @@ export function usePlanWork({ initialDate, canEdit }: UsePlanWorkArgs) {
|
||||
// Snapshot the currently-cached grid for a given key. Returns
|
||||
// `undefined` if there's nothing cached (we don't patch empty data).
|
||||
function snapshotGrid(key: readonly unknown[]): GridData | undefined {
|
||||
return qc.getQueryData<GridData>(key as any);
|
||||
return qc.getQueryData<GridData>(key);
|
||||
}
|
||||
|
||||
// Apply a per-date cell patch to the cached grid at `key`. Returns the
|
||||
@@ -312,7 +312,7 @@ export function usePlanWork({ initialDate, canEdit }: UsePlanWorkArgs) {
|
||||
// `ctx` may be `undefined` (e.g. if onMutate itself threw) — guarded below.
|
||||
function rollbackCells(ctx: CellRollback | undefined) {
|
||||
if (!ctx || !ctx.rolled) return;
|
||||
const prev = qc.getQueryData<GridData>(ctx.key as any);
|
||||
const prev = qc.getQueryData<GridData>(ctx.key);
|
||||
if (!prev) return;
|
||||
const userPrev = prev.cells[ctx.userId] ?? {};
|
||||
const userNext = { ...userPrev };
|
||||
@@ -379,7 +379,7 @@ export function usePlanWork({ initialDate, canEdit }: UsePlanWorkArgs) {
|
||||
// Find the user that owns this entry in the current grid by
|
||||
// looking for any cell with entryId === id (we already know
|
||||
// the id from vars; it doesn't change across the update).
|
||||
const grid = qc.getQueryData<GridData>(currentGridKey as any);
|
||||
const grid = qc.getQueryData<GridData>(currentGridKey);
|
||||
let ownerUserId: number | null = null;
|
||||
if (grid) {
|
||||
for (const [uidStr, byDate] of Object.entries(grid.cells)) {
|
||||
@@ -430,7 +430,7 @@ export function usePlanWork({ initialDate, canEdit }: UsePlanWorkArgs) {
|
||||
// For delete we need to know the entry's user_id and full range.
|
||||
// Look it up from the current grid: find the user that has a cell
|
||||
// with entryId === id, and read rangeFrom/rangeTo from that cell.
|
||||
const grid = qc.getQueryData<GridData>(currentGridKey as any);
|
||||
const grid = qc.getQueryData<GridData>(currentGridKey);
|
||||
if (!grid) return null;
|
||||
for (const [uidStr, byDate] of Object.entries(grid.cells)) {
|
||||
let entryRange: { from: string; to: string } | null = null;
|
||||
@@ -511,7 +511,7 @@ export function usePlanWork({ initialDate, canEdit }: UsePlanWorkArgs) {
|
||||
onMutate: (vars): CellRollback => {
|
||||
// Find the user/date for this overrideId in the current grid, then
|
||||
// patch that single cell with the new values.
|
||||
const grid = qc.getQueryData<GridData>(currentGridKey as any);
|
||||
const grid = qc.getQueryData<GridData>(currentGridKey);
|
||||
if (!grid) return null;
|
||||
for (const [uidStr, byDate] of Object.entries(grid.cells)) {
|
||||
for (const [date, cells] of Object.entries(byDate)) {
|
||||
@@ -559,7 +559,7 @@ export function usePlanWork({ initialDate, canEdit }: UsePlanWorkArgs) {
|
||||
method: "DELETE",
|
||||
}),
|
||||
onMutate: (vars): CellRollback => {
|
||||
const grid = qc.getQueryData<GridData>(currentGridKey as any);
|
||||
const grid = qc.getQueryData<GridData>(currentGridKey);
|
||||
if (!grid) return null;
|
||||
for (const [uidStr, byDate] of Object.entries(grid.cells)) {
|
||||
for (const [date, cells] of Object.entries(byDate)) {
|
||||
@@ -600,7 +600,7 @@ export function usePlanWork({ initialDate, canEdit }: UsePlanWorkArgs) {
|
||||
// PlanWork.tsx so they continue to compile unchanged; by the time a
|
||||
// `mutateAsync` promise rejects, the mutation's own `onError` has already
|
||||
// restored the patched cells, so there is nothing left to do here.
|
||||
|
||||
|
||||
function rollbackMutation(_mutation: unknown, _userId: number) {
|
||||
/* no-op — see onMutate/onError above */
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ export default function AttendanceHistory() {
|
||||
const { data, isPending } = useQuery(
|
||||
attendanceHistoryOptions({ month, userId: user?.id }),
|
||||
);
|
||||
const records = data ?? [];
|
||||
const records = useMemo(() => data ?? [], [data]);
|
||||
|
||||
const computed = useMemo(() => {
|
||||
const [yearStr, monthStr] = month.split("-");
|
||||
|
||||
@@ -621,7 +621,10 @@ export default function InvoiceDetail() {
|
||||
const customers = customersQuery.data ?? [];
|
||||
|
||||
const bankAccountsQuery = useQuery(bankAccountsOptions());
|
||||
const bankAccounts = bankAccountsQuery.data ?? [];
|
||||
const bankAccounts = useMemo(
|
||||
() => bankAccountsQuery.data ?? [],
|
||||
[bankAccountsQuery.data],
|
||||
);
|
||||
|
||||
const invoiceQuery = useQuery(invoiceDetailOptions(id));
|
||||
const invoice = invoiceQuery.data ?? null;
|
||||
@@ -656,8 +659,9 @@ export default function InvoiceDetail() {
|
||||
const [deleting, setDeleting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const blobTimeouts = blobTimeoutsRef.current;
|
||||
return () => {
|
||||
blobTimeoutsRef.current.forEach(clearTimeout);
|
||||
blobTimeouts.forEach(clearTimeout);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -121,8 +121,9 @@ export default function OrderDetail() {
|
||||
}, [orderQuery.error]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
useEffect(() => {
|
||||
const blobTimeouts = blobTimeoutsRef.current;
|
||||
return () => {
|
||||
blobTimeoutsRef.current.forEach(clearTimeout);
|
||||
blobTimeouts.forEach(clearTimeout);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@ import {
|
||||
getCell,
|
||||
getCells,
|
||||
type ModalMode as HookModalMode,
|
||||
type PlanEntryBody,
|
||||
type PlanEntryPatchBody,
|
||||
type PlanOverrideBody,
|
||||
type PlanOverridePatchBody,
|
||||
} from "../hooks/usePlanWork";
|
||||
import type { PlanCellModalMode } from "../components/PlanCellModal";
|
||||
import PlanGrid from "../components/PlanGrid";
|
||||
@@ -182,7 +186,13 @@ export default function PlanWork() {
|
||||
if (bulkForm.user_ids.length === 0) return;
|
||||
setBulkSubmitting(true);
|
||||
try {
|
||||
const data: any = await bulkCreate.mutateAsync({
|
||||
// Counts can arrive either at the envelope root or nested under .data.
|
||||
type BulkSummary = {
|
||||
created_days?: number;
|
||||
skipped_days?: number;
|
||||
users?: number;
|
||||
};
|
||||
const data = (await bulkCreate.mutateAsync({
|
||||
user_ids: bulkForm.user_ids.map(Number),
|
||||
date_from: bulkForm.date_from,
|
||||
date_to: bulkForm.is_range ? bulkForm.date_to : bulkForm.date_from,
|
||||
@@ -190,12 +200,12 @@ export default function PlanWork() {
|
||||
project_id: bulkForm.project_id ? Number(bulkForm.project_id) : null,
|
||||
category: bulkForm.category,
|
||||
note: bulkForm.note,
|
||||
});
|
||||
})) as BulkSummary & { data?: BulkSummary };
|
||||
// apiCall returns the full envelope { success, data, message };
|
||||
// the summary counts are under .data
|
||||
const summary = data?.data ?? data;
|
||||
const summary: BulkSummary = data?.data ?? data;
|
||||
const skipped =
|
||||
summary?.skipped_days > 0
|
||||
(summary?.skipped_days ?? 0) > 0
|
||||
? ` ${summary.skipped_days} dní přeskočeno (limit 3 na den).`
|
||||
: "";
|
||||
alert.success(
|
||||
@@ -392,7 +402,7 @@ export default function PlanWork() {
|
||||
// optimistic cache patch the hook already applied.
|
||||
|
||||
const saveEntry = useCallback(
|
||||
async (body: any) => {
|
||||
async (body: PlanEntryBody) => {
|
||||
try {
|
||||
await createEntry.mutateAsync(body);
|
||||
// Pulse the first day of the new entry — for multi-day entries
|
||||
@@ -409,7 +419,7 @@ export default function PlanWork() {
|
||||
);
|
||||
|
||||
const updateEntryFn = useCallback(
|
||||
async (id: number, body: any) => {
|
||||
async (id: number, body: PlanEntryPatchBody) => {
|
||||
// Find the user for this entry so we know which cell to pulse /
|
||||
// which cache to roll back. The hook's optimistic patch already
|
||||
// discovered this; we read it from the current grid.
|
||||
@@ -473,7 +483,7 @@ export default function PlanWork() {
|
||||
);
|
||||
|
||||
const saveOverride = useCallback(
|
||||
async (body: any) => {
|
||||
async (body: PlanOverrideBody) => {
|
||||
try {
|
||||
await createOverride.mutateAsync(body);
|
||||
firePulse(body.user_id, body.shift_date);
|
||||
@@ -488,7 +498,7 @@ export default function PlanWork() {
|
||||
);
|
||||
|
||||
const updateOverrideFn = useCallback(
|
||||
async (id: number, body: any) => {
|
||||
async (id: number, body: PlanOverridePatchBody) => {
|
||||
// Find the user/date for the pulse + rollback.
|
||||
let userId: number | null = null;
|
||||
let date: string | null = null;
|
||||
|
||||
@@ -362,8 +362,9 @@ export default function ReceivedInvoices({
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const blobTimeouts = blobTimeoutsRef.current;
|
||||
return () => {
|
||||
blobTimeoutsRef.current.forEach(clearTimeout);
|
||||
blobTimeouts.forEach(clearTimeout);
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -1149,11 +1150,9 @@ export default function ReceivedInvoices({
|
||||
? "Zavřít"
|
||||
: "Uložit"
|
||||
}
|
||||
cancelText={
|
||||
editInvoice && editInvoice._originalStatus === "paid"
|
||||
? "Zavřít"
|
||||
: "Zrušit"
|
||||
}
|
||||
// Read-only (paid) detail has only a close action — a single "Zavřít"
|
||||
// button, not a redundant cancel button beside it.
|
||||
hideCancel={editInvoice?._originalStatus === "paid"}
|
||||
loading={saving}
|
||||
>
|
||||
{editInvoice &&
|
||||
|
||||
@@ -715,7 +715,25 @@ export default function Settings() {
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
const si = systemInfo as Record<string, any>;
|
||||
type NasInfo = { configured?: boolean; path?: string | null };
|
||||
type SystemInfo = {
|
||||
app_version?: string;
|
||||
node_version?: string;
|
||||
platform?: string;
|
||||
uptime?: string;
|
||||
environment?: string;
|
||||
timezone?: string;
|
||||
memory?: {
|
||||
rss?: string;
|
||||
heap_used?: string;
|
||||
heap_total?: string;
|
||||
system_free?: string;
|
||||
system_total?: string;
|
||||
};
|
||||
database?: { status?: string; migrations_applied?: number | string };
|
||||
nas?: Record<string, NasInfo | undefined>;
|
||||
};
|
||||
const si = systemInfo as SystemInfo;
|
||||
const Row = ({
|
||||
label,
|
||||
children,
|
||||
@@ -800,7 +818,7 @@ export default function Settings() {
|
||||
["Faktury", si.nas?.invoices],
|
||||
["Objednávky", si.nas?.orders],
|
||||
["Nabídky", si.nas?.offers],
|
||||
] as [string, Record<string, any>][]
|
||||
] as [string, NasInfo | undefined][]
|
||||
).map(([label, info]) => (
|
||||
<Row key={label} label={label}>
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useRef, useId } from "react";
|
||||
import { useState, useEffect, useRef, useId, useCallback } from "react";
|
||||
import {
|
||||
useParams,
|
||||
useNavigate,
|
||||
@@ -174,7 +174,10 @@ export default function WarehouseIssueForm() {
|
||||
|
||||
const baseId = useId();
|
||||
const counterRef = useRef(0);
|
||||
const nextKey = () => `${baseId}-item-${counterRef.current++}`;
|
||||
const nextKey = useCallback(
|
||||
() => `${baseId}-item-${counterRef.current++}`,
|
||||
[baseId],
|
||||
);
|
||||
|
||||
// Pre-fill data from reservation ("Create výdej" button)
|
||||
const prefill = location.state as {
|
||||
@@ -262,7 +265,7 @@ export default function WarehouseIssueForm() {
|
||||
}
|
||||
formInitialized.current = true;
|
||||
}
|
||||
}, [isEdit, issue]);
|
||||
}, [isEdit, issue, nextKey]);
|
||||
|
||||
const saveMutation = useApiMutation<
|
||||
ReturnType<typeof buildPayload>,
|
||||
|
||||
@@ -126,7 +126,10 @@ export default function WarehouseReceiptForm() {
|
||||
|
||||
const baseId = useId();
|
||||
const counterRef = useRef(0);
|
||||
const nextKey = () => `${baseId}-item-${counterRef.current++}`;
|
||||
const nextKey = useCallback(
|
||||
() => `${baseId}-item-${counterRef.current++}`,
|
||||
[baseId],
|
||||
);
|
||||
|
||||
const [form, setForm] = useState<ReceiptForm>({
|
||||
supplier_id: null,
|
||||
@@ -198,7 +201,7 @@ export default function WarehouseReceiptForm() {
|
||||
}
|
||||
formInitialized.current = true;
|
||||
}
|
||||
}, [isEdit, receipt]);
|
||||
}, [isEdit, receipt, nextKey]);
|
||||
|
||||
const saveMutation = useApiMutation<
|
||||
ReturnType<typeof buildPayload>,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { theme } from "./theme";
|
||||
|
||||
/** Loose shape for poking into MUI styleOverrides objects in assertions. */
|
||||
type StyleObj = Record<string, unknown>;
|
||||
|
||||
/** Minimal palette shape used by the colorSchemes assertions below. */
|
||||
interface SchemesPalette {
|
||||
primary: { main: string };
|
||||
@@ -44,18 +47,20 @@ describe("MUI theme", () => {
|
||||
});
|
||||
|
||||
it("makes buttons pill-shaped and cards 16px by default", () => {
|
||||
const btn = theme.components?.MuiButton?.styleOverrides?.root as any;
|
||||
expect(btn?.borderRadius).toBe(999);
|
||||
const card = theme.components?.MuiCard?.styleOverrides?.root as any;
|
||||
expect(card?.borderRadius).toBe(16);
|
||||
const btn = theme.components?.MuiButton?.styleOverrides?.root as StyleObj;
|
||||
expect(btn.borderRadius).toBe(999);
|
||||
const card = theme.components?.MuiCard?.styleOverrides?.root as StyleObj;
|
||||
expect(card.borderRadius).toBe(16);
|
||||
});
|
||||
|
||||
it("adds 200-300ms interaction motion (press + focus ring)", () => {
|
||||
const btn = theme.components?.MuiButton?.styleOverrides?.root as any;
|
||||
expect(btn?.transition).toContain("transform");
|
||||
expect(btn?.["&:active"]?.transform).toBe("scale(0.97)");
|
||||
const btn = theme.components?.MuiButton?.styleOverrides?.root as StyleObj;
|
||||
expect(btn.transition).toContain("transform");
|
||||
const active = btn["&:active"] as StyleObj;
|
||||
expect(active.transform).toBe("scale(0.97)");
|
||||
const input = theme.components?.MuiOutlinedInput?.styleOverrides
|
||||
?.root as any;
|
||||
expect(input?.["&.Mui-focused"]?.boxShadow).toContain("rgba");
|
||||
?.root as StyleObj;
|
||||
const focused = input["&.Mui-focused"] as StyleObj;
|
||||
expect(focused.boxShadow).toContain("rgba");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user