cce99aadfd
A round of operator-facing fixes on the booth screen, shift views, and the
font-scale control. (Follows the font-scale feature in f706726, which used CSS
`zoom` — reverted here for the rem approach below.)
Font scaling (the A−/A+ control now actually works without breaking layout):
- The control scaled via CSS `zoom`, which also scaled viewport-locked containers
(h-screen frame, max-h-[90vh] modals) so at 130% modal headers/footers were
pushed off-screen. Reworked to scale TEXT only: converted every `text-[Npx]`
font utility to rem across the web app (~230 sites in 25 files + the
.label/.hint/.btn component classes + body in index.css; 16px root, so 100% is
visually identical), and applyFontScale now sets the ROOT font-size. vh/h-screen
layout stays put, so chrome never clips; tall content scrolls its own container.
Verified at 130%: text 12px→15.6px while the frame stayed viewport-height.
Live feed (event rows):
- Plate, badges and reason now flow inline after the identity and wrap only when
the row runs out of width — no more forced second line when there's empty space.
- Dropped the redundant TARGË via-badge (the plate chip already conveys it).
- Removed the Direction filter group (Hyrje/Dalje) — it duplicated the entry/exit
options already in the Type filter.
Active sessions:
- Rebuilt as a real table (Ticket/subscriber · Plate · Entry · Elapsed) so columns
align and long values (subscriber names, ticket ids) no longer truncate.
- Dropped the status column (an unpaid transient is normal; a subscriber shows ★ +
name; overstay keeps a row tint). Removed the now-redundant status filter; only
the Transient/Subscriber filter remains. Plate is now searchable (uses s.plate).
Shift report (close-shift modal + Shift History + printed Z-report slip):
- Removed the confusing `shitje` (subscription-sales) sub-line — Abonime is the
total; only the out-of-window part is broken out. subscriptionSalesMinor stays in
the signed payload (audit data), just not displayed/printed.
- Show the inherited opening cash ("Arka fillestare") above the expected drawer, so
opening + cash-taken = expected reads clearly. Money values no longer line-wrap.
Subscription edit modal:
- Fixed the 2-col grid alignment: a lone "only one version" cell was shifting every
following row by one column — it now emits a full label+value pair.
Removed orphaned i18n keys (fStatus*, fDir*, srcSubSales) from sq+en (parity kept).
Full workspace build/lint/test green.
Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
179 lines
6.8 KiB
TypeScript
179 lines
6.8 KiB
TypeScript
import { useMemo, useState } from "react";
|
||
import { useTranslation } from "react-i18next";
|
||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||
import {
|
||
ApiError,
|
||
can,
|
||
createRole,
|
||
deleteRole,
|
||
fetchRoles,
|
||
updateRole,
|
||
type ManagedRole,
|
||
type Permission,
|
||
type SessionUser,
|
||
} from "./api.js";
|
||
import { Modal } from "./ui/Modal.js";
|
||
|
||
// Role management (admin). Compose a role from the permission grid (a checkbox
|
||
// matrix of resource × action) and name it; users are then assigned a role. The
|
||
// built-in `admin` role is shown read-only/locked (it always has every permission
|
||
// and can't be edited or deleted). The server enforces the same. See
|
||
// @parking/shared PERMISSIONS.
|
||
|
||
/** Group "resource:action" permissions by resource for the grid rows. */
|
||
function groupByResource(perms: Permission[]): Record<string, Permission[]> {
|
||
const out: Record<string, Permission[]> = {};
|
||
for (const p of perms) {
|
||
const resource = p.split(":")[0]!;
|
||
(out[resource] ??= []).push(p);
|
||
}
|
||
return out;
|
||
}
|
||
|
||
export function RolesManager({ user }: { user: SessionUser | null }) {
|
||
const { t } = useTranslation();
|
||
const qc = useQueryClient();
|
||
const rolesQ = useQuery({ queryKey: ["roles"], queryFn: fetchRoles });
|
||
|
||
const canCreate = can(user, "role:create");
|
||
const canUpdate = can(user, "role:update");
|
||
const canDelete = can(user, "role:delete");
|
||
|
||
const catalog = rolesQ.data?.catalog ?? [];
|
||
const roles = rolesQ.data?.roles ?? [];
|
||
const grouped = useMemo(() => groupByResource(catalog), [catalog]);
|
||
|
||
const [error, setError] = useState<string | null>(null);
|
||
const [editing, setEditing] = useState<ManagedRole | "new" | null>(null);
|
||
|
||
const invalidate = () => {
|
||
void qc.invalidateQueries({ queryKey: ["roles"] });
|
||
void qc.invalidateQueries({ queryKey: ["users"] });
|
||
};
|
||
const onError = (e: unknown) => setError(e instanceof ApiError ? e.message : (e as Error).message);
|
||
|
||
return (
|
||
<div className="">
|
||
<div className="mb-3 flex items-center justify-between">
|
||
<h1 className="text-sm font-bold uppercase tracking-widest text-term-amber">{t("roles.title")}</h1>
|
||
{canCreate && (
|
||
<button type="button" className="btn btn-go btn-sm" onClick={() => { setEditing("new"); setError(null); }}>
|
||
{t("roles.add")}
|
||
</button>
|
||
)}
|
||
</div>
|
||
|
||
{error && <div className="mb-2 rounded-term border border-term-red px-3 py-2 text-[0.75rem] text-term-red">{error}</div>}
|
||
|
||
<Modal
|
||
open={editing != null}
|
||
onClose={() => setEditing(null)}
|
||
title={editing && editing !== "new" ? t("roles.editTitle") : t("roles.new")}
|
||
width="max-w-2xl"
|
||
>
|
||
{editing && (
|
||
<RoleEditor
|
||
role={editing === "new" ? null : editing}
|
||
grouped={grouped}
|
||
onCancel={() => setEditing(null)}
|
||
onSubmit={async (v) => {
|
||
try {
|
||
if (editing === "new") await createRole(v);
|
||
else await updateRole(editing.id, v);
|
||
setEditing(null);
|
||
invalidate();
|
||
} catch (e) { onError(e); }
|
||
}}
|
||
/>
|
||
)}
|
||
</Modal>
|
||
|
||
<div className="flex flex-col gap-2">
|
||
{roles.map((r) => (
|
||
<div key={r.id} className="rounded-term border border-term-border bg-term-panel p-3">
|
||
<div className="flex items-center justify-between">
|
||
<div className="flex items-center gap-2">
|
||
<span className="text-[0.8125rem] font-semibold text-term-text">{r.name}</span>
|
||
{r.builtin && (
|
||
<span className="rounded-term border border-term-amber/50 px-1.5 py-0.5 text-[0.625rem] uppercase tracking-wider text-term-amber">
|
||
{t("roles.builtin")}
|
||
</span>
|
||
)}
|
||
<span className="text-[0.6875rem] text-term-muted">
|
||
{t("roles.permCount", { count: r.permissions.length })} · {t("roles.userCount", { count: r.userCount })}
|
||
</span>
|
||
</div>
|
||
<div className="flex gap-2">
|
||
{canUpdate && !r.builtin && (
|
||
<button type="button" className="btn btn-ghost btn-sm" onClick={() => { setEditing(r); setError(null); }}>{t("roles.edit")}</button>
|
||
)}
|
||
{canDelete && !r.builtin && (
|
||
<button type="button" className="btn btn-danger btn-sm"
|
||
onClick={() => { if (confirm(t("roles.confirmDelete", { name: r.name }))) deleteRoleSafe(r.id, invalidate, onError); }}>{t("roles.delete")}</button>
|
||
)}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
async function deleteRoleSafe(id: string, ok: () => void, onError: (e: unknown) => void) {
|
||
try { await deleteRole(id); ok(); } catch (e) { onError(e); }
|
||
}
|
||
|
||
function RoleEditor({
|
||
role, grouped, onCancel, onSubmit,
|
||
}: {
|
||
role: ManagedRole | null;
|
||
grouped: Record<string, Permission[]>;
|
||
onCancel: () => void;
|
||
onSubmit: (v: { name: string; permissions: Permission[] }) => void;
|
||
}) {
|
||
const { t } = useTranslation();
|
||
const [name, setName] = useState(role?.name ?? "");
|
||
const [perms, setPerms] = useState<Set<Permission>>(new Set(role?.permissions ?? []));
|
||
const toggle = (p: Permission) =>
|
||
setPerms((prev) => {
|
||
const next = new Set(prev);
|
||
next.has(p) ? next.delete(p) : next.add(p);
|
||
return next;
|
||
});
|
||
|
||
const valid = name.trim().length > 0;
|
||
|
||
return (
|
||
<div>
|
||
<div className="field mb-3 w-64">
|
||
<span className="label">{t("roles.name")}</span>
|
||
<input className="input" value={name} onChange={(e) => setName(e.target.value)} />
|
||
</div>
|
||
|
||
<div className="label">{t("roles.permissions")}</div>
|
||
<div className="mt-1 grid grid-cols-1 gap-1">
|
||
{Object.entries(grouped).map(([resource, list]) => (
|
||
<div key={resource} className="flex flex-wrap items-center gap-x-4 gap-y-1 border-t border-term-border py-1.5">
|
||
<span className="w-28 shrink-0 text-[0.75rem] font-semibold text-term-text">{resource}</span>
|
||
{list.map((p) => {
|
||
const action = p.split(":")[1]!;
|
||
return (
|
||
<label key={p} className="flex items-center gap-1 text-[0.75rem] text-term-text">
|
||
<input type="checkbox" className="accent-term-amber" checked={perms.has(p)} onChange={() => toggle(p)} />
|
||
{action}
|
||
</label>
|
||
);
|
||
})}
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
<div className="mt-3 flex justify-end gap-2">
|
||
<button type="button" className="btn btn-sm" onClick={onCancel}>{t("common.cancel")}</button>
|
||
<button type="button" className="btn btn-primary btn-sm" disabled={!valid} onClick={() => onSubmit({ name: name.trim(), permissions: [...perms] })}>{t("common.save")}</button>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|