Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ function Shell() {
<a className="skip" href="#main" onClick={(e) => { e.preventDefault(); document.getElementById("main")?.focus(); }}>Chuyển đến nội dung</a>
{!(isAdminPage && !adminBody && authed) && !(isOpsPage && authed && opsAllowed) && !(isBusinessPage && !businessBody && authed) && <Header page={route.page} />}
{(WORKFLOW_DEMO || mode === "local") && <p className="demo-banner" role="status">MÔ PHỎNG FE · Dữ liệu thử nghiệm, không thanh toán / chuyển tiền thật.</p>}
<div id="main" tabIndex={-1} key={route.raw.split("?")[0]}>
{/* Khu khách hàng: đổi key theo đường dẫn để mỗi trang dựng lại.
Khu Nhân viên/Quản lý/Vận hành KD/Quản trị: giữ key theo khu để header, menu và dữ liệu vận hành
không bị dựng lại (mất dữ liệu → hiện "Đang tải…" → giật) mỗi lần bấm; nội dung từng trang dựng lại trong *Routes. */}
<div id="main" tabIndex={-1} key={isAdminPage || isOpsPage || isBusinessPage ? `area:${route.page}` : route.raw.split("?")[0]}>
{needsLogin ? null : loadError && !ready ? (
<main className="container page">
<Empty title="Không tải được dữ liệu" text={loadError}>
Expand All @@ -202,7 +205,7 @@ function Shell() {
businessBody || <BusinessRoutes parts={route.parts} query={route.query} />
) : isOpsPage ? (
opsAllowed ? (
<OpsProvider notify={notify} mode={mode} onApiError={onApiError} role={opsRole}>
<OpsProvider notify={notify} mode={mode} onApiError={onApiError} role={opsRole} navKey={route.raw.split("?")[0]}>
<FacilityOperationsRoutes role={opsRole} parts={route.parts} query={route.query} />
</OpsProvider>
) : (
Expand Down
9 changes: 7 additions & 2 deletions SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ export function useRoute() {
const read = () => (typeof window === "undefined" ? parseRoute("") : parseRoute(window.location.hash));
const [route, setRoute] = useState(read);
useEffect(() => {
let lastPath = read().raw.split("?")[0];
const onChange = () => {
setRoute(read());
window.scrollTo(0, 0);
const next = read();
const path = next.raw.split("?")[0];
setRoute(next);
// Chỉ cuộn lên đầu khi đổi trang; đổi bộ lọc / ?id trong cùng trang thì giữ vị trí để không bị nhảy
if (path !== lastPath) window.scrollTo(0, 0);
lastPath = path;
};
window.addEventListener("hashchange", onChange);
return () => window.removeEventListener("hashchange", onChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ export default function AdminRoutes({ parts }) {
// tab: truyền mục menu hiện tại cho AdminShell.
// body: nội dung trang được chọn ở các điều kiện phía trên.
// {body} được truyền vào AdminShell thông qua children.
return <AdminLayout tab={tab}>{body}</AdminLayout>;
// key theo đường dẫn: nội dung trang dựng lại khi đổi trang, header/menu giữ nguyên (không giật)
return <AdminLayout tab={tab}><React.Fragment key={parts.join("/")}>{body}</React.Fragment></AdminLayout>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { adminApi } from "../api/adminApi.js";
import { Select } from "../../../shared/components/Pickers.jsx";
import { Button, Field, Modal, Notice } from "../../../shared/components/UI.jsx";
import { isEmail, isPhone, today } from "../../../shared/utils/format.js";
import { FACILITY_ROLES, roleLabel, sortRoles } from "../../../shared/utils/roles.js";
import { FACILITY_ROLES, roleLabel, sortRoles, uniqueRoles } from "../../../shared/utils/roles.js";
import { go } from "../../../app/router.js";
import { useChangeFlow } from "../../../shared/components/ChangeFlowDialog.jsx";
import { useApp } from "../../../app/state/AppProvider.jsx";
Expand Down Expand Up @@ -63,7 +63,7 @@ export default function CreateUserPage() {

const meta = useLoad(async () => {
const [roles, facilities] = await Promise.all([adminApi.roles(), adminApi.facilities()]);
return { roles: sortRoles(roles, (r) => r.roleName), facilities: facilities.filter((f) => f.status === "ACTIVE") };
return { roles: uniqueRoles(sortRoles(roles, (r) => r.roleName), (r) => r.roleName), facilities: facilities.filter((f) => f.status === "ACTIVE") };
}, [], onApiError);


Expand Down Expand Up @@ -380,32 +380,38 @@ export default function CreateUserPage() {
Hiển thị mỗi role dưới dạng một nút lựa chọn. */}
<div className={`field${errors.roleId ? " field--invalid" : ""}`}>
<span className="field__label" id="role-label">Vai trò</span>
<div className="role-chips" role="radiogroup" aria-labelledby="role-label">

{/* Render danh sách vai trò lấy từ API. */}
{roles.map((r) => (
{/* Hai nhóm: vai trò phải chọn cơ sở (Nhân viên, Quản lý) ở trên; vai trò không gắn cơ sở ở dưới. */}
<div className="role-groups" role="radiogroup" aria-labelledby="role-label">
<div className="role-group">
<span className="role-group__label">Theo cơ sở · cần chọn cơ sở phụ trách</span>
<div className="role-chips">{roles.filter((r) => FACILITY_ROLES.includes(r.roleName)).map((r) => (
<button
type="button"
key={r.roleId}

// Khai báo nút có hành vi giống radio.
role="radio"

// Xác định vai trò này đang được chọn hay không.
aria-checked={String(form.roleId) === String(r.roleId)}

// Thêm class is-on để làm nổi bật role đang chọn.
className={String(form.roleId) === String(r.roleId) ? "is-on" : ""}

// Khi click, cập nhật roleId của form.
onClick={() => set("roleId", r.roleId)}
>
{/* Hiển thị tên vai trò dễ đọc. */}
{roleLabel(r.roleName)}
</button>
))}

{/* Trong lúc API tải vai trò, hiển thị thông báo. */}
))}</div>
</div>
<div className="role-group">
<span className="role-group__label">Không gắn cơ sở</span>
<div className="role-chips">{roles.filter((r) => !FACILITY_ROLES.includes(r.roleName)).map((r) => (
<button
type="button"
key={r.roleId}
role="radio"
aria-checked={String(form.roleId) === String(r.roleId)}
className={String(form.roleId) === String(r.roleId) ? "is-on" : ""}
onClick={() => set("roleId", r.roleId)}
>
{roleLabel(r.roleName)}
</button>
))}</div>
</div>
{meta.loading && <span className="muted">Đang tải vai trò…</span>}
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { DatePicker, Select } from "../../../shared/components/Pickers.jsx";
import { Button, Empty, Field, LinkButton, Notice, StatusTag } from "../../../shared/components/UI.jsx";
import { useChangeFlow } from "../../../shared/components/ChangeFlowDialog.jsx";
import { isEmail, isPhone, today } from "../../../shared/utils/format.js";
import { ASSIGNMENT_STATUS, USER_STATUS, needsFacility, roleLabel, sortRoles } from "../../../shared/utils/roles.js";
import { ASSIGNMENT_STATUS, USER_STATUS, needsFacility, roleLabel, sortRoles, uniqueRoles } from "../../../shared/utils/roles.js";
import { useApp } from "../../../app/state/AppProvider.jsx";
import { dateOnlyLabel, dateTime, tempPassword, useLoad } from "../utils/adminUtils.js";

Expand Down Expand Up @@ -221,7 +221,7 @@ export default function UserDetailPage({ id }) {
]);
return {
user,
roles: sortRoles(roles, (r) => r.roleName),
roles: uniqueRoles(sortRoles(roles, (r) => r.roleName), (r) => r.roleName),
facilities: facilities.filter((f) => f.status === "ACTIVE"),
assignments,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ export default function BusinessRoutes({ parts, query }) {
</main>
);
}
return <BusinessLayout active={active}>{body}</BusinessLayout>;
// key theo đường dẫn: nội dung trang dựng lại khi đổi trang, header/menu giữ nguyên (không giật)
return <BusinessLayout active={active}><React.Fragment key={parts.join("/")}>{body}</React.Fragment></BusinessLayout>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@
.business-app .biz-bars { align-items: flex-start; gap: 20px; height: 184px; padding-top: 10px; }
.business-app .biz-bars__col { justify-content: flex-start; gap: 8px; }
.business-app .biz-bars__col b { display: none; }
.business-app .biz-bars__col i { max-width: none; flex: none; background: var(--purple); border-radius: 6px; }
.business-app .biz-bars__col i { max-width: 220px; flex: none; background: var(--purple); border-radius: 6px; }
/* Ít cơ sở (1–2) thì cột không kéo hết chiều ngang; giữ độ rộng cột như Figma B04 (~5 cơ sở) */
.business-app .biz-bars { justify-content: flex-start; }
.business-app .biz-bars__col { flex: 0 1 220px; }
.business-app .biz-bars__col span { font-size: 13px; line-height: 16px; }
.business-app .business-reports .table th:first-child { width: 27%; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function RenewalStatusPage({ id }) {
const expiredOf = r => r.status === "EXPIRED" || (!paidOf(r) && r.status === "APPROVED" && r.payment_deadline_at && Date.parse(r.payment_deadline_at) <= Date.now());
const label = r => expiredOf(r) ? "Đã hết hạn thanh toán" : r.status === "REJECTED" ? "Đã từ chối" : paidOf(r) ? "Đã thanh toán · Đã gia hạn" : r.status === "APPROVED" ? (r.at_counter ? "Chờ thu tại quầy" : "Đã duyệt · Chờ thanh toán") : "Chờ cơ sở duyệt";
return <main className="container page workflow-page"><PageHeader title="Theo dõi yêu cầu gia hạn" description="Ngày hết hạn chỉ cập nhật sau khi duyệt và thanh toán đủ." />{error && <Notice tone="error">{error}</Notice>}
{rows.map(r => <RecordCard key={r.renewal_id} title={`${r.renewal_id} · ${r.months} tháng`} subtitle={id} status={label(r)} actions={r.status === "APPROVED" && !paidOf(r) && !expiredOf(r) && <><LinkButton to="payments">Thanh toán PayOS</LinkButton><Button variant="outline" disabled={busy || r.at_counter} onClick={async () => { setBusy(true); setError(""); try { const out = await dispatch("CHOOSE_RENEWAL_AT_COUNTER", { renewal_id: r.renewal_id }); setError(out.ok ? "" : out.error); } catch { setError("Chưa chọn được thanh toán tại quầy. Vui lòng thử lại."); } finally { setBusy(false); } }}>Chọn thanh toán tại quầy</Button></>}>
{rows.map(r => <RecordCard key={r.renewal_id} title={`${r.renewal_id} · ${r.months} tháng`} subtitle={id} status={label(r)} actions={r.status === "APPROVED" && !paidOf(r) && !expiredOf(r) && <>{!r.at_counter && <LinkButton to="payments">Thanh toán PayOS</LinkButton>}<Button variant="outline" disabled={busy || r.at_counter} onClick={async () => { setBusy(true); setError(""); try { const out = await dispatch("CHOOSE_RENEWAL_AT_COUNTER", { renewal_id: r.renewal_id }); setError(out.ok ? "" : out.error); } catch { setError("Chưa chọn được thanh toán tại quầy. Vui lòng thử lại."); } finally { setBusy(false); } }}>Chọn thanh toán tại quầy</Button></>}>
<InfoTiles items={[["Hạn thanh toán", r.payment_deadline_at ? `${dateLabel(r.payment_deadline_at)} · ${timeLabel(r.payment_deadline_at)}` : "Chưa có thông tin"], ["Kỳ dự kiến", `${dateLabel(r.old_end)} → ${dateLabel(r.new_end)}`], ["Tiền thuê gia hạn", money(r.amount)], ["Cọc bổ sung", "Không thu lại cọc"]]} />
{expiredOf(r) && <Notice>Yêu cầu gia hạn đã hết hiệu lực. Kỳ thuê hiện tại không thay đổi; không chuyển tiền theo mã cũ.</Notice>}{r.reason && <Notice tone="error">Lý do từ chối: {r.reason}</Notice>}{r.at_counter && !paidOf(r) && !expiredOf(r) && <Notice>Đang chờ nhân viên thu tiền tại quầy. Kỳ thuê hiện tại chưa thay đổi.</Notice>}
</RecordCard>)}{!rows.length && <WorkflowEmpty text="Chưa có yêu cầu gia hạn cho hợp đồng này." />}<LinkButton to={`units/${encodeURIComponent(id)}`} variant="outline">Về hợp đồng</LinkButton></main>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export default function FacilityOperationsRoutes({ role, parts, query }) {
const [Page, active] = hit || [null, ""];
return (
<FacilityOperationsLayout role={role} active={active}>
{/* key theo đường dẫn: nội dung trang dựng lại khi đổi trang, header/menu/dữ liệu giữ nguyên */}
<React.Fragment key={parts.join("/")}>
{Page ? (
staff && LIST_KIND[parts[0]] ? <StaffTab kind={LIST_KIND[parts[0]]} Detail={Page} query={query} /> : <Page key={query.get("id") || "list"} query={query} />
) : (
Expand All @@ -89,6 +91,7 @@ export default function FacilityOperationsRoutes({ role, parts, query }) {
</Empty>
</main>
)}
</React.Fragment>
</FacilityOperationsLayout>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function appendLog(state, text, to) {
return { ...state, log: [{ id: `L-${at.getTime()}`, text, to, role: "ALL", at: at.toISOString(), read: false }, ...(state.log || [])].slice(0, 60) };
}

export function OpsProvider({ children, notify, mode = "local", onApiError, role }) {
export function OpsProvider({ children, notify, mode = "local", onApiError, role, navKey }) {
// source: "loading" | "api" | "local"
const [source, setSource] = useState(mode === "api" ? "loading" : "local");
const [state, setState] = useState(() => (mode === "api" ? null : readOps()));
Expand Down Expand Up @@ -214,6 +214,12 @@ export function OpsProvider({ children, notify, mode = "local", onApiError, role
window.addEventListener("focus", refresh);
return () => { clearInterval(timer); window.removeEventListener("focus", refresh); };
}, [mode, reload]);
// Đổi trang trong khu vận hành: nạp lại board ngầm (giữ dữ liệu đang hiện, không bật màn "Đang tải…")
const firstNav = useRef(true);
useEffect(() => {
if (firstNav.current) { firstNav.current = false; return; }
if (mode === "api" && !activeAction.current && ref.current) reload();
}, [navKey, mode, reload]);

const reset = useCallback(() => commit(createOpsData()), [commit]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import { InspectionReview } from "../../facility-operations/settlements/SettlementComponents.jsx";
import { canFinalizeReturn } from "../../facility-operations/settlements/settlementModel.js";
import { RecordCard } from "../../facility-operations/workflows/WorkflowComponents.jsx";
Expand Down Expand Up @@ -33,6 +33,9 @@ export function ContractListPage({ query }) {
const sel = query.get("id") ? ops.contracts.find(c=>c.id===query.get("id")) : null;
const [note, setNote] = useState("");
const mismatch = ops.payments.filter((p) => p.status === "MISMATCH");
const detailRef = useRef(null);
// "Xem hồ sơ" mở chi tiết ngay dưới danh sách: cuộn tới để quản lý thấy trang đã chuyển
useEffect(() => { if (sel) detailRef.current?.scrollIntoView({ behavior: "smooth", block: "start" }); }, [sel?.id]);
return (
<main className="container page">
<PageHeaderBlock title="Hợp đồng & xử lý quá hạn" text="Theo dõi hạn thuê, đối soát trả kho và yêu cầu cần duyệt tại cơ sở." />
Expand All @@ -42,9 +45,8 @@ export function ContractListPage({ query }) {
))}
<div className="customer-detail__column">{ops.contracts.map(c=>{const [label,tone]=CONTRACT_STATE(c);return <RecordCard key={c.id} title={`${c.id} · ${c.customer}`} subtitle={`Kho ${c.unit} · hết hạn ${dateLabel(c.end)}`} status={label} actions={<LinkButton to={c.state==="RENEWAL"?"manager/renewals":`manager/contracts${qs({id:c.id})}`}>{c.state==="RETURNED"?"Duyệt đối soát":c.state==="OVERDUE"?"Xem hồ sơ quá hạn":"Xem hồ sơ"}</LinkButton>}><p>{c.state==="RETURNED"?"Biên bản đã gửi · khấu trừ tối đa bằng cọc":c.state==="RENEWAL"?"Có yêu cầu gia hạn cần duyệt":"Theo dõi hạn thuê và lịch sử liên hệ khách"}</p></RecordCard>;})}</div>
{query.get("id")&&!sel&&<Empty title="Không tìm thấy hợp đồng" text="Chọn đúng hồ sơ thuộc cơ sở phụ trách."/>}
<div className="workflow-links"><LinkButton to="manager/refunds" variant="outline">Hoàn tiền đơn huỷ</LinkButton><LinkButton to="manager/deposit-refunds" variant="outline">Hoàn cọc sau trả kho</LinkButton></div>
{sel && (
<section className="panel form-card">
<section className="panel form-card contract-detail" ref={detailRef}>
<h2>{sel.id} · Bước tiếp theo</h2>
{sel.state === "RETURNED" ? (
<>
Expand Down Expand Up @@ -84,16 +86,15 @@ export function ContractListPage({ query }) {
}}
/>
)}
<LinkButton to="manager/deposit-refunds" variant="outline">Hoàn cọc sau trả kho</LinkButton>
{/* Figma M07: lối vào M08 hoàn tiền đơn huỷ */}
<LinkButton to="manager/refunds" className="btn--fit">Hoàn tiền đơn huỷ{(ops.refunds || []).some((r) => r.status === "PENDING") ? ` (${ops.refunds.filter((r) => r.status === "PENDING").length})` : ""}</LinkButton>
{(sel.reminders || []).length > 0 && (
<ul className="ops-notes">
{sel.reminders.map((r, i) => <li key={i}><small>{dateTimeLabel(r.at)}</small>{r.text}</li>)}
</ul>
)}
</section>
)}
{/* Figma M07: lối vào M08 hoàn tiền đơn huỷ và hoàn cọc, một thẻ cuối trang */}
<div className="panel workflow-links workflow-links--panel"><LinkButton to="manager/refunds" variant="outline">Hoàn tiền đơn huỷ{(ops.refunds || []).some((r) => r.status === "PENDING") ? ` (${ops.refunds.filter((r) => r.status === "PENDING").length})` : ""}</LinkButton><LinkButton to="manager/deposit-refunds" variant="outline">Hoàn cọc sau trả kho</LinkButton></div>
</main>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@
from { opacity: 0; }
to { opacity: 1; }
}
/* Chuyển trang chỉ mờ nhẹ, không trượt: mờ từ 0 hoặc dịch lên xuống làm màn hình chớp và nhảy khi bấm liên tục */
@keyframes ss-page-in {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: none; }
from { opacity: 0.55; }
to { opacity: 1; }
}
@keyframes ss-pop-in {
from { opacity: 0; transform: translateY(8px) scale(0.97); }
Expand All @@ -70,8 +71,9 @@
to { opacity: 1; transform: none; }
}

/* Chuyển trang: #main đổi key theo đường dẫn trong App.jsx nên chạy lại mỗi lần đổi trang */
#main { animation: ss-page-in var(--ss-base) var(--ss-ease) both; }
/* Chuyển trang: #main đổi key theo đường dẫn ở khu khách hàng (App.jsx) nên chạy lại mỗi lần đổi trang.
Khu nhân viên/quản lý/vận hành/quản trị giữ #main theo khu nên chỉ chạy khi vào khu, không chớp mỗi lần bấm. */
#main { animation: ss-page-in var(--ss-fast) ease-out; }

/* Popup chuẩn (Modal/ConfirmDialog): nền mờ dần, hộp phóng nhẹ */
.overlay { animation: ss-fade-in var(--ss-fast) ease-out both; }
Expand Down
Loading
Loading