Compare commits
10 Commits
c7f9d9aa36
...
v2.0.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ae69e09a3 | ||
|
|
df83eb2091 | ||
|
|
9c862034ca | ||
|
|
67d62a6df0 | ||
|
|
512f1fd92b | ||
|
|
941caf9d85 | ||
|
|
b00d18d0b3 | ||
|
|
decadd895e | ||
|
|
54f3c414f5 | ||
|
|
ca092c6166 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "app-ts",
|
"name": "app-ts",
|
||||||
"version": "2.0.0",
|
"version": "2.0.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "app-ts",
|
"name": "app-ts",
|
||||||
"version": "2.0.0",
|
"version": "2.0.2",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dnd-kit/core": "^6.3.1",
|
"@dnd-kit/core": "^6.3.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "app-ts",
|
"name": "app-ts",
|
||||||
"version": "2.0.0",
|
"version": "2.0.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/server.js",
|
"main": "dist/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
106
src/__tests__/nas-project-folder.test.ts
Normal file
106
src/__tests__/nas-project-folder.test.ts
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
||||||
|
import fs from "fs";
|
||||||
|
import os from "os";
|
||||||
|
import path from "path";
|
||||||
|
import { NasFileManager } from "../services/nas-file-manager";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Folder auto-creation primitive used by both the manual project-create path
|
||||||
|
* (projects.service createProject) and the order→project paths (orders.service
|
||||||
|
* createOrder / createOrderFromQuotation). Uses an isolated temp dir via the
|
||||||
|
* constructor seam so it is deterministic and passes even where the real NAS
|
||||||
|
* (Z:) is not mounted.
|
||||||
|
*/
|
||||||
|
describe("NasFileManager.createProjectFolder", () => {
|
||||||
|
let tmpBase: string;
|
||||||
|
let nas: NasFileManager;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
tmpBase = fs.mkdtempSync(path.join(os.tmpdir(), "nas-proj-"));
|
||||||
|
nas = new NasFileManager(tmpBase);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fs.rmSync(tmpBase, { recursive: true, force: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("creates a <number>_<name> folder for a new project", () => {
|
||||||
|
const ok = nas.createProjectFolder("26710001", "Rekonstrukce haly");
|
||||||
|
expect(ok).toBe(true);
|
||||||
|
expect(
|
||||||
|
fs.existsSync(path.join(tmpBase, "26710001_Rekonstrukce_haly")),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is idempotent — a second call does not create a duplicate", () => {
|
||||||
|
expect(nas.createProjectFolder("26710002", "Hala")).toBe(true);
|
||||||
|
expect(nas.createProjectFolder("26710002", "Hala")).toBe(true);
|
||||||
|
const matches = fs
|
||||||
|
.readdirSync(tmpBase)
|
||||||
|
.filter((e) => e.startsWith("26710002_"));
|
||||||
|
expect(matches).toEqual(["26710002_Hala"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves Czech diacritics (no transliteration)", () => {
|
||||||
|
expect(nas.createProjectFolder("26710003", "Měření haly")).toBe(true);
|
||||||
|
expect(fs.existsSync(path.join(tmpBase, "26710003_Měření_haly"))).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("strips illegal characters and collapses spaces", () => {
|
||||||
|
expect(nas.createProjectFolder("26710004", "A / B: C")).toBe(true);
|
||||||
|
expect(fs.existsSync(path.join(tmpBase, "26710004_A_B_C"))).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles an empty name without crashing (trailing underscore)", () => {
|
||||||
|
expect(nas.createProjectFolder("26710005", "")).toBe(true);
|
||||||
|
expect(fs.existsSync(path.join(tmpBase, "26710005_"))).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns false and creates nothing when the NAS base is not mounted", () => {
|
||||||
|
const missing = new NasFileManager(
|
||||||
|
path.join(tmpBase, "does-not-exist-subdir"),
|
||||||
|
);
|
||||||
|
expect(missing.createProjectFolder("26710006", "X")).toBe(false);
|
||||||
|
expect(fs.existsSync(path.join(tmpBase, "does-not-exist-subdir"))).toBe(
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Folder deletion primitive used by the "delete folder" checkbox on both the
|
||||||
|
* order delete (orders.service deleteOrder) and project delete (projects.service
|
||||||
|
* deleteProject) paths. Matches the project by number prefix.
|
||||||
|
*/
|
||||||
|
describe("NasFileManager.deleteProjectFolder", () => {
|
||||||
|
let tmpBase: string;
|
||||||
|
let nas: NasFileManager;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
tmpBase = fs.mkdtempSync(path.join(os.tmpdir(), "nas-del-"));
|
||||||
|
nas = new NasFileManager(tmpBase);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fs.rmSync(tmpBase, { recursive: true, force: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes an existing project folder (matched by number prefix)", async () => {
|
||||||
|
nas.createProjectFolder("26710010", "Hala");
|
||||||
|
expect(fs.existsSync(path.join(tmpBase, "26710010_Hala"))).toBe(true);
|
||||||
|
const ok = await nas.deleteProjectFolder("26710010");
|
||||||
|
expect(ok).toBe(true);
|
||||||
|
expect(fs.existsSync(path.join(tmpBase, "26710010_Hala"))).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is a no-op (returns true) when no folder exists for the number", async () => {
|
||||||
|
expect(await nas.deleteProjectFolder("26710011")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns false when the NAS base is not mounted", async () => {
|
||||||
|
const missing = new NasFileManager(path.join(tmpBase, "nope"));
|
||||||
|
expect(await missing.deleteProjectFolder("26710012")).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -479,6 +479,7 @@ function ViewModal(props: Props) {
|
|||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
onSubmit={onClose}
|
onSubmit={onClose}
|
||||||
submitText="Zavřít"
|
submitText="Zavřít"
|
||||||
|
hideCancel
|
||||||
>
|
>
|
||||||
<Typography sx={{ mb: 1 }}>
|
<Typography sx={{ mb: 1 }}>
|
||||||
<strong>Datum:</strong> {formatDate(c.shift_date)}
|
<strong>Datum:</strong> {formatDate(c.shift_date)}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Link as RouterLink } from "react-router-dom";
|
|||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import { Card, Button, EmptyState } from "../../ui";
|
import { Card, Button, EmptyState } from "../../ui";
|
||||||
|
import { iconBadgeSx, type IconBadgeColor } from "../../theme";
|
||||||
import {
|
import {
|
||||||
ENTITY_TYPE_LABELS,
|
ENTITY_TYPE_LABELS,
|
||||||
getActivityIconClass,
|
getActivityIconClass,
|
||||||
@@ -159,17 +160,20 @@ export default function DashActivityFeed({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={[
|
||||||
display: "flex",
|
{
|
||||||
alignItems: "center",
|
display: "flex",
|
||||||
justifyContent: "center",
|
alignItems: "center",
|
||||||
width: 32,
|
justifyContent: "center",
|
||||||
height: 32,
|
width: 32,
|
||||||
borderRadius: "50%",
|
height: 32,
|
||||||
flexShrink: 0,
|
borderRadius: "50%",
|
||||||
bgcolor: isDefault ? "grey.600" : `${badgeColor}.main`,
|
flexShrink: 0,
|
||||||
color: "common.white",
|
},
|
||||||
}}
|
iconBadgeSx(
|
||||||
|
isDefault ? "default" : (badgeColor as IconBadgeColor),
|
||||||
|
),
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
{getActivityIcon(act.action)}
|
{getActivityIcon(act.action)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import DialogActions from "@mui/material/DialogActions";
|
|||||||
import { useAuth } from "../../context/AuthContext";
|
import { useAuth } from "../../context/AuthContext";
|
||||||
import { useAlert } from "../../context/AlertContext";
|
import { useAlert } from "../../context/AlertContext";
|
||||||
import apiFetch from "../../utils/api";
|
import apiFetch from "../../utils/api";
|
||||||
|
import { iconBadgeSx } from "../../theme";
|
||||||
import { Card, Button, Modal, Field, TextField } from "../../ui";
|
import { Card, Button, Modal, Field, TextField } from "../../ui";
|
||||||
import useDialogScrollLock from "../../ui/useDialogScrollLock";
|
import useDialogScrollLock from "../../ui/useDialogScrollLock";
|
||||||
|
|
||||||
@@ -251,17 +252,18 @@ export default function DashProfile({
|
|||||||
>
|
>
|
||||||
<Box sx={{ display: "flex", alignItems: "center", gap: 1.5 }}>
|
<Box sx={{ display: "flex", alignItems: "center", gap: 1.5 }}>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={[
|
||||||
width: 36,
|
{
|
||||||
height: 36,
|
width: 36,
|
||||||
borderRadius: "50%",
|
height: 36,
|
||||||
display: "flex",
|
borderRadius: "50%",
|
||||||
alignItems: "center",
|
display: "flex",
|
||||||
justifyContent: "center",
|
alignItems: "center",
|
||||||
flexShrink: 0,
|
justifyContent: "center",
|
||||||
bgcolor: totpEnabled ? "success.main" : "grey.600",
|
flexShrink: 0,
|
||||||
color: "common.white",
|
},
|
||||||
}}
|
iconBadgeSx(totpEnabled ? "success" : "default"),
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
width="18"
|
width="18"
|
||||||
@@ -425,7 +427,8 @@ export default function DashProfile({
|
|||||||
p: 1.5,
|
p: 1.5,
|
||||||
mb: 2,
|
mb: 2,
|
||||||
borderRadius: 2,
|
borderRadius: 2,
|
||||||
bgcolor: "warning.light",
|
bgcolor:
|
||||||
|
"rgba(var(--mui-palette-warning-mainChannel) / 0.12)",
|
||||||
color: "warning.main",
|
color: "warning.main",
|
||||||
fontSize: "0.875rem",
|
fontSize: "0.875rem",
|
||||||
}}
|
}}
|
||||||
|
|||||||
110
src/admin/components/dashboard/DashTodayPlan.tsx
Normal file
110
src/admin/components/dashboard/DashTodayPlan.tsx
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import { Card } from "../../ui";
|
||||||
|
import { formatDate } from "../../utils/formatters";
|
||||||
|
|
||||||
|
/** The logged-in user's resolved work plan for today (see GET /api/admin/dashboard). */
|
||||||
|
export interface TodayPlan {
|
||||||
|
shift_date: string;
|
||||||
|
category: string;
|
||||||
|
category_label: string;
|
||||||
|
category_color: string | null;
|
||||||
|
project_id: number | null;
|
||||||
|
project_number: string | null;
|
||||||
|
project_name: string | null;
|
||||||
|
note: string;
|
||||||
|
source: "entry" | "override";
|
||||||
|
rangeFrom: string | null;
|
||||||
|
rangeTo: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function projectLabel(p: TodayPlan): string {
|
||||||
|
const parts = [p.project_number, p.project_name].filter(Boolean);
|
||||||
|
return parts.length > 0 ? parts.join(" — ") : "Bez projektu";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Vaše dnešní zařazení" — shows the logged-in user's work-plan entry for today
|
||||||
|
* (category + project/site + note, with a range badge when the day is part of a
|
||||||
|
* multi-day range). `plan === null` = the user has plan access but nothing is
|
||||||
|
* scheduled today (muted empty state). Rendered near the clock-in on the
|
||||||
|
* dashboard; the caller gates it on the plan permission.
|
||||||
|
*/
|
||||||
|
export default function DashTodayPlan({ plan }: { plan: TodayPlan | null }) {
|
||||||
|
const color = plan?.category_color || "var(--mui-palette-primary-main)";
|
||||||
|
return (
|
||||||
|
<Card sx={{ mb: 3 }}>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle2"
|
||||||
|
sx={{ mb: 1.5, fontWeight: 600, color: "text.secondary" }}
|
||||||
|
>
|
||||||
|
Vaše dnešní zařazení
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
{plan ? (
|
||||||
|
<Box sx={{ display: "flex", flexDirection: "column", gap: 1 }}>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 1,
|
||||||
|
flexWrap: "wrap",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "inline-flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 0.75,
|
||||||
|
px: 1.25,
|
||||||
|
py: 0.5,
|
||||||
|
borderRadius: 999,
|
||||||
|
border: 1,
|
||||||
|
borderColor: "divider",
|
||||||
|
bgcolor: `color-mix(in srgb, ${color} 12%, transparent)`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: 10,
|
||||||
|
height: 10,
|
||||||
|
borderRadius: "50%",
|
||||||
|
bgcolor: color,
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
sx={{ fontWeight: 700, fontSize: "0.8rem" }}
|
||||||
|
>
|
||||||
|
{plan.category_label}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
{plan.rangeFrom &&
|
||||||
|
plan.rangeTo &&
|
||||||
|
plan.rangeFrom !== plan.rangeTo && (
|
||||||
|
<Typography variant="caption" color="text.secondary">
|
||||||
|
součást rozsahu {formatDate(plan.rangeFrom)} –{" "}
|
||||||
|
{formatDate(plan.rangeTo)}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Typography variant="h6" sx={{ lineHeight: 1.25 }}>
|
||||||
|
{projectLabel(plan)}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
{plan.note && (
|
||||||
|
<Typography variant="body2" color="text.secondary">
|
||||||
|
{plan.note}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
<Typography variant="body2" color="text.secondary">
|
||||||
|
Pro dnešek nemáte naplánováno.
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import Typography from "@mui/material/Typography";
|
|||||||
import { useAuth } from "../context/AuthContext";
|
import { useAuth } from "../context/AuthContext";
|
||||||
import Forbidden from "../components/Forbidden";
|
import Forbidden from "../components/Forbidden";
|
||||||
import { companySettingsOptions } from "../lib/queries/settings";
|
import { companySettingsOptions } from "../lib/queries/settings";
|
||||||
|
import { iconBadgeSx } from "../theme";
|
||||||
import {
|
import {
|
||||||
attendanceHistoryOptions,
|
attendanceHistoryOptions,
|
||||||
type AttendanceRecord,
|
type AttendanceRecord,
|
||||||
@@ -533,17 +534,18 @@ export default function AttendanceHistory() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={[
|
||||||
display: "flex",
|
{
|
||||||
alignItems: "center",
|
display: "flex",
|
||||||
justifyContent: "center",
|
alignItems: "center",
|
||||||
width: 44,
|
justifyContent: "center",
|
||||||
height: 44,
|
width: 44,
|
||||||
borderRadius: 2,
|
height: 44,
|
||||||
bgcolor: "info.main",
|
borderRadius: 2,
|
||||||
color: "#fff",
|
flexShrink: 0,
|
||||||
flexShrink: 0,
|
},
|
||||||
}}
|
iconBadgeSx("info"),
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
width="24"
|
width="24"
|
||||||
|
|||||||
@@ -12,12 +12,16 @@ import { require2FAOptions } from "../lib/queries/settings";
|
|||||||
import { getCzechDate } from "../utils/dashboardHelpers";
|
import { getCzechDate } from "../utils/dashboardHelpers";
|
||||||
import { useApiMutation } from "../lib/queries/mutations";
|
import { useApiMutation } from "../lib/queries/mutations";
|
||||||
import { Card, Button, StatusChip, PageEnter } from "../ui";
|
import { Card, Button, StatusChip, PageEnter } from "../ui";
|
||||||
|
import { iconBadgeSx } from "../theme";
|
||||||
import DashKpiCards from "../components/dashboard/DashKpiCards";
|
import DashKpiCards from "../components/dashboard/DashKpiCards";
|
||||||
import DashQuickActions from "../components/dashboard/DashQuickActions";
|
import DashQuickActions from "../components/dashboard/DashQuickActions";
|
||||||
import DashActivityFeed from "../components/dashboard/DashActivityFeed";
|
import DashActivityFeed from "../components/dashboard/DashActivityFeed";
|
||||||
import DashAttendanceToday from "../components/dashboard/DashAttendanceToday";
|
import DashAttendanceToday from "../components/dashboard/DashAttendanceToday";
|
||||||
import DashProfile from "../components/dashboard/DashProfile";
|
import DashProfile from "../components/dashboard/DashProfile";
|
||||||
import DashSessions from "../components/dashboard/DashSessions";
|
import DashSessions from "../components/dashboard/DashSessions";
|
||||||
|
import DashTodayPlan, {
|
||||||
|
type TodayPlan,
|
||||||
|
} from "../components/dashboard/DashTodayPlan";
|
||||||
|
|
||||||
const API_BASE = "/api/admin";
|
const API_BASE = "/api/admin";
|
||||||
|
|
||||||
@@ -68,6 +72,7 @@ interface DashData {
|
|||||||
pending_orders?: number;
|
pending_orders?: number;
|
||||||
unpaid_invoices?: number;
|
unpaid_invoices?: number;
|
||||||
pending_leave_requests?: number;
|
pending_leave_requests?: number;
|
||||||
|
today_plan?: TodayPlan | null;
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,17 +258,18 @@ export default function Dashboard() {
|
|||||||
>
|
>
|
||||||
<Box sx={{ display: "flex", alignItems: "center", gap: 1.5 }}>
|
<Box sx={{ display: "flex", alignItems: "center", gap: 1.5 }}>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={[
|
||||||
width: 40,
|
{
|
||||||
height: 40,
|
width: 40,
|
||||||
borderRadius: "50%",
|
height: 40,
|
||||||
display: "flex",
|
borderRadius: "50%",
|
||||||
alignItems: "center",
|
display: "flex",
|
||||||
justifyContent: "center",
|
alignItems: "center",
|
||||||
bgcolor: "error.main",
|
justifyContent: "center",
|
||||||
color: "#fff",
|
flexShrink: 0,
|
||||||
flexShrink: 0,
|
},
|
||||||
}}
|
iconBadgeSx("error"),
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
width="20"
|
width="20"
|
||||||
@@ -315,6 +321,13 @@ export default function Dashboard() {
|
|||||||
<DashKpiCards dashData={dashData ?? null} />
|
<DashKpiCards dashData={dashData ?? null} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* My work plan for today — paired with the clock-in below */}
|
||||||
|
{!dashLoading &&
|
||||||
|
(hasPermission("attendance.record") ||
|
||||||
|
hasPermission("attendance.manage")) && (
|
||||||
|
<DashTodayPlan plan={dashData?.today_plan ?? null} />
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Quick actions */}
|
{/* Quick actions */}
|
||||||
{!dashLoading && (
|
{!dashLoading && (
|
||||||
<DashQuickActions
|
<DashQuickActions
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ import {
|
|||||||
LoadingState,
|
LoadingState,
|
||||||
PageEnter,
|
PageEnter,
|
||||||
RichTextView,
|
RichTextView,
|
||||||
|
headerActionsSx,
|
||||||
} from "../ui";
|
} from "../ui";
|
||||||
|
|
||||||
const API_BASE = "/api/admin";
|
const API_BASE = "/api/admin";
|
||||||
@@ -1114,14 +1115,7 @@ export default function InvoiceDetail() {
|
|||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box sx={headerActionsSx}>
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 1,
|
|
||||||
flexWrap: "wrap",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{hasPermission("invoices.export") && (
|
{hasPermission("invoices.export") && (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleViewPdf(invoice.language || "cs")}
|
onClick={() => handleViewPdf(invoice.language || "cs")}
|
||||||
@@ -1140,7 +1134,11 @@ export default function InvoiceDetail() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{hasPermission("invoices.delete") && (
|
{hasPermission("invoices.delete") && (
|
||||||
<Button onClick={() => setDeleteConfirm(true)} color="error">
|
<Button
|
||||||
|
onClick={() => setDeleteConfirm(true)}
|
||||||
|
variant="outlined"
|
||||||
|
color="error"
|
||||||
|
>
|
||||||
Smazat
|
Smazat
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
@@ -1656,14 +1654,7 @@ export default function InvoiceDetail() {
|
|||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box sx={headerActionsSx}>
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 1,
|
|
||||||
flexWrap: "wrap",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{isEdit && invoice && hasPermission("invoices.export") && (
|
{isEdit && invoice && hasPermission("invoices.export") && (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleViewPdf(invoice.language || "cs")}
|
onClick={() => handleViewPdf(invoice.language || "cs")}
|
||||||
@@ -1710,7 +1701,11 @@ export default function InvoiceDetail() {
|
|||||||
</Button>
|
</Button>
|
||||||
))}
|
))}
|
||||||
{hasPermission("invoices.delete") && (
|
{hasPermission("invoices.delete") && (
|
||||||
<Button onClick={() => setDeleteConfirm(true)} color="error">
|
<Button
|
||||||
|
onClick={() => setDeleteConfirm(true)}
|
||||||
|
variant="outlined"
|
||||||
|
color="error"
|
||||||
|
>
|
||||||
Smazat
|
Smazat
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ import {
|
|||||||
EmptyState,
|
EmptyState,
|
||||||
LoadingState,
|
LoadingState,
|
||||||
PageEnter,
|
PageEnter,
|
||||||
|
headerActionsSx,
|
||||||
} from "../ui";
|
} from "../ui";
|
||||||
|
|
||||||
const API_BASE = "/api/admin";
|
const API_BASE = "/api/admin";
|
||||||
@@ -1118,14 +1119,7 @@ export default function OfferDetail() {
|
|||||||
{isCompleted && <StatusChip label="Dokončeno" color="success" />}
|
{isCompleted && <StatusChip label="Dokončeno" color="success" />}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box sx={headerActionsSx}>
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 1,
|
|
||||||
flexWrap: "wrap",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{isEdit && hasPermission("offers.export") && (
|
{isEdit && hasPermission("offers.export") && (
|
||||||
<Button
|
<Button
|
||||||
onClick={handlePdf}
|
onClick={handlePdf}
|
||||||
@@ -1184,7 +1178,11 @@ export default function OfferDetail() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{isEdit && hasPermission("offers.delete") && (
|
{isEdit && hasPermission("offers.delete") && (
|
||||||
<Button onClick={() => setDeleteConfirm(true)} color="error">
|
<Button
|
||||||
|
onClick={() => setDeleteConfirm(true)}
|
||||||
|
variant="outlined"
|
||||||
|
color="error"
|
||||||
|
>
|
||||||
Smazat
|
Smazat
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import {
|
|||||||
LoadingState,
|
LoadingState,
|
||||||
PageEnter,
|
PageEnter,
|
||||||
RichTextView,
|
RichTextView,
|
||||||
|
headerActionsSx,
|
||||||
type DataColumn,
|
type DataColumn,
|
||||||
} from "../ui";
|
} from "../ui";
|
||||||
|
|
||||||
@@ -424,14 +425,7 @@ export default function OrderDetail() {
|
|||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box sx={headerActionsSx}>
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 1,
|
|
||||||
flexWrap: "wrap",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{order.invoice ? (
|
{order.invoice ? (
|
||||||
<Button
|
<Button
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
ConfirmDialog,
|
ConfirmDialog,
|
||||||
LoadingState,
|
LoadingState,
|
||||||
PageEnter,
|
PageEnter,
|
||||||
|
headerActionsSx,
|
||||||
} from "../ui";
|
} from "../ui";
|
||||||
|
|
||||||
const API_BASE = "/api/admin";
|
const API_BASE = "/api/admin";
|
||||||
@@ -320,14 +321,7 @@ export default function ProjectDetail() {
|
|||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
{canEdit && (
|
{canEdit && (
|
||||||
<Box
|
<Box sx={headerActionsSx}>
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 1,
|
|
||||||
flexWrap: "wrap",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button onClick={handleSave} disabled={saving}>
|
<Button onClick={handleSave} disabled={saving}>
|
||||||
{saving ? "Ukládání..." : "Uložit"}
|
{saving ? "Ukládání..." : "Uložit"}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import {
|
|||||||
|
|
||||||
import { useApiMutation } from "../lib/queries/mutations";
|
import { useApiMutation } from "../lib/queries/mutations";
|
||||||
import apiFetch from "../utils/api";
|
import apiFetch from "../utils/api";
|
||||||
|
import { iconBadgeSx } from "../theme";
|
||||||
const API_BASE = "/api/admin";
|
const API_BASE = "/api/admin";
|
||||||
|
|
||||||
const PlusIcon = (
|
const PlusIcon = (
|
||||||
@@ -842,17 +843,18 @@ export default function Settings() {
|
|||||||
>
|
>
|
||||||
<Box sx={{ display: "flex", alignItems: "center", gap: 1.5 }}>
|
<Box sx={{ display: "flex", alignItems: "center", gap: 1.5 }}>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={[
|
||||||
width: 36,
|
{
|
||||||
height: 36,
|
width: 36,
|
||||||
borderRadius: "50%",
|
height: 36,
|
||||||
display: "flex",
|
borderRadius: "50%",
|
||||||
alignItems: "center",
|
display: "flex",
|
||||||
justifyContent: "center",
|
alignItems: "center",
|
||||||
bgcolor: require2FA ? "success.light" : "action.hover",
|
justifyContent: "center",
|
||||||
color: require2FA ? "success.main" : "text.secondary",
|
flexShrink: 0,
|
||||||
flexShrink: 0,
|
},
|
||||||
}}
|
iconBadgeSx(require2FA ? "success" : "default"),
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
width="18"
|
width="18"
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ export default function WarehouseInventory() {
|
|||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
{statusFilter && (
|
{statusFilter && (
|
||||||
<Button variant="outlined" onClick={resetFilters}>
|
<Button variant="outlined" color="inherit" onClick={resetFilters}>
|
||||||
Zrušit filtry
|
Zrušit filtry
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
PageHeader,
|
PageHeader,
|
||||||
PageEnter,
|
PageEnter,
|
||||||
ConfirmDialog,
|
ConfirmDialog,
|
||||||
|
headerActionsSx,
|
||||||
type DataColumn,
|
type DataColumn,
|
||||||
} from "../ui";
|
} from "../ui";
|
||||||
|
|
||||||
@@ -192,7 +193,7 @@ export default function WarehouseInventoryDetail() {
|
|||||||
<PageHeader
|
<PageHeader
|
||||||
title={s.session_number || "Inventura"}
|
title={s.session_number || "Inventura"}
|
||||||
actions={
|
actions={
|
||||||
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
|
<Box sx={headerActionsSx}>
|
||||||
<Button
|
<Button
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
to="/warehouse/inventory"
|
to="/warehouse/inventory"
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
PageHeader,
|
PageHeader,
|
||||||
ConfirmDialog,
|
ConfirmDialog,
|
||||||
PageEnter,
|
PageEnter,
|
||||||
|
headerActionsSx,
|
||||||
type DataColumn,
|
type DataColumn,
|
||||||
} from "../ui";
|
} from "../ui";
|
||||||
|
|
||||||
@@ -233,7 +234,7 @@ export default function WarehouseIssueDetail() {
|
|||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
actions={
|
actions={
|
||||||
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
|
<Box sx={headerActionsSx}>
|
||||||
<Button
|
<Button
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
to="/warehouse/issues"
|
to="/warehouse/issues"
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ export default function WarehouseIssues() {
|
|||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
{hasActiveFilters && (
|
{hasActiveFilters && (
|
||||||
<Button variant="outlined" onClick={resetFilters}>
|
<Button variant="outlined" color="inherit" onClick={resetFilters}>
|
||||||
Zrušit filtry
|
Zrušit filtry
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
PageHeader,
|
PageHeader,
|
||||||
ConfirmDialog,
|
ConfirmDialog,
|
||||||
PageEnter,
|
PageEnter,
|
||||||
|
headerActionsSx,
|
||||||
type DataColumn,
|
type DataColumn,
|
||||||
} from "../ui";
|
} from "../ui";
|
||||||
|
|
||||||
@@ -233,7 +234,7 @@ export default function WarehouseItemDetail() {
|
|||||||
|
|
||||||
// Edit / view mode action buttons
|
// Edit / view mode action buttons
|
||||||
const headerActions = canManage ? (
|
const headerActions = canManage ? (
|
||||||
<Box sx={{ display: "flex", gap: 1 }}>
|
<Box sx={headerActionsSx}>
|
||||||
{editing || isNew ? (
|
{editing || isNew ? (
|
||||||
<>
|
<>
|
||||||
{!isNew && (
|
{!isNew && (
|
||||||
@@ -362,7 +363,7 @@ export default function WarehouseItemDetail() {
|
|||||||
title={title}
|
title={title}
|
||||||
subtitle={subtitle}
|
subtitle={subtitle}
|
||||||
actions={
|
actions={
|
||||||
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
|
<Box sx={headerActionsSx}>
|
||||||
<Button
|
<Button
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
to="/warehouse/items"
|
to="/warehouse/items"
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
PageHeader,
|
PageHeader,
|
||||||
ConfirmDialog,
|
ConfirmDialog,
|
||||||
PageEnter,
|
PageEnter,
|
||||||
|
headerActionsSx,
|
||||||
type DataColumn,
|
type DataColumn,
|
||||||
} from "../ui";
|
} from "../ui";
|
||||||
|
|
||||||
@@ -301,7 +302,7 @@ export default function WarehouseReceiptDetail() {
|
|||||||
title={r.receipt_number || "Nový doklad"}
|
title={r.receipt_number || "Nový doklad"}
|
||||||
subtitle={r.supplier?.name}
|
subtitle={r.supplier?.name}
|
||||||
actions={
|
actions={
|
||||||
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
|
<Box sx={headerActionsSx}>
|
||||||
<Button
|
<Button
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
to="/warehouse/receipts"
|
to="/warehouse/receipts"
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ export default function WarehouseReceipts() {
|
|||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
{hasActiveFilters && (
|
{hasActiveFilters && (
|
||||||
<Button variant="outlined" onClick={resetFilters}>
|
<Button variant="outlined" color="inherit" onClick={resetFilters}>
|
||||||
Zrušit filtry
|
Zrušit filtry
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ export default function WarehouseReservations() {
|
|||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
{hasActiveFilters && (
|
{hasActiveFilters && (
|
||||||
<Button variant="outlined" onClick={resetFilters}>
|
<Button variant="outlined" color="inherit" onClick={resetFilters}>
|
||||||
Zrušit filtry
|
Zrušit filtry
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createTheme } from "@mui/material/styles";
|
import { createTheme, type Theme } from "@mui/material/styles";
|
||||||
|
|
||||||
const FONT_BODY = "'Plus Jakarta Sans', system-ui, sans-serif";
|
const FONT_BODY = "'Plus Jakarta Sans', system-ui, sans-serif";
|
||||||
const FONT_HEADING = "'Urbanist', sans-serif";
|
const FONT_HEADING = "'Urbanist', sans-serif";
|
||||||
@@ -7,6 +7,19 @@ const FONT_MONO = "'DM Mono', Menlo, monospace";
|
|||||||
// Standard Material easing (matches the legacy --transition cubic-bezier).
|
// Standard Material easing (matches the legacy --transition cubic-bezier).
|
||||||
const EASE = "cubic-bezier(0.4, 0, 0.2, 1)";
|
const EASE = "cubic-bezier(0.4, 0, 0.2, 1)";
|
||||||
|
|
||||||
|
// Dark-mode fills for FILLED colored surfaces (contained buttons, filled chips,
|
||||||
|
// StatCard badges). The palette .main stays BRIGHT in dark mode (it drives text,
|
||||||
|
// outlined buttons and row tints), but a bright fill makes WHITE text/glyphs
|
||||||
|
// illegible — so filled surfaces drop to these darker shades (≈ the light-scheme
|
||||||
|
// values) in dark mode. One rule everywhere: filled colored = white text,
|
||||||
|
// readable in both themes. Light mode needs no override (its .main is dark).
|
||||||
|
export const FILLED_DARK_BG = {
|
||||||
|
error: { bg: "#dc2626", hover: "#b91c1c" },
|
||||||
|
success: { bg: "#15803d", hover: "#166534" },
|
||||||
|
warning: { bg: "#b45309", hover: "#92400e" },
|
||||||
|
info: { bg: "#1d4ed8", hover: "#1e40af" },
|
||||||
|
} as const;
|
||||||
|
|
||||||
export const theme = createTheme({
|
export const theme = createTheme({
|
||||||
cssVariables: {
|
cssVariables: {
|
||||||
colorSchemeSelector: "[data-theme='%s']",
|
colorSchemeSelector: "[data-theme='%s']",
|
||||||
@@ -80,6 +93,47 @@ export const theme = createTheme({
|
|||||||
},
|
},
|
||||||
"&:active": { transform: "translateY(0) scale(0.97)" },
|
"&:active": { transform: "translateY(0) scale(0.97)" },
|
||||||
},
|
},
|
||||||
|
// Filled colored buttons: WHITE text in BOTH themes (was per-scheme
|
||||||
|
// contrastText → near-black text on colored fills in dark mode, which
|
||||||
|
// also clashed with the always-white primary — "black text on one red
|
||||||
|
// button, white on another"). In dark mode the fill drops to a darker
|
||||||
|
// shade so white stays legible.
|
||||||
|
containedError: ({ theme }) => ({
|
||||||
|
color: "#fff",
|
||||||
|
...theme.applyStyles("dark", {
|
||||||
|
"&:not(.Mui-disabled)": {
|
||||||
|
backgroundColor: FILLED_DARK_BG.error.bg,
|
||||||
|
"&:hover": { backgroundColor: FILLED_DARK_BG.error.hover },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
containedSuccess: ({ theme }) => ({
|
||||||
|
color: "#fff",
|
||||||
|
...theme.applyStyles("dark", {
|
||||||
|
"&:not(.Mui-disabled)": {
|
||||||
|
backgroundColor: FILLED_DARK_BG.success.bg,
|
||||||
|
"&:hover": { backgroundColor: FILLED_DARK_BG.success.hover },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
containedWarning: ({ theme }) => ({
|
||||||
|
color: "#fff",
|
||||||
|
...theme.applyStyles("dark", {
|
||||||
|
"&:not(.Mui-disabled)": {
|
||||||
|
backgroundColor: FILLED_DARK_BG.warning.bg,
|
||||||
|
"&:hover": { backgroundColor: FILLED_DARK_BG.warning.hover },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
containedInfo: ({ theme }) => ({
|
||||||
|
color: "#fff",
|
||||||
|
...theme.applyStyles("dark", {
|
||||||
|
"&:not(.Mui-disabled)": {
|
||||||
|
backgroundColor: FILLED_DARK_BG.info.bg,
|
||||||
|
"&:hover": { backgroundColor: FILLED_DARK_BG.info.hover },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
MuiCard: {
|
MuiCard: {
|
||||||
@@ -99,6 +153,54 @@ export const theme = createTheme({
|
|||||||
fontWeight: 700,
|
fontWeight: 700,
|
||||||
transition: `background-color 200ms ${EASE}, box-shadow 200ms ${EASE}`,
|
transition: `background-color 200ms ${EASE}, box-shadow 200ms ${EASE}`,
|
||||||
},
|
},
|
||||||
|
// Filled colored chips follow the same rule as filled buttons: white
|
||||||
|
// label in both themes, darker fill in dark mode so white stays legible.
|
||||||
|
// (Chip has no per-color `filledX` key, so target the color class and
|
||||||
|
// scope to the filled variant.)
|
||||||
|
colorError: ({ theme }) => ({
|
||||||
|
"&.MuiChip-filled": {
|
||||||
|
color: "#fff",
|
||||||
|
...theme.applyStyles("dark", {
|
||||||
|
backgroundColor: FILLED_DARK_BG.error.bg,
|
||||||
|
"&.MuiChip-clickable:hover": {
|
||||||
|
backgroundColor: FILLED_DARK_BG.error.hover,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
colorSuccess: ({ theme }) => ({
|
||||||
|
"&.MuiChip-filled": {
|
||||||
|
color: "#fff",
|
||||||
|
...theme.applyStyles("dark", {
|
||||||
|
backgroundColor: FILLED_DARK_BG.success.bg,
|
||||||
|
"&.MuiChip-clickable:hover": {
|
||||||
|
backgroundColor: FILLED_DARK_BG.success.hover,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
colorWarning: ({ theme }) => ({
|
||||||
|
"&.MuiChip-filled": {
|
||||||
|
color: "#fff",
|
||||||
|
...theme.applyStyles("dark", {
|
||||||
|
backgroundColor: FILLED_DARK_BG.warning.bg,
|
||||||
|
"&.MuiChip-clickable:hover": {
|
||||||
|
backgroundColor: FILLED_DARK_BG.warning.hover,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
colorInfo: ({ theme }) => ({
|
||||||
|
"&.MuiChip-filled": {
|
||||||
|
color: "#fff",
|
||||||
|
...theme.applyStyles("dark", {
|
||||||
|
backgroundColor: FILLED_DARK_BG.info.bg,
|
||||||
|
"&.MuiChip-clickable:hover": {
|
||||||
|
backgroundColor: FILLED_DARK_BG.info.hover,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
MuiOutlinedInput: {
|
MuiOutlinedInput: {
|
||||||
@@ -124,3 +226,29 @@ export const fonts = {
|
|||||||
heading: FONT_HEADING,
|
heading: FONT_HEADING,
|
||||||
mono: FONT_MONO,
|
mono: FONT_MONO,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type IconBadgeColor =
|
||||||
|
| "default"
|
||||||
|
| "primary"
|
||||||
|
| "success"
|
||||||
|
| "warning"
|
||||||
|
| "error"
|
||||||
|
| "info";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sx fragment for a solid icon-badge tile: a `<color>.main` fill with a WHITE
|
||||||
|
* glyph, darkened in dark mode (FILLED_DARK_BG) so white stays legible on the
|
||||||
|
* otherwise-bright success/warning/info/error fills. `default` = neutral grey.
|
||||||
|
* Single source of truth for every labelled icon badge — use in an sx array
|
||||||
|
* next to the tile's size/shape so they can never drift apart:
|
||||||
|
* sx={[{ width: 40, height: 40, borderRadius: 2, display: "flex", … }, iconBadgeSx(color)]}
|
||||||
|
*/
|
||||||
|
export function iconBadgeSx(color: IconBadgeColor) {
|
||||||
|
const bg = color === "default" ? "grey.600" : `${color}.main`;
|
||||||
|
const darkBg = (FILLED_DARK_BG as Record<string, { bg: string }>)[color]?.bg;
|
||||||
|
return (theme: Theme) => ({
|
||||||
|
bgcolor: bg,
|
||||||
|
color: "common.white",
|
||||||
|
...(darkBg ? theme.applyStyles("dark", { backgroundColor: darkBg }) : {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
|
import type { SxProps, Theme } from "@mui/material/styles";
|
||||||
|
|
||||||
export interface PageHeaderProps {
|
export interface PageHeaderProps {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -8,6 +9,26 @@ export interface PageHeaderProps {
|
|||||||
actions?: ReactNode;
|
actions?: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared sx for a header action-button group. On mobile each button gets its
|
||||||
|
* own full-width row (column + stretch); from `sm` up it's the usual right-
|
||||||
|
* aligned wrapping row. Use on the Box that wraps the header's action Buttons
|
||||||
|
* (page headers + detail-page headers) so the mobile layout is identical
|
||||||
|
* everywhere — no more buttons wrapping into a ragged grid on phones.
|
||||||
|
*/
|
||||||
|
export const headerActionsSx: SxProps<Theme> = {
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: { xs: "column", sm: "row" },
|
||||||
|
alignItems: { xs: "stretch", sm: "center" },
|
||||||
|
justifyContent: { sm: "flex-end" },
|
||||||
|
flexWrap: { sm: "wrap" },
|
||||||
|
gap: 1,
|
||||||
|
width: { xs: "100%", sm: "auto" },
|
||||||
|
// Some detail-page headers keep a StatusChip in this same group — keep it at
|
||||||
|
// its natural size on mobile instead of stretching it into a full-width bar.
|
||||||
|
"& > .MuiChip-root": { alignSelf: { xs: "flex-start", sm: "auto" } },
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard page header: title (+ optional subtitle) on the left,
|
* Standard page header: title (+ optional subtitle) on the left,
|
||||||
* action controls on the right. No framer-motion — pages add their own entrance.
|
* action controls on the right. No framer-motion — pages add their own entrance.
|
||||||
@@ -36,19 +57,7 @@ export default function PageHeader({
|
|||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
{actions && (
|
{actions && <Box sx={headerActionsSx}>{actions}</Box>}
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "flex-end",
|
|
||||||
gap: 1,
|
|
||||||
flexWrap: "wrap",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{actions}
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { ReactNode } from "react";
|
|||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import Card from "./Card";
|
import Card from "./Card";
|
||||||
|
import { iconBadgeSx } from "../theme";
|
||||||
|
|
||||||
export type StatCardColor =
|
export type StatCardColor =
|
||||||
| "default"
|
| "default"
|
||||||
@@ -30,27 +31,23 @@ export default function StatCard({
|
|||||||
color = "default",
|
color = "default",
|
||||||
footer,
|
footer,
|
||||||
}: StatCardProps) {
|
}: StatCardProps) {
|
||||||
// Solid tile + white glyph: high-contrast in both themes (the old light tint
|
|
||||||
// left the icon dark/low-visibility, esp. for the default variant).
|
|
||||||
const iconBg = color === "default" ? "grey.600" : `${color}.main`;
|
|
||||||
const iconColor = "common.white";
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<Box sx={{ display: "flex", alignItems: "flex-start", gap: 1.5 }}>
|
<Box sx={{ display: "flex", alignItems: "flex-start", gap: 1.5 }}>
|
||||||
{icon && (
|
{icon && (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={[
|
||||||
display: "flex",
|
{
|
||||||
alignItems: "center",
|
display: "flex",
|
||||||
justifyContent: "center",
|
alignItems: "center",
|
||||||
width: 40,
|
justifyContent: "center",
|
||||||
height: 40,
|
width: 40,
|
||||||
borderRadius: 2,
|
height: 40,
|
||||||
bgcolor: iconBg,
|
borderRadius: 2,
|
||||||
color: iconColor,
|
flexShrink: 0,
|
||||||
flexShrink: 0,
|
},
|
||||||
}}
|
iconBadgeSx(color),
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
{icon}
|
{icon}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export { default as Pagination } from "./Pagination";
|
|||||||
export { default as DateField } from "./DateField";
|
export { default as DateField } from "./DateField";
|
||||||
export { default as MonthField } from "./MonthField";
|
export { default as MonthField } from "./MonthField";
|
||||||
export { default as TimeField } from "./TimeField";
|
export { default as TimeField } from "./TimeField";
|
||||||
export { default as PageHeader } from "./PageHeader";
|
export { default as PageHeader, headerActionsSx } from "./PageHeader";
|
||||||
export { default as EmptyState } from "./EmptyState";
|
export { default as EmptyState } from "./EmptyState";
|
||||||
export { default as LoadingState } from "./LoadingState";
|
export { default as LoadingState } from "./LoadingState";
|
||||||
export { default as FilterBar } from "./FilterBar";
|
export { default as FilterBar } from "./FilterBar";
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { requireAuth } from "../../middleware/auth";
|
|||||||
import { success } from "../../utils/response";
|
import { success } from "../../utils/response";
|
||||||
import { localTimeStr } from "../../utils/date";
|
import { localTimeStr } from "../../utils/date";
|
||||||
import { toCzk } from "../../services/exchange-rates";
|
import { toCzk } from "../../services/exchange-rates";
|
||||||
|
import { resolveCell } from "../../services/plan.service";
|
||||||
|
|
||||||
export default async function dashboardRoutes(
|
export default async function dashboardRoutes(
|
||||||
fastify: FastifyInstance,
|
fastify: FastifyInstance,
|
||||||
@@ -42,6 +43,29 @@ export default async function dashboardRoutes(
|
|||||||
result.my_shift = { has_ongoing: myShift !== null };
|
result.my_shift = { has_ongoing: myShift !== null };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Today's work plan (personal) — powers the "Vaše dnešní zařazení" card.
|
||||||
|
// resolveCell applies override-beats-range precedence; null = the user has
|
||||||
|
// plan access but nothing is scheduled today. The category key is enriched
|
||||||
|
// with its label + colour so the widget needs no extra query. todayStr uses
|
||||||
|
// local (Europe/Prague) calendar date — the plan's @db.Date day.
|
||||||
|
if (has("attendance.record") || has("attendance.manage")) {
|
||||||
|
const todayStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
|
||||||
|
const cell = await resolveCell(userId, todayStr);
|
||||||
|
if (cell) {
|
||||||
|
const cat = await prisma.plan_categories.findUnique({
|
||||||
|
where: { key: cell.category },
|
||||||
|
select: { label: true, color: true },
|
||||||
|
});
|
||||||
|
result.today_plan = {
|
||||||
|
...cell,
|
||||||
|
category_label: cat?.label ?? cell.category,
|
||||||
|
category_color: cat?.color ?? null,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
result.today_plan = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Attendance admin — only for attendance.manage
|
// Attendance admin — only for attendance.manage
|
||||||
if (has("attendance.manage")) {
|
if (has("attendance.manage")) {
|
||||||
const [todayAttendance, onLeaveToday, usersCount] = await Promise.all([
|
const [todayAttendance, onLeaveToday, usersCount] = await Promise.all([
|
||||||
|
|||||||
@@ -310,7 +310,9 @@ export default async function ordersRoutes(
|
|||||||
const id = parseId(request.params.id, reply);
|
const id = parseId(request.params.id, reply);
|
||||||
if (id === null) return;
|
if (id === null) return;
|
||||||
|
|
||||||
const result = await deleteOrder(id);
|
const body = request.body as Record<string, unknown> | undefined;
|
||||||
|
const deleteFiles = !!body?.delete_files;
|
||||||
|
const result = await deleteOrder(id, deleteFiles);
|
||||||
if ("error" in result) return error(reply, result.error!, result.status!);
|
if ("error" in result) return error(reply, result.error!, result.status!);
|
||||||
|
|
||||||
await logAudit({
|
await logAudit({
|
||||||
|
|||||||
@@ -105,8 +105,12 @@ interface DownloadResult {
|
|||||||
export class NasFileManager {
|
export class NasFileManager {
|
||||||
private readonly basePath: string;
|
private readonly basePath: string;
|
||||||
|
|
||||||
constructor() {
|
constructor(basePath?: string) {
|
||||||
this.basePath = path.resolve(config.nas.path).replace(/\\/g, "/");
|
// basePath is an injection seam for tests; production callers pass nothing
|
||||||
|
// and get the configured NAS_PATH.
|
||||||
|
this.basePath = path
|
||||||
|
.resolve(basePath ?? config.nas.path)
|
||||||
|
.replace(/\\/g, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
public isConfigured(): boolean {
|
public isConfigured(): boolean {
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import {
|
|||||||
releaseSharedNumber,
|
releaseSharedNumber,
|
||||||
isOrderNumberTaken,
|
isOrderNumberTaken,
|
||||||
} from "./numbering.service";
|
} from "./numbering.service";
|
||||||
|
import { NasFileManager } from "./nas-file-manager";
|
||||||
|
|
||||||
|
// Best-effort NAS folder creation for order-spawned projects, mirroring
|
||||||
|
// projects.service. Stateless singleton; reads NAS_PATH at construction.
|
||||||
|
const nasFileManager = new NasFileManager();
|
||||||
|
|
||||||
interface OrderItemInput {
|
interface OrderItemInput {
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
@@ -262,6 +267,23 @@ export async function createOrderFromQuotation(
|
|||||||
return { order, project, orderNumber };
|
return { order, project, orderNumber };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Best-effort NAS project folder, outside the transaction (mirrors
|
||||||
|
// createProject). A project created from an accepted offer must get the same
|
||||||
|
// 02_PROJEKTY/<number>_<name> folder as a manually-created one. Non-fatal: a
|
||||||
|
// NAS outage must never roll back the order.
|
||||||
|
if (result.project.project_number && nasFileManager.isConfigured()) {
|
||||||
|
const created = nasFileManager.createProjectFolder(
|
||||||
|
result.project.project_number,
|
||||||
|
result.project.name || "",
|
||||||
|
);
|
||||||
|
if (!created) {
|
||||||
|
console.error(
|
||||||
|
"[orders.service] NAS folder not created for project",
|
||||||
|
result.project.project_number,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: {
|
data: {
|
||||||
order_id: result.order.id,
|
order_id: result.order.id,
|
||||||
@@ -297,7 +319,7 @@ export async function createOrder(
|
|||||||
attachmentName?: string | null,
|
attachmentName?: string | null,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
return await prisma.$transaction(async (tx) => {
|
const result = await prisma.$transaction(async (tx) => {
|
||||||
const orderNumber =
|
const orderNumber =
|
||||||
body.order_number !== undefined && body.order_number !== null
|
body.order_number !== undefined && body.order_number !== null
|
||||||
? String(body.order_number)
|
? String(body.order_number)
|
||||||
@@ -362,6 +384,8 @@ export async function createOrder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let projectId: number | undefined;
|
let projectId: number | undefined;
|
||||||
|
let createdProject: { project_number: string; name: string } | null =
|
||||||
|
null;
|
||||||
// Only auto-create a project for genuine offer-less orders; share the
|
// Only auto-create a project for genuine offer-less orders; share the
|
||||||
// order's number (same shared pool) exactly like the from-quotation flow.
|
// order's number (same shared pool) exactly like the from-quotation flow.
|
||||||
if (body.create_project !== false && body.quotation_id == null) {
|
if (body.create_project !== false && body.quotation_id == null) {
|
||||||
@@ -375,14 +399,42 @@ export async function createOrder(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
projectId = project.id;
|
projectId = project.id;
|
||||||
|
if (project.project_number) {
|
||||||
|
createdProject = {
|
||||||
|
project_number: project.project_number,
|
||||||
|
name: project.name || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: order.id,
|
id: order.id,
|
||||||
order_number: order.order_number,
|
order_number: order.order_number,
|
||||||
project_id: projectId,
|
project_id: projectId,
|
||||||
|
createdProject,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Best-effort NAS project folder, outside the transaction (mirrors
|
||||||
|
// createProject). Non-fatal so a NAS outage can't roll back the order.
|
||||||
|
if (result.createdProject && nasFileManager.isConfigured()) {
|
||||||
|
const created = nasFileManager.createProjectFolder(
|
||||||
|
result.createdProject.project_number,
|
||||||
|
result.createdProject.name,
|
||||||
|
);
|
||||||
|
if (!created) {
|
||||||
|
console.error(
|
||||||
|
"[orders.service] NAS folder not created for project",
|
||||||
|
result.createdProject.project_number,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: result.id,
|
||||||
|
order_number: result.order_number,
|
||||||
|
project_id: result.project_id,
|
||||||
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof Error && "status" in err) {
|
if (err instanceof Error && "status" in err) {
|
||||||
return {
|
return {
|
||||||
@@ -536,15 +588,17 @@ export async function updateOrder(id: number, body: UpdateOrderData) {
|
|||||||
return { data: { id, order_number: existing.order_number } };
|
return { data: { id, order_number: existing.order_number } };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteOrder(id: number) {
|
export async function deleteOrder(id: number, deleteFiles = false) {
|
||||||
const existing = await prisma.orders.findUnique({ where: { id } });
|
const existing = await prisma.orders.findUnique({ where: { id } });
|
||||||
if (!existing)
|
if (!existing)
|
||||||
return { error: "Objednávka nenalezena", status: 404 } as const;
|
return { error: "Objednávka nenalezena", status: 404 } as const;
|
||||||
|
|
||||||
// Fetch linked projects before the transaction for number release later
|
// Fetch linked projects before the transaction for number release and
|
||||||
|
// (optional) NAS folder cleanup later. project_number is needed to locate
|
||||||
|
// the folder on the share.
|
||||||
const linkedProjects = await prisma.projects.findMany({
|
const linkedProjects = await prisma.projects.findMany({
|
||||||
where: { order_id: id },
|
where: { order_id: id },
|
||||||
select: { id: true, created_at: true },
|
select: { id: true, created_at: true, project_number: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
// Guard: projects may have non-cascaded warehouse refs (sklad_issues,
|
// Guard: projects may have non-cascaded warehouse refs (sklad_issues,
|
||||||
@@ -610,6 +664,24 @@ export async function deleteOrder(id: number) {
|
|||||||
await tx.orders.delete({ where: { id } });
|
await tx.orders.delete({ where: { id } });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Best-effort NAS folder cleanup for the order's project(s), outside the
|
||||||
|
// transaction and only when the user ticked the "delete folder" checkbox in
|
||||||
|
// the order delete modal. Non-fatal: a NAS error must not undo the
|
||||||
|
// already-committed DB delete. deleteProjectFolder is idempotent — it returns
|
||||||
|
// true (no-op) when the folder is already absent.
|
||||||
|
if (deleteFiles && nasFileManager.isConfigured()) {
|
||||||
|
for (const p of linkedProjects) {
|
||||||
|
if (!p.project_number) continue;
|
||||||
|
const ok = await nasFileManager.deleteProjectFolder(p.project_number);
|
||||||
|
if (!ok) {
|
||||||
|
console.error(
|
||||||
|
"[orders.service] NAS folder not deleted for project",
|
||||||
|
p.project_number,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const year = existing.created_at
|
const year = existing.created_at
|
||||||
? new Date(existing.created_at).getFullYear()
|
? new Date(existing.created_at).getFullYear()
|
||||||
: new Date().getFullYear();
|
: new Date().getFullYear();
|
||||||
|
|||||||
@@ -189,10 +189,16 @@ export async function createProject(data: CreateProjectInput) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (project.project_number && nasFileManager.isConfigured()) {
|
if (project.project_number && nasFileManager.isConfigured()) {
|
||||||
nasFileManager.createProjectFolder(
|
const created = nasFileManager.createProjectFolder(
|
||||||
project.project_number,
|
project.project_number,
|
||||||
project.name || "",
|
project.name || "",
|
||||||
);
|
);
|
||||||
|
if (!created) {
|
||||||
|
console.error(
|
||||||
|
"[projects.service] NAS folder not created for project",
|
||||||
|
project.project_number,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return project;
|
return project;
|
||||||
|
|||||||
Reference in New Issue
Block a user