Skip to content
Merged
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
10 changes: 10 additions & 0 deletions DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,13 @@ Bổ sung @playwright/test trong devDependencies để kiểm thao tác biểu m
- Khách đã chọn một ô cụ thể trên sơ đồ mà ô đó đang thuê / đang giữ: ô **Ngày bắt đầu** chỉ cho chọn từ ngày ô trống lại (`free_from` = hết hạn đơn trước + ngày đệm). Các ngày trước đó vẫn hiện trên lịch nhưng **làm mờ, không bấm được**; ngày đang chọn tự dời tới ngày sớm nhất hợp lệ. Dưới lịch ghi "Ô … đang có người thuê đến … · chọn được ngày bắt đầu từ …".
- Ở chế độ đặt đúng ô **không hiện hộp đỏ "Không còn ô trống cho cả kỳ thuê"** và nút đặt không bị khoá vì số ô trống theo loại kho; chỉ xét chính ô đã chọn. Hộp này vẫn giữ cho chế độ tự bố trí.
- Ô quá hạn trả (không có `free_from`) giữ như cũ: không nhận đặt trước, hiện lý do.

## D63 — 17/11/2026: Dọn ghi chú màn hình, vai trò dưới tên khách, hotline chữ thường — Đã chốt

> Vector chốt ngày 17/11/2026. Bổ sung D32 (mục Giao diện: "màn không ghi mã nội bộ") và D50 (#1 hotline, #23 bỏ quản lý duyệt gia hạn); giữ nguyên lịch sử ở trên. Không đổi API, không đổi database (D48).

- **Ghi chú trên màn hình viết cho người dùng, không viết cho dev:** bỏ hoặc viết lại câu nhắc lệnh chạy, biến môi trường, đường dẫn API, "backend", "máy chủ chưa hỗ trợ…", mã quyết định (D32) và các câu giải thích cách hệ thống tính. Thông báo lỗi giữ hướng dẫn cho người dùng ("Vui lòng thử lại sau", "Tải lại trước khi gửi tiếp").
- **Chế độ thử nghiệm (mock/offline):** giữ một dải báo chung ở đầu trang ("Chế độ thử nghiệm · Dữ liệu mẫu, không thanh toán hoặc chuyển tiền thật.") để người kiểm thử nhận biết (AGENTS.md mục 5); bỏ các ghi chú "Chế độ mô phỏng FE" lặp lại trên từng màn.
- **Gia hạn (D50 #23):** chữ hiển thị không còn "chờ quản lý duyệt" / "cơ sở duyệt và chốt giá"; dùng "chờ xác nhận" / "đã được xác nhận".
- **Màn khách hàng:** dưới họ tên trên thanh đầu trang hiện vai trò "Khách hàng" (giống thẻ vai trò của nhân viên, quản lý, admin).
- **Hotline ở chân trang** hiện chữ thường cùng màu các dòng khác, không còn là liên kết `tel:`. Số hotline giữ theo D50.
2 changes: 1 addition & 1 deletion SafeSpace-Customer-UI/SafeSpace-Customer-UI/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "vite --host 127.0.0.1",
"build": "vite build --base=./",
"preview": "vite preview --host 127.0.0.1",
"test": "node --test tests/patch13.test.js tests/contract-paper.test.js tests/refund-request.test.js tests/renewal-consent.test.js tests/figma-batch04.test.js tests/reservation-policy.test.js tests/damage-workflow.test.js tests/incident-workflow.test.js tests/settlement-batch08.test.js tests/admin-business-batch09.test.js tests/return-policy.test.js tests/reducer.test.js tests/api-mappers.test.js tests/admin.test.js tests/ops.test.js tests/units.test.js tests/ops-api.test.mjs tests/payment-access.test.js tests/payment-api.test.mjs tests/access.test.js tests/figma-workflow.test.js tests/auth-support-integration.test.js tests/renewal-unit-move.test.js tests/luot1-ui.test.js tests/luot2-settlement.test.js tests/luot3-renewal.test.js tests/luot4-units.test.js tests/luot4b-nav.test.js tests/luot5-reports.test.js tests/luot6-door-demo.test.mjs tests/qr-reader.test.js tests/admin-logs.test.js",
"test": "node --test tests/patch13.test.js tests/contract-paper.test.js tests/refund-request.test.js tests/renewal-consent.test.js tests/figma-batch04.test.js tests/reservation-policy.test.js tests/damage-workflow.test.js tests/incident-workflow.test.js tests/settlement-batch08.test.js tests/admin-business-batch09.test.js tests/return-policy.test.js tests/reducer.test.js tests/api-mappers.test.js tests/admin.test.js tests/ops.test.js tests/units.test.js tests/ops-api.test.mjs tests/payment-access.test.js tests/payment-api.test.mjs tests/payment-status.test.js tests/access.test.js tests/figma-workflow.test.js tests/auth-support-integration.test.js tests/renewal-unit-move.test.js tests/luot1-ui.test.js tests/luot2-settlement.test.js tests/luot3-renewal.test.js tests/luot4-units.test.js tests/luot4b-nav.test.js tests/luot5-reports.test.js tests/luot6-door-demo.test.mjs tests/qr-reader.test.js tests/admin-logs.test.js",
"test:render": "node tests/render.test.mjs",
"dev:mock": "node scripts/dev-mock.mjs",
"check:structure": "node scripts/check-structure.mjs",
Expand Down
6 changes: 3 additions & 3 deletions SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ function Shell() {
}, [isAdmin, isOps, businessAllowed, roles, route.page]);

const businessBody = mode !== "api" ? (
<main className="container page"><Empty title="Khu vận hành kinh doanh cần kết nối máy chủ" text="Chạy npm run dev:business để xem giao diện khi chưa có backend, hoặc bật chế độ API và chạy máy chủ của bạn." /></main>
<main className="container page"><Empty title="Khu vận hành kinh doanh chưa sẵn sàng" text="Chưa kết nối được hệ thống. Vui lòng thử lại sau." /></main>
) : authed && !businessAllowed ? (
<main className="container page"><Empty title="Bạn không có quyền truy cập" text="Tài khoản hiện tại không được phép xem nội dung này. Khu này dành cho tài khoản Quản lý vận hành kinh doanh."><LinkButton to={homeFor(roles)}>Về tổng quan</LinkButton></Empty></main>
) : null;

const adminBody =
mode !== "api" ? (
<main className="container page">
<Empty title="Khu quản trị cần kết nối máy chủ" text="Bật VITE_USE_API=true và chạy backend SSFRMS để quản lý tài khoản, vai trò và nhật ký.">
<Empty title="Khu quản trị chưa sẵn sàng" text="Chưa kết nối được hệ thống. Vui lòng thử lại sau.">
<LinkButton to="home">Về trang chủ</LinkButton>
</Empty>
</main>
Expand All @@ -201,7 +201,7 @@ function Shell() {
<div className={`app${!isAdminPage && !isOpsPage && !isBusinessPage ? " customer-app" : ""}${["profile", "support"].includes(route.page) ? " app--auth-support" : ""}`}>
<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>}
{(WORKFLOW_DEMO || mode === "local") && <p className="demo-banner" role="status">Chế độ thử nghiệm · Dữ liệu mẫu, không thanh toán hoặc chuyển tiền thật.</p>}
{/* 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. */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { submitCancellation, submitReturnRequest } from "../../shared/api/refund
import { readPhotoData, verifyPhotoFile } from "../../shared/utils/refundRequest.js";
import { submitRenewalWithConsent } from "../../shared/api/renewalConsentApi.js";
import { api } from "../../shared/api/customerApi.js";
import { paidBeforeExpiry } from "../../shared/api/paymentStatus.js";
import { ApiError, setToken } from "../../shared/api/httpClient.js";
import { isUnsupported, localAccessCode, normAccess, normCancelPreview, normDoor, normPayos, normScan } from "../../features/customer/access/accessApi.js";
import { notYetMessage } from "../../shared/utils/access.js";
Expand Down Expand Up @@ -312,6 +313,7 @@ const EMPTY_REMOTE = { reservations: [], reservationDetails: {}, contracts: [],
const fail = (error, code) => ({ ok: false, error, code });
const readOverlay = (userId) => ({ ...emptyOverlay(), ...(readJson(overlayKey(userId)) || {}) });


function ApiProvider({ children }) {
const [session, setSession] = useState(() => {
const s = readSession();
Expand Down Expand Up @@ -479,10 +481,11 @@ function ApiProvider({ children }) {
if (cancelling.current.has(r.reservationId)) continue;
cancelling.current.add(r.reservationId);
const seconds = refs.current.overlay.holds[r.reservationId] ? paymentTimeoutSeconds : 24 * 3600;
api
.cancelReservation(r.reservationId, `Quá ${timeoutLabel(seconds)} chưa thanh toán`)
.catch(() => {})
.then(() => loadCustomer().catch(() => {}));
paidBeforeExpiry(r.reservationId).then(async (paid) => {
if (paid === false) await api.cancelReservation(r.reservationId, `Quá ${timeoutLabel(seconds)} chưa thanh toán`).catch(() => {});
else if (paid === null) cancelling.current.delete(r.reservationId);
await loadCustomer().catch(() => {});
});
}
};
const id = setInterval(tick, 5000);
Expand Down Expand Up @@ -661,8 +664,14 @@ function ApiProvider({ children }) {
const r = d.reservations.find((x) => x.reservation_id === p.reservation_id);
if (!r) return fail("Không tìm thấy đơn đặt chỗ.", "NOT_FOUND");
if (!r.transfer_confirmed_at && ["PENDING_PAYMENT", "CANCELLED"].includes(r.status)) {
// Khách có thể vừa trả tiền ở những giây cuối: hỏi máy chủ trước khi huỷ.
const paid = cancelling.current.has(r.api_id) ? false : await paidBeforeExpiry(r.api_id);
if (paid) {
await loadCustomer().catch(() => {});
return { ok: true, status: "PAID" };
}
updateOverlay((o) => ({ ...o, expired: { ...o.expired, [r.api_id]: Date.now() } }));
if (!cancelling.current.has(r.api_id)) {
if (paid === false && !cancelling.current.has(r.api_id)) {
cancelling.current.add(r.api_id);
api
.cancelReservation(r.api_id, `Quá ${timeoutLabel(r.timeout_seconds || paymentTimeoutSeconds)} chưa thanh toán`)
Expand Down Expand Up @@ -694,7 +703,7 @@ function ApiProvider({ children }) {
const { dto, acknowledged } = await submitRenewalWithConsent(api, c.api_id, months, p.policy_consent);
if (!acknowledged) {
await loadCustomer();
return fail("Máy chủ đã nhận gia hạn nhưng chưa xác nhận bằng chứng đồng ý. Kiểm tra Theo dõi gia hạn hoặc liên hệ cơ sở trước khi gửi lại.");
return fail("Đã gửi gia hạn nhưng chưa ghi nhận được xác nhận đồng ý chính sách. Kiểm tra Theo dõi gia hạn trước khi gửi lại.");
}
remember("Gia hạn đã được xác nhận", `Kho ${c.unit_number} · mở thanh toán để kéo dài hợp đồng.`, "payments", `Gia hạn ${c.unit_number} đã xác nhận — chờ thanh toán`);
await loadCustomer();
Expand All @@ -703,7 +712,7 @@ function ApiProvider({ children }) {
case "CANCEL_RENEWAL": {
const r = d.renewals.find((x) => x.renewal_id === p.renewal_id);
if (!r) return fail("Không tìm thấy yêu cầu gia hạn.", "NOT_FOUND");
if (r.status !== "PENDING") return fail("Chỉ huỷ được yêu cầu gia hạn đang chờ quản lý duyệt.");
if (r.status !== "PENDING") return fail("Chỉ huỷ được yêu cầu gia hạn đang chờ xác nhận.");
await api.cancelRenewal(r.api_id);
const c = d.contracts.find((x) => x.contract_id === r.contract_id);
remember("Đã huỷ yêu cầu gia hạn", `${r.renewal_id} · Kho ${c?.unit_number ?? ""}`.trim(), `units/${r.contract_id}`, `Yêu cầu gia hạn ${r.renewal_id} đã huỷ`);
Expand Down Expand Up @@ -796,7 +805,7 @@ function ApiProvider({ children }) {
// C11fc: backend chưa có API chọn trả phí tại quầy → ghi trong trình duyệt; nhân viên thu ở S09f
case "CHOOSE_RENEWAL_AT_COUNTER": {
const renewal = d.renewals.find(x => x.renewal_id === p.renewal_id);
if (!renewal || renewal.status !== "APPROVED") return fail("Yêu cầu chưa được duyệt hoặc đã thanh toán.");
if (!renewal || renewal.status !== "APPROVED") return fail("Yêu cầu chưa được xác nhận hoặc đã thanh toán.");
await api.chooseRenewalCounter(renewal.api_id);
await loadCustomer();
return { ok: true };
Expand Down Expand Up @@ -871,6 +880,12 @@ function ApiProvider({ children }) {
if (paid) await loadCustomer().catch(() => {});
return { ok: true, paid };
}
// /status nhờ máy chủ đối soát thẳng với PayOS (khi chạy máy cá nhân webhook không về được).
const quick = await api.reservationStatus(item.api_id).catch(() => null);
if (quick?.isPaid) {
await loadCustomer().catch(() => {});
return { ok: true, paid: true, cancelled: false };
}
const r = await api.reservation(item.api_id);
const status = String(r?.status || "");
const paid = ["PAID", "CONFIRMED", "UNIT_ASSIGNED", "CHECKED_IN", "COMPLETED"].includes(status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ const handlers = {
CANCEL_RENEWAL(state, p, ctx) {
const r = state.renewals.find((x) => x.renewal_id === p.renewal_id);
if (!r) fail("Không tìm thấy yêu cầu gia hạn.", "NOT_FOUND");
if (r.status !== "PENDING") fail("Chỉ huỷ được yêu cầu gia hạn đang chờ quản lý duyệt.");
if (r.status !== "PENDING") fail("Chỉ huỷ được yêu cầu gia hạn đang chờ xác nhận.");
let next = {
...state,
renewals: state.renewals.map((x) => (x.renewal_id === r.renewal_id ? { ...x, status: "CANCELLED", cancelled_at: iso(ctx.now) } : x)),
Expand Down Expand Up @@ -392,7 +392,7 @@ const handlers = {
if (!c || ["ENDED", "RETURN_PENDING"].includes(c.status) || c.start_date > localDate(ctx.now)) fail("Hợp đồng chưa thể đăng ký trả kho.");
const pending = hasPending(state, c.contract_id);
if (state.returns.some(r => r.contract_id === c.contract_id && !["CANCELLED", "REJECTED"].includes(r.status))) fail("Đã có yêu cầu trả kho đang chờ xử lý.");
if (pending.renewal) fail("Hợp đồng đang có yêu cầu gia hạn chờ duyệt.");
if (pending.renewal) fail("Hợp đồng đang có yêu cầu gia hạn chờ xử lý.");
const dateError = visitDateError(p.date, c.end_date, localDate(ctx.now), "trả kho", c.start_date);
if (dateError) fail(dateError);
const invalid = validateRefundChoice(p.bank, c.customer_name || state.user?.full_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const adminApi = {

// Gán một vai trò cho người dùng (POST /api/admin/users/{userId}/roles)
// Đề xuất atomic replacement; không fallback assign rồi revoke.
changeRole: async(userId,body)=>{try{return await request(`/api/admin/users/${userId}/role-change`,{method:"POST",body});}catch(error){if([404,405].includes(error.status))throw new ApiError("Máy chủ chưa hỗ trợ đổi vai trò trong một thao tác. Chưa đổi vai trò; không gán rồi gỡ thay thế.",error.status);throw error;}},
changeRole: async(userId,body)=>{try{return await request(`/api/admin/users/${userId}/role-change`,{method:"POST",body});}catch(error){if([404,405].includes(error.status))throw new ApiError("Chưa đổi được vai trò. Vui lòng thử lại sau.",error.status);throw error;}},
assignRole: (userId, roleId) => request(`/api/admin/users/${userId}/roles`, { method: "POST", body: { roleId } }),

// Thu hồi một vai trò khỏi người dùng (DELETE /api/admin/users/{userId}/roles/{roleId})
Expand Down
Loading
Loading