From ffb3673884769d2e14ec2ccd2019214b25a0f8ab Mon Sep 17 00:00:00 2001 From: Vector Date: Mon, 2 Nov 2026 11:58:23 +0700 Subject: [PATCH] fix(F40): dong bo Figma, het giat chuyen trang, doi SDT (L4), sua tai lieu T01/T22 --- DECISIONS.md | 2 +- .../ADMIN-FLOW-COVERAGE.md | 2 +- .../SafeSpace-Customer-UI/BACKEND-TODO.md | 14 +++--- .../SafeSpace-Customer-UI/BE-CONTRACT.md | 6 +-- .../CUSTOMER-FLOW-COVERAGE.md | 2 +- .../OPS-FLOW-COVERAGE.md | 18 +++++-- .../SafeSpace-Customer-UI/src/app/App.jsx | 17 ++++--- .../SafeSpace-Customer-UI/src/app/router.js | 9 +++- .../src/app/state/AppProvider.jsx | 7 ++- .../src/app/state/appReducer.js | 6 ++- .../src/features/admin/AdminRoutes.jsx | 3 +- .../features/admin/users/CreateUserPage.jsx | 48 +++++++++++-------- .../features/admin/users/UserDetailPage.jsx | 4 +- .../src/features/business/BusinessRoutes.jsx | 3 +- .../src/features/business/business.css | 5 +- .../customer/contracts/RenewalStatusPage.jsx | 2 +- .../customer/profile/CustomerProfilePage.jsx | 19 +++++--- .../FacilityOperationsRoutes.jsx | 3 ++ .../state/FacilityOperationsProvider.jsx | 8 +++- .../workflows/WorkflowComponents.jsx | 25 ++++++---- .../workflows/useWorkflowData.js | 9 ++-- .../manager/contracts/ContractListPage.jsx | 13 ++--- .../discrepancies/DiscrepancyListPage.jsx | 4 +- .../manager/refunds/DepositRefundPage.jsx | 5 +- .../staff/overdue/OverdueRemovalPage.jsx | 7 +-- .../src/shared/styles/motion.css | 10 ++-- .../src/shared/styles/ss.css | 7 +++ .../src/shared/styles/workflows.css | 11 +++-- .../src/shared/utils/roles.js | 13 +++++ .../tests/auth-support.browser.mjs | 8 ++-- .../tests/auth-support.spec.js | 18 +++---- .../tests/batch10-browser.spec.js | 4 +- progress.md | 22 +++++++++ 33 files changed, 224 insertions(+), 110 deletions(-) diff --git a/DECISIONS.md b/DECISIONS.md index 3b92508..a9c16ab 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -269,7 +269,7 @@ Bổ sung @playwright/test trong devDependencies để kiểm thao tác biểu m ## D32 — 2026-10-26: Khấu trừ tối đa bằng cọc, quá hạn theo cọc, sự cố cơ sở, không thu hồi mã — Đã chốt > Người dùng chốt ngày 26/10/2026 (kế hoạch hoàn thiện 26–31/10). Áp dụng cho **mọi hợp đồng**, kể cả hợp đồng đang chạy. -> Chưa triển khai code; việc BE/FE ghi ở `SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md` mục "D31". +> Chưa triển khai code; việc BE/FE ghi ở `SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md` mục "D32" (02/11/2026: sửa tham chiếu ghi nhầm "D31", không đổi nội dung quyết định). **Tiền khi trả kho và quá hạn** - Tổng khấu trừ khi trả kho (vệ sinh 10% cọc cố định, hư hỏng, quá hạn) tối đa bằng 100% cọc. Vượt cọc thì hoàn 0 đ và dừng ở đó; **không phát sinh công nợ ngoài cọc**, không tạo khoản phải thu khách sau trả kho. diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/ADMIN-FLOW-COVERAGE.md b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/ADMIN-FLOW-COVERAGE.md index 0493a3e..4b3e3f8 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/ADMIN-FLOW-COVERAGE.md +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/ADMIN-FLOW-COVERAGE.md @@ -10,7 +10,7 @@ tài khoản khác mở `#/admin` sẽ thấy "Không có quyền truy cập". T |---|---|---|---| | A01 Quản lý tài khoản | `#/admin` | `src/features/admin/users/UserListPage.jsx` | `GET dashboard/stats`, `GET users?page&pageSize&searchTerm&status&roleId`, `GET roles`, `GET users/{id}/facilities` (cột Cơ sở phụ trách) | | (thêm) Chi tiết tài khoản | `#/admin/users/:id` | `src/features/admin/users/UserDetailPage.jsx` | `GET/PUT users/{id}`, `POST users/{id}/reset-password`, `POST/DELETE users/{id}/roles`, `GET users/{id}/facilities`, `POST user-facilities`, `PUT user-facilities/{id}/status` | -| A02 Thêm & phân quyền tài khoản | `#/admin/new` | `src/features/admin/users/CreateUserPage.jsx` | `POST users` (+ `POST user-facilities` khi là Nhân viên / Quản lý) | +| A02 Thêm & phân quyền tài khoản | `#/admin/new` | `src/features/admin/users/CreateUserPage.jsx` | `POST users` (+ `POST user-facilities` khi là Nhân viên / Quản lý). Có ô **Tên đăng nhập** riêng (D33: bắt buộc, ≤ 50 ký tự, không khoảng trắng / @); vai trò chia 2 nhóm: Nhân viên / Quản lý cơ sở (cần chọn cơ sở) và Khách hàng / Vận hành KD / Quản trị; "Vận hành KD" chỉ hiện một lần (cập nhật 02/11/2026) | | A03 Cấu hình quyền truy cập | `#/admin/permissions` | `src/features/admin/permissions/PermissionListPage.jsx` | `GET roles`, `GET permissions`, `POST/DELETE roles/{id}/permissions` | | A04 Nhật ký hoạt động | `#/admin/logs` | `src/features/admin/logs/AuditLogPage.jsx` | `GET logs/login-history`, `GET logs/activity-logs` | | Thông báo / admin | (chuông) | `src/features/admin/AdminLayout.jsx` | `GET dashboard/stats`, `GET logs/login-history` | diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md index e1e9ab9..ff760bb 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BACKEND-TODO.md @@ -110,7 +110,7 @@ tên route + tên trường JSON là giao diện chạy ngay, không phải sử "scannedAt": "2026-10-16T03:32:00Z", "reason": null } { "result": "DENIED", "reason": "Mã đã hết hiệu lực — hợp đồng đã trả kho.", "unitNumber": "B-015", ... } ``` -`code` chỉ là mã tham chiếu (không chứa bí mật). Hết hiệu lực khi biên bản trả kho được lập (S04) hoặc hợp đồng kết thúc. (D31: hết hiệu lực ngay khi khách gửi yêu cầu trả kho thành công; không có thu hồi thủ công.) +`code` chỉ là mã tham chiếu (không chứa bí mật). Hết hiệu lực khi biên bản trả kho được lập (S04) hoặc hợp đồng kết thúc. (D32: hết hiệu lực ngay khi khách gửi yêu cầu trả kho thành công; không có thu hồi thủ công.) Hợp đồng quá hạn có khoá QR hay không: nhóm chốt (giao diện chỉ hiện `reason` backend trả về). ### R · Phản hồi hỗ trợ (Ngọc Mai) @@ -174,10 +174,10 @@ Bảng trong DB đã có sẵn (`HandoverRecord`, `ReturnInspection`, `UnitAssig |---|---|---|---| | M05 | `POST /api/ops/allocations/{id}` | `{ unitCode }` | Kho phải trống, đúng loại + diện tích → tạo `UnitAssignment`, `RentalContract`, lịch xác minh + `HandoverRecord`; kho → `RESERVED` | | M06 | `PUT /api/ops/assignments/{id}` | `{ staffId }` | Giao việc (bàn giao / trả kho / hỗ trợ) cho nhân viên cùng cơ sở | -| M03 | `POST /api/ops/renewals/{id}/approve` | — | `ContractRenewal` → APPROVED, cập nhật `EndDate` hợp đồng (**D31 thay: chưa đổi EndDate khi duyệt, xem T02**) | +| M03 | `POST /api/ops/renewals/{id}/approve` | — | `ContractRenewal` → APPROVED, cập nhật `EndDate` hợp đồng (**D32 thay: chưa đổi EndDate khi duyệt, xem T02**) | | M03 | `POST /api/ops/renewals/{id}/reject` | `{ reason }` | `reason` rỗng → 400; gửi lý do cho khách | | M07 | `POST /api/ops/contracts/{id}/reminders` | `{ note }` | Ghi lịch sử nhắc khách (`OverdueCase`) | -| M07 | `POST /api/ops/contracts/{id}/refund` | — | Chỉ sau biên bản trả kho. Hoàn cọc = cọc − khoản còn nợ; kho → `AVAILABLE`; hợp đồng đóng (**D31 thay: khấu trừ tối đa bằng cọc, REFUND `PENDING`, ô cần vệ sinh giữ `MAINTENANCE`, xem T06–T07**) | +| M07 | `POST /api/ops/contracts/{id}/refund` | — | Chỉ sau biên bản trả kho. Hoàn cọc = cọc − khoản còn nợ; kho → `AVAILABLE`; hợp đồng đóng (**D32 thay: khấu trừ tối đa bằng cọc, REFUND `PENDING`, ô cần vệ sinh giữ `MAINTENANCE`, xem T06–T07**) | | M01/M02/M04 | (trong `GET /api/ops/board`) | — | `units` (12 ô của cơ sở, D17), `revenue` 6 tháng + cơ cấu theo loại kho, tỷ lệ lấp đầy tính từ `units` | Luật nghiệp vụ chi tiết (điều kiện chặn, chuyển trạng thái) xem `src/features/facility-operations/state/facilityOperationsReducer.js` — có test `tests/ops.test.js`. @@ -199,7 +199,7 @@ Luật nghiệp vụ chi tiết (điều kiện chặn, chuyển trạng thái) | Thông báo (chuông) | `GET /api/notifications`, `POST /api/notifications/read` `{ ids? }` | Lưu trong trình duyệt | | Hồ sơ (C13) | `PUT /api/auth/profile` `{ fullName }`, `POST /api/auth/change-password`, `POST /api/auth/forgot-password` | Đổi tên lưu cục bộ; đổi / quên mật khẩu đang khoá | | Đăng nhập | D32: đã bổ sung code nhận **email hoặc username** qua `{username, password}`; giữ HTTP 401 hiện có cho sai thông tin | FE login đã xử lý riêng 401; còn kiểm chứng SQL Server của nhóm | -| Hỗ trợ (C12) | Cho gửi khi **chưa có hợp đồng** (`ContractId` không bắt buộc); nhận ảnh đính kèm (multipart, ≤3 ảnh, ≤5 MB). D31 giữ, xem T19 | Chưa có hợp đồng thì không gửi được; ảnh lưu cục bộ | +| Hỗ trợ (C12) | Cho gửi khi **chưa có hợp đồng** (`ContractId` không bắt buộc); nhận ảnh đính kèm (multipart, ≤3 ảnh, ≤5 MB). D32 giữ, xem T19 | Chưa có hợp đồng thì không gửi được; ảnh lưu cục bộ | ## C. Ưu tiên 3 — chỉnh nhỏ - [ ] JSON `DateTime` trả kèm `Z` (UTC); hiện đọc từ DB không có múi giờ, giao diện phải tự coi là UTC. @@ -389,8 +389,8 @@ Nguồn: DECISIONS.md D27. Các việc backend cần làm: - Hủy trước StartDate: `cancellationFee` = 10% `requiredDeposit` (không phải 10% tiền thuê như H1 cũ). `refundAmount` = tiền thuê đã thu + 90% cọc. - Dừng sau StartDate (Move-out): hoàn 70% cọc, giữ 30%. Tiền thuê hoàn theo phương án B: tháng đang dùng tính đủ; các tháng nguyên vẹn chưa bắt đầu được hoàn. - Trả kho sạch, đúng hạn: hoàn 100% cọc. Vi phạm vệ sinh cơ bản: trừ 10% cọc cố định. -- Hư hỏng vật lý hoặc quá hạn: trừ `DamageFee` và `OverdueFee` vào phần cọc còn lại; vượt cọc thì hoàn 0 đ và ghi công nợ. (**D31 thay: không ghi công nợ, tổng khấu trừ tối đa bằng cọc.**) -- Quá hạn: đọc tham số `OVERDUE` từ cấu hình B02, không hard-code. (D31: 5% cọc ban đầu mỗi ngày, tối đa 100% cọc, xem T09.) +- Hư hỏng vật lý hoặc quá hạn: trừ `DamageFee` và `OverdueFee` vào phần cọc còn lại; vượt cọc thì hoàn 0 đ và ghi công nợ. (**D32 thay: không ghi công nợ, tổng khấu trừ tối đa bằng cọc.**) +- Quá hạn: đọc tham số `OVERDUE` từ cấu hình B02, không hard-code. (D32: 5% cọc ban đầu mỗi ngày, tối đa 100% cọc, xem T09.) - Ghi trạng thái hoàn khi Quản lý xác nhận ở M07; chuyển khoản thủ công. - Đồng bộ FE: appReducer.js `CANCEL_FEE_RATE` và màn C14a phải theo công thức trên. @@ -427,7 +427,7 @@ theo loại kho + diện tích (D17: cỡ M 15 m², cỡ L 30 m²) và từ ch ## Phí phát sinh khi trả kho và công nợ (F40: S04, S09f, C11f) -> **D31 (26/10/2026):** không còn công nợ sau trả kho. Chỉ giữ việc lưu phí ở biên bản (T05) và trừ trong phạm vi cọc (T06). Các mục thanh toán phí qua PayOS, trả tại quầy và `feeCollections` bên dưới **không làm**. +> **D32 (26/10/2026):** không còn công nợ sau trả kho. Chỉ giữ việc lưu phí ở biên bản (T05) và trừ trong phạm vi cọc (T06). Các mục thanh toán phí qua PayOS, trả tại quầy và `feeCollections` bên dưới **không làm**. Giao diện đã làm theo Figma; backend cần bổ sung: diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BE-CONTRACT.md b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BE-CONTRACT.md index 3e9a01b..7ed2b84 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BE-CONTRACT.md +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/BE-CONTRACT.md @@ -121,11 +121,11 @@ Hình dạng dữ liệu giao diện đang dùng nằm ở `src/features/facilit - AccessQrDto có validFrom, backupCode là PIN6; POST /api/access/scan nhận thêm unitNumber (bắt buộc khi dùng PIN). ContractDetailDto có accessUpdatedAt để tạo thông báo cấp lại mã. - PayOS thành công tự phân bổ/cấp hợp đồng, không còn yêu cầu bàn giao. Xem đầy đủ tại docs/figma-ui-sync-2026-10-22.md. -## Đồng bộ 26/10 — D31 +## Đồng bộ 26/10 — D32 (trước đây ghi nhầm D31, sửa 02/11/2026) -Nguồn `DECISIONS.md` D31; danh sách việc và người làm ở `BACKEND-TODO.md` mục "D31". Những điểm hợp đồng API thay đổi: +Nguồn `DECISIONS.md` D32 (dòng A01 theo D31 — đăng nhập email/username); danh sách việc và người làm ở `BACKEND-TODO.md` mục "D32". Những điểm hợp đồng API thay đổi: -| Màn | Endpoint | Thay đổi theo D31 | +| Màn | Endpoint | Thay đổi theo D32 | |---|---|---| | A01 | `POST /api/auth/login` | Nhận email **hoặc** username trong cùng ô (`identifier` hoặc `username`) | | C03b, C04 | `GET /api/rental-policy`, `GET /api/rental-policy/versions/{version}` | Bản chính sách hiện hành (công khai) và bản theo phiên bản; đơn lưu `policyVersion`, `acceptedAt`, `channel` khi khách đồng ý | diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/CUSTOMER-FLOW-COVERAGE.md b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/CUSTOMER-FLOW-COVERAGE.md index 8978e68..73de004 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/CUSTOMER-FLOW-COVERAGE.md +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/CUSTOMER-FLOW-COVERAGE.md @@ -32,7 +32,7 @@ Nguồn: file Figma "SafeSpace - Modern UI" (section Khách hàng + Trang chủ | C11 / C11b Thanh toán & lịch hẹn | `#/payments` | `src/features/customer/payments/PaymentListPage.jsx` | Thẻ lịch hẹn + bảng khoản thu; khoản gia hạn đã duyệt có nút "Thanh toán" → C11q (`src/shared/components/PayosModal.jsx`, `POST /api/payments/{id}/payos`); trả xong hiện thông báo C11b | | C12 Hỗ trợ | `#/support` | `src/features/customer/support/SupportPage.jsx` | Danh sách yêu cầu, trích đoạn phản hồi và Cập nhật yêu cầu; giữ 8 nhóm, tiêu đề Khác, cấp lại QR/PIN/chìa khóa. Ảnh chỉ giữ tên cục bộ, chưa upload máy chủ. | | C12b Tiến trình hỗ trợ | `#/support/:id` | `src/features/customer/support/SupportTicketDetailPage.jsx` | Nội dung, nhân viên, lịch sử responses, mốc thời gian từ API, báo lỗi và tải lại; không dựng dữ liệu còn thiếu | -| C13, C13a–d, toast | `#/profile` | `src/features/customer/profile/CustomerProfilePage.jsx` | Chỉ sửa tên; email / SĐT chỉ đọc (SĐT che bớt); hộp thoại "Đã hiểu" | +| C13, C13a–d, toast | `#/profile` | `src/features/customer/profile/CustomerProfilePage.jsx` | Sửa tên hiển thị và **số điện thoại** (`PUT /api/auth/profile` gửi `fullName`, `phone`; kiểm định dạng 0xxxxxxxxx / +84), nút "Lưu thông tin" theo Figma; tên đăng nhập và email chỉ đọc; hộp thoại "Đã hiểu" (cập nhật 02/11/2026, L4) | | C14 / C14a / C14b Đơn đặt chỗ | `#/reservations`, `#/reservations/:id` | `src/features/customer/reservations/ReservationListPage.jsx`, `src/features/customer/payments/CheckoutPage.jsx` | Nút "Huỷ đơn" (đơn chưa nhận kho) → hộp thoại C14a: đã trả, phí huỷ, số tiền hoàn (`cancel-preview`); huỷ xong "Đã huỷ · Đang hoàn tiền" | | Popup thông báo (public / customer, đã đọc) | (header) | `src/shared/components/Header.jsx` | | diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/OPS-FLOW-COVERAGE.md b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/OPS-FLOW-COVERAGE.md index 620d1ad..d94bbee 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/OPS-FLOW-COVERAGE.md +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/OPS-FLOW-COVERAGE.md @@ -10,11 +10,15 @@ Dữ liệu: `src/features/facility-operations/data/facilityOperationsSeed.js` ( | S01 Công việc trong ngày | `#/staff` | 3 số liệu (có "Chờ thu tiền tại kho") + thẻ việc dạng **lưới 3x3** (9 thẻ / trang, phân trang); không có việc → S01-trống | | S09a / S02a / S03a / S04a / S05a | `#/staff/reconcile` … `#/staff/support` (không có `?id`) | Mỗi tab là lưới 3x3 thẻ việc của tab đó; bấm thẻ mở màn xử lý; không có việc → thông báo trống (S09a-trống) | | S09 Thu tiền tại kho | `#/staff/reconcile?id=` (có `?id`) | Đơn khách chọn "Thanh toán tại cửa hàng": số tiền, giữ chỗ đến, gồm thuê + cọc; "Xác nhận đã thu" (`POST /api/ops/payments/{id}/confirm`) / "Để sau". Đơn trả PayOS không vào đây | -| S02 Xác minh khách hàng | `#/staff/verify?id=` | Loại + số giấy tờ (chỉ giữ 4 số cuối), 2 ô đối chiếu; xong chuyển sang bàn giao | -| S03 Bàn giao kho | `#/staff/handover?id=` | Thẻ từ / Mã PIN / Vân tay; chặn khi chưa xác minh; kho → Đang hoạt động | +| S02 Xác minh khách hàng | `#/staff/verify?id=` | Checklist 4 mục đối chiếu (D30-14), **không nhập lại số giấy tờ**; xong mở bước nhận chìa khóa (cập nhật 02/11/2026) | +| S03 Nhận chìa khóa vật lý | `#/staff/handover?id=` (`#/staff/keys?id=` cùng màn) | Chặn khi chưa xác minh; 3 ô xác nhận rồi ghi nhận đã giao chìa khóa. **Không** còn thẻ từ / vân tay và **không** phải bước kích hoạt: hợp đồng, QR/PIN cấp tự động sau thanh toán (D26) | | S04 Kiểm tra trả kho | `#/staff/return?id=` | 4 mục biên bản, gửi quản lý; kho → Chờ kiểm tra | | S05 Xử lý hỗ trợ | `#/staff/support?id=` | Ghi nhận xử lý + trạng thái tiếp theo | | S06 Đã ghi nhận | `#/staff/done?kind=` | Màn kết quả theo từng thao tác | +| Thu gia hạn tại quầy | `#/staff/renewal-payments` | Khoản `RENEWAL` khách chọn trả tại quầy; xác nhận đã thu | +| Báo sai lệch thanh toán | `#/staff/mismatch` | Nhân viên báo số thu thực tế khác hệ thống, gửi quản lý đối soát | +| D30-11 Xử lý đồ quá hạn ngày 20 | `#/staff/overdue` | Lập biên bản + ảnh sau khi đã thực hiện; rỗng → "Không có kho quá hạn đến ngày 20" | +| Hỗ trợ chưa có hợp đồng | `#/staff/inquiries` | Trả lời tư vấn khách chưa thuê kho (chờ BE `/api/support/inquiries`, T19) | ## Quản lý cơ sở (`#/manager`) @@ -24,10 +28,16 @@ Dữ liệu: `src/features/facility-operations/data/facilityOperationsSeed.js` ( | M02 / M02a Danh sách kho | `#/manager/units?tab=` | Lọc theo trạng thái (thêm "Bảo trì"), tìm mã kho / khách, phân trang 12; cột "Thao tác": "Đổi trạng thái" → hộp thoại M02a (Trống ↔ Bảo trì, Chờ kiểm tra → Trống / Bảo trì, bắt buộc lý do) — `PUT /api/ops/units/{code}/status` (F12) | | M05 Phân bổ kho | `#/manager/allocate?id=` | Chỉ hiện kho trống đúng loại + diện tích; phân bổ xong tạo lịch xác minh & bàn giao cho nhân viên | | M06 Phân công | `#/manager/assign` | Giao việc cho nhân viên (ca làm, số việc đang nhận) | -| M03 Gia hạn | `#/manager/renewals` | Duyệt (cập nhật ngày hết hạn) / Từ chối (bắt buộc lý do) | -| M07 Hợp đồng & quá hạn | `#/manager/contracts?id=` | Ghi nhận đã nhắc khách; xác nhận hoàn cọc sau biên bản trả kho | +| M03 Gia hạn | `#/manager/renewals` | Duyệt = chốt giá, tạo khoản `RENEWAL` chờ thanh toán 24 giờ, **chưa đổi ngày hết hạn** (D32); Từ chối bắt buộc lý do. Khối "Chốt giá khi duyệt" (D30-17) còn chờ BE trả số tiền (L8) | +| M07 Hợp đồng & quá hạn | `#/manager/contracts?id=` | Ghi nhận đã nhắc khách; chốt số hoàn sau biên bản trả kho → khoản hoàn `PENDING` (D32), chuyển tiền ở màn Hoàn cọc | | M04 Báo cáo doanh thu | `#/manager/report` | Biểu đồ 6 tháng, cơ cấu theo loại kho, tỷ lệ lấp đầy; xuất CSV | | M08 Cập nhật thành công | `#/manager/done?kind=` | | +| Hoàn cọc sau trả kho (D30-09) | `#/manager/deposit-refunds` | Duyệt đối soát và ghi nhận chuyển khoản là hai bước; `PENDING` → `PAID`; rỗng → "Không có đối soát chờ duyệt" | +| M08 Hoàn tiền đơn huỷ | `#/manager/refunds` | Ghi mã giao dịch, chỉ một lần (D27) | +| Báo cáo sai lệch | `#/manager/discrepancies`, `#/manager/discrepancy-detail?id=` | Danh sách báo cáo của nhân viên, trạng thái rỗng / lỗi tải theo Figma | +| Hồ sơ quá hạn | `#/manager/overdue` | Nhắc khách ngày 10–14, phân công xử lý ngày 20 (chờ BE `overdue-cases`, T12) | +| Sự cố cơ sở | `#/manager/incidents` | Lối vào từ M07 → "Sự cố cơ sở"; phương án chuyển ô / kết thúc (T13) | +| Phản hồi / kiểm khắc phục hư hỏng | `#/manager/damage-responses`, `#/manager/damage-inspections` | D30-18; chờ BE damage-cases (T23) | ## Chỗ Figma tự mâu thuẫn, code chọn như sau - Figma dùng ngày cố định (14/09, 20/09) → code tính theo ngày hiện tại để lịch hẹn luôn ở tương lai. diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx index f3db9d3..e635d5c 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx @@ -161,7 +161,7 @@ function Shell() { const businessBody = mode !== "api" ? (
) : authed && !businessAllowed ? ( -
Về trang của tôi
+
Về tổng quan
) : null; const adminBody = @@ -173,8 +173,8 @@ function Shell() { ) : authed && !isAdmin ? (
- - Về trang của tôi + + Về tổng quan
) : null; @@ -184,7 +184,10 @@ function Shell() { { e.preventDefault(); document.getElementById("main")?.focus(); }}>Chuyển đến nội dung {!(isAdminPage && !adminBody && authed) && !(isOpsPage && authed && opsAllowed) && !(isBusinessPage && !businessBody && authed) &&
} {(WORKFLOW_DEMO || mode === "local") &&

MÔ PHỎNG FE · Dữ liệu thử nghiệm, không thanh toán / chuyển tiền thật.

} -
+ {/* 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. */} +
{needsLogin ? null : loadError && !ready ? (
@@ -202,13 +205,13 @@ function Shell() { businessBody || ) : isOpsPage ? ( opsAllowed ? ( - + ) : (
- - Về trang của tôi + + Về tổng quan
) diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/router.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/router.js index 2689639..8327be8 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/router.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/router.js @@ -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); diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/AppProvider.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/AppProvider.jsx index a3c9794..f100c0c 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/AppProvider.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/AppProvider.jsx @@ -705,9 +705,12 @@ function ApiProvider({ children }) { case "UPDATE_NAME": { const current = refs.current.session; if (!current) return fail("Vui lòng đăng nhập lại."); - const profile = await api.updateProfile({ fullName: String(p.name || "").trim() }); + const body = { fullName: String(p.name || "").trim() }; + // Backend: Phone = null thì giữ nguyên số cũ, chuỗi rỗng thì xoá số + if (p.phone !== undefined) body.phone = String(p.phone || "").replace(/[\s.-]/g, ""); + const profile = await api.updateProfile(body); if (!applyProfile(profile, current)) return fail("Phiên đăng nhập đã thay đổi. Vui lòng thử lại."); - return { ok: true, name: profile.fullName }; + return { ok: true, name: profile.fullName, phone: profile.phone ?? body.phone }; } case "REQUEST_RETURN": { const c = d.contracts.find((x) => x.contract_id === p.contract_id); diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/appReducer.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/appReducer.js index 480b87d..40cad4d 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/appReducer.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/state/appReducer.js @@ -417,11 +417,15 @@ const handlers = { }; }, + // C13: lưu tên hiển thị và (nếu gửi kèm) số điện thoại UPDATE_NAME(state, p) { const name = (p.name || "").trim(); if (name.length < 2) fail("Vui lòng nhập tên hiển thị."); if (name.length > 100) fail("Tên không quá 100 ký tự."); - return { state: { ...state, user: { ...state.user, full_name: name } }, result: { name } }; + if (p.phone === undefined) return { state: { ...state, user: { ...state.user, full_name: name } }, result: { name } }; + const phone = String(p.phone || "").replace(/[\s.-]/g, ""); + if (phone && !/^(0\d{9}|\+84\d{9})$/.test(phone)) fail("Số điện thoại chưa đúng định dạng."); + return { state: { ...state, user: { ...state.user, full_name: name, phone } }, result: { name, phone } }; }, CHANGE_PASSWORD(state, p) { diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/AdminRoutes.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/AdminRoutes.jsx index a5f94a7..1ea49fa 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/AdminRoutes.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/AdminRoutes.jsx @@ -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 {body}; + // 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 {body}; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/users/CreateUserPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/users/CreateUserPage.jsx index 605af25..1d59708 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/users/CreateUserPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/users/CreateUserPage.jsx @@ -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"; @@ -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); @@ -170,9 +170,9 @@ export default function CreateUserPage() { // Nhưng nếu đã nhập thì phải đúng định dạng. if (form.phone && !isPhone(form.phone)) e.phone = "Số điện thoại chưa đúng định dạng."; - // Username phải dài 3-50 ký tự. - // Chỉ được chứa chữ cái, số, dấu chấm, _, @ và -. - if (!/^[a-zA-Z0-9._@-]{3,50}$/.test(form.username)) e.username = "Tên đăng nhập 3–50 ký tự: chữ, số, dấu . _ - @"; + // Username phải dài 3-50 ký tự (D33: không khoảng trắng, không @ để không nhầm với email). + // Chỉ được chứa chữ cái, số, dấu chấm, _ và -. + if (!/^[a-zA-Z0-9._-]{3,50}$/.test(form.username)) e.username = "Tên đăng nhập 3–50 ký tự: chữ, số, dấu . _ - (không có @ hoặc khoảng trắng)"; // Mật khẩu tạm thời tối thiểu 8 ký tự. if (form.password.length < 8) e.password = "Mật khẩu tạm thời cần ít nhất 8 ký tự."; @@ -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. */}
Vai trò -
- - {/* 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. */} +
+
+ Theo cơ sở · cần chọn cơ sở phụ trách +
{roles.filter((r) => FACILITY_ROLES.includes(r.roleName)).map((r) => ( - ))} - - {/* Trong lúc API tải vai trò, hiển thị thông báo. */} + ))}
+
+
+ Không gắn cơ sở +
{roles.filter((r) => !FACILITY_ROLES.includes(r.roleName)).map((r) => ( + + ))}
+
{meta.loading && Đang tải vai trò…}
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/users/UserDetailPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/users/UserDetailPage.jsx index 57e3f32..fd80c62 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/users/UserDetailPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/admin/users/UserDetailPage.jsx @@ -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"; @@ -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, }; diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/BusinessRoutes.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/BusinessRoutes.jsx index dafd42c..b3997de 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/BusinessRoutes.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/BusinessRoutes.jsx @@ -44,5 +44,6 @@ export default function BusinessRoutes({ parts, query }) {
); } - return {body}; + // 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 {body}; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/business.css b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/business.css index 4d089f8..d7d6123 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/business.css +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/business.css @@ -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%; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/contracts/RenewalStatusPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/contracts/RenewalStatusPage.jsx index f813fd3..5f22fe3 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/contracts/RenewalStatusPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/contracts/RenewalStatusPage.jsx @@ -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
{error && {error}} - {rows.map(r => Thanh toán PayOS}> + {rows.map(r => {!r.at_counter && Thanh toán PayOS}}> {expiredOf(r) && 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ũ.}{r.reason && Lý do từ chối: {r.reason}}{r.at_counter && !paidOf(r) && !expiredOf(r) && Đang chờ nhân viên thu tiền tại quầy. Kỳ thuê hiện tại chưa thay đổi.} )}{!rows.length && }Về hợp đồng
; diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/profile/CustomerProfilePage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/profile/CustomerProfilePage.jsx index e4ab9b1..8e9716e 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/profile/CustomerProfilePage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/profile/CustomerProfilePage.jsx @@ -1,7 +1,7 @@ import React, { useEffect, useRef, useState } from "react"; import { Button, Dialog, Field, PageHeader } from "../../../shared/components/UI.jsx"; import { go } from "../../../app/router.js"; -import { maskPhone } from "../../../shared/utils/format.js"; +import { isPhone } from "../../../shared/utils/format.js"; import { useApp } from "../../../app/state/AppProvider.jsx"; export default function CustomerProfilePage() { @@ -9,6 +9,8 @@ export default function CustomerProfilePage() { const { user } = data; const [name, setName] = useState(user.full_name); const [nameError, setNameError] = useState(""); + const [phone, setPhone] = useState(user.phone || ""); + const [phoneError, setPhoneError] = useState(""); const [pw, setPw] = useState({ current: "", next: "", confirm: "" }); const [pwErrors, setPwErrors] = useState({}); const [dialog, setDialog] = useState(null); @@ -17,20 +19,25 @@ export default function CustomerProfilePage() { const namePending = useRef(false); const passwordPending = useRef(false); useEffect(() => setName(user.full_name), [user.user_id, user.full_name]); + useEffect(() => setPhone(user.phone || ""), [user.user_id, user.phone]); const saveName = async (e) => { e.preventDefault(); if (namePending.current) return; const fullName = name.trim(); if (fullName.length < 2 || fullName.length > 100) return setNameError("Tên hiển thị cần từ 2 đến 100 ký tự."); + const phoneValue = phone.trim(); + if (phoneValue && !isPhone(phoneValue)) return setPhoneError("Số điện thoại chưa đúng định dạng (VD: 0901234567)."); namePending.current = true; setSavingName(true); setNameError(""); + setPhoneError(""); try { - const res = await dispatch("UPDATE_NAME", { name: fullName }); + const res = await dispatch("UPDATE_NAME", { name: fullName, phone: phoneValue }); if (!res.ok) return setNameError(res.error); setName(res.name); - setDialog({ title: "Đã lưu tên", message: "Tên hiển thị của bạn đã được cập nhật." }); + if (res.phone !== undefined) setPhone(res.phone || ""); + setDialog({ title: "Đã lưu thông tin", message: "Tên hiển thị và số điện thoại của bạn đã được cập nhật." }); } finally { namePending.current = false; setSavingName(false); @@ -88,12 +95,12 @@ export default function CustomerProfilePage() { - - + + { setPhone(e.target.value); setPhoneError(""); }} />

Thông báo

Nhận nhắc lịch hẹn, hạn hợp đồng và cập nhật thanh toán trong ứng dụng.

- +
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/FacilityOperationsRoutes.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/FacilityOperationsRoutes.jsx index 57fed25..f5e2604 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/FacilityOperationsRoutes.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/FacilityOperationsRoutes.jsx @@ -80,6 +80,8 @@ export default function FacilityOperationsRoutes({ role, parts, query }) { const [Page, active] = hit || [null, ""]; return ( + {/* key theo đường dẫn: nội dung trang dựng lại khi đổi trang, header/menu/dữ liệu giữ nguyên */} + {Page ? ( staff && LIST_KIND[parts[0]] ? : ) : ( @@ -89,6 +91,7 @@ export default function FacilityOperationsRoutes({ role, parts, query }) { )} + ); } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/FacilityOperationsProvider.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/FacilityOperationsProvider.jsx index 89bcf6a..3c64037 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/FacilityOperationsProvider.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/state/FacilityOperationsProvider.jsx @@ -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())); @@ -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]); diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/WorkflowComponents.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/WorkflowComponents.jsx index 3b131cc..8e4ec61 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/WorkflowComponents.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/WorkflowComponents.jsx @@ -2,24 +2,33 @@ import ConfirmDialog from "../../../shared/components/ConfirmDialog.jsx"; import React, { useRef, useState } from "react"; import { Button, Empty, Modal, Notice, Tag } from "../../../shared/components/UI.jsx"; -export function WorkflowState({ load, children }) { +// errorView: chữ trạng thái lỗi tải theo Figma của từng màn ({ title, text, label }); 403 khi tải = dữ liệu ngoài cơ sở phụ trách (Figma QUYEN02) +export function WorkflowState({ load, children, errorView }) { return <>{load.demo && Chế độ mô phỏng FE · Dữ liệu lưu trong trình duyệt, không phải giao dịch thật.} {load.needsRefresh&&Chưa xác minh kết quả. Tải lại trước khi gửi tiếp; không chuyển tiền lần nữa.} - {load.loading ?

Đang tải dữ liệu…

: load.error ? {load.error} : null} + {load.loading ?

Đang tải dữ liệu…

: load.error ? ( + load.errorStatus === 403 ? + : errorView ? + : {load.error} + ) : null} {!load.loading && !load.error && children} ; } export function InfoTiles({ items }) { return
{items.map(([label, value]) =>
{label}
{value ?? "—"}
)}
; } export function RecordCard({ title, subtitle, status, children, actions }) { return

{title}

{subtitle &&

{subtitle}

}{children}
{status && {status}}{actions}
; } -export function WorkflowEmpty({ text = "Chưa có hồ sơ trong danh sách này." }) { return ; } +export function WorkflowEmpty({ title = "Chưa có dữ liệu", text = "Chưa có hồ sơ trong danh sách này.", children }) { return {children}; } -export function WorkflowConfirm({ title, summary, busy, error, onConfirm, onClose }) { - return ; +export function WorkflowConfirm({ title, summary, busy, error, forbidden, failTitle, confirmLabel, onConfirm, onClose, onReload }) { + // Figma QUYEN04: quyền / phân công vừa đổi → không thử lại, chỉ tải lại dữ liệu + if (error && forbidden) return ; + return ; } export function useWorkflowChange(load) { - const [pending, setPending] = useState(null), [result, setResult] = useState(null), [error, setError] = useState(""); + const [pending, setPending] = useState(null), [result, setResult] = useState(null), [error, setError] = useState(""), [forbidden, setForbidden] = useState(false); const guard=useRef(false); - const ask = (action, payload, title, summary) => { setError(""); setPending({ action, payload, title, summary }); }; - const dialog = pending ? setPending(null)} onConfirm={async () => { if(guard.current)return;guard.current=true;let out;try{out=await load.run(pending.action, pending.payload);}finally{guard.current=false;} if (out.ok) { setPending(null); setResult("Đã lưu kết quả"); } else setError(out.error); }} /> : result ? setResult(null)} onConfirm={()=>setResult(null)}/> : null; + // opts (chữ theo Figma từng màn): { successTitle, failTitle, confirmLabel, doneLabel, onDone } + const ask = (action, payload, title, summary, opts = {}) => { setError(""); setForbidden(false); setPending({ action, payload, title, summary, opts }); }; + const closeResult = () => { const done = result?.onDone; setResult(null); done?.(); }; + const dialog = pending ? setPending(null)} onReload={() => { setPending(null); load.reload(); }} onConfirm={async () => { if(guard.current)return;guard.current=true;let out;try{out=await load.run(pending.action, pending.payload);}finally{guard.current=false;} if (out.ok) { setPending(null); setResult({ title: pending.opts.successTitle || "Đã lưu kết quả", label: pending.opts.doneLabel || "Về hồ sơ", onDone: pending.opts.onDone }); } else { setForbidden(out.code === "FORBIDDEN"); setError(out.error); } }} /> : result ? : null; return [dialog, ask]; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/useWorkflowData.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/useWorkflowData.js index f65018f..ea09db7 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/useWorkflowData.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/useWorkflowData.js @@ -25,13 +25,14 @@ export function useWorkflowData(resource) { const [data, setData] = useState(() => demo ? readDemo()[storageResource] : resource === "policy" ? null : []); const [loading, setLoading] = useState(!demo); const [error, setError] = useState(""); + const [errorStatus, setErrorStatus] = useState(0); const [busy, setBusy] = useState(false); const guard = useRef(false), generation = useRef(0); const reload = useCallback(async () => { const seq = ++generation.current; - setLoading(true); setError(""); + setLoading(true); setError(""); setErrorStatus(0); try { const result = demo ? readDemo()[storageResource] : await loadWorkflow(resource); if(["depositRefunds","overdue"].includes(resource)&&!Array.isArray(result))throw new Error("Máy chủ chưa trả danh sách hợp lệ."); if (seq === generation.current) {setData(result);setNeedsRefresh(false);} } - catch (e) { if (seq === generation.current) setError(e.message); onApiError?.(e); } + catch (e) { if (seq === generation.current) { setError(e.message); setErrorStatus(e?.status || 0); } onApiError?.(e); } finally { if (seq === generation.current) setLoading(false); } }, [demo, resource, storageResource, onApiError, actorKey]); useEffect(() => { reload(); return () => { generation.current++; }; }, [reload]); @@ -71,9 +72,9 @@ export function useWorkflowData(resource) { else await reload(); } return { ok: true }; - } catch (e) { if(e.uncertain||e.status===0||e.status===409||e.status>=500)setNeedsRefresh(true); onApiError?.(e); return { ok: false, error: e.message }; } + } catch (e) { if(e.uncertain||e.status===0||e.status===409||e.status>=500)setNeedsRefresh(true); onApiError?.(e); return e?.status === 403 ? { ok: false, code: "FORBIDDEN", error: "Quyền tài khoản hoặc trạng thái phân công vừa thay đổi. Tải lại dữ liệu và kiểm tra quyền hiện tại trước khi tiếp tục." } : { ok: false, error: e.message }; } finally { guard.current = false; setBusy(false); } }, [demo, resource, storageResource, user, roles, onApiError, reload, needsRefresh, facilityId, data, actorKey]); const scoped = ["depositRefunds","overdue"].includes(resource) ? (data||[]).filter(r=>facilityId!=null&&r.facilityId===facilityId) : data; - return { data:scoped, loading, error, busy, reload, run, demo,needsRefresh }; + return { data:scoped, loading, error, errorStatus, busy, reload, run, demo,needsRefresh }; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/contracts/ContractListPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/contracts/ContractListPage.jsx index 9cffd4d..8a27746 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/contracts/ContractListPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/contracts/ContractListPage.jsx @@ -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"; @@ -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 (
@@ -42,9 +45,8 @@ export function ContractListPage({ query }) { ))}
{ops.contracts.map(c=>{const [label,tone]=CONTRACT_STATE(c);return {c.state==="RETURNED"?"Duyệt đối soát":c.state==="OVERDUE"?"Xem hồ sơ quá hạn":"Xem hồ sơ"}}>

{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"}

;})}
{query.get("id")&&!sel&&} -
Hoàn tiền đơn huỷHoàn cọc sau trả kho
{sel && ( -
+

{sel.id} · Bước tiếp theo

{sel.state === "RETURNED" ? ( <> @@ -84,9 +86,6 @@ export function ContractListPage({ query }) { }} /> )} - Hoàn cọc sau trả kho - {/* Figma M07: lối vào M08 hoàn tiền đơn huỷ */} - Hoàn tiền đơn huỷ{(ops.refunds || []).some((r) => r.status === "PENDING") ? ` (${ops.refunds.filter((r) => r.status === "PENDING").length})` : ""} {(sel.reminders || []).length > 0 && (
    {sel.reminders.map((r, i) =>
  • {dateTimeLabel(r.at)}{r.text}
  • )} @@ -94,6 +93,8 @@ export function ContractListPage({ query }) { )}
)} + {/* Figma M07: lối vào M08 hoàn tiền đơn huỷ và hoàn cọc, một thẻ cuối trang */} +
Hoàn tiền đơn huỷ{(ops.refunds || []).some((r) => r.status === "PENDING") ? ` (${ops.refunds.filter((r) => r.status === "PENDING").length})` : ""}Hoàn cọc sau trả kho
); } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/discrepancies/DiscrepancyListPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/discrepancies/DiscrepancyListPage.jsx index 0956fb7..bcb156e 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/discrepancies/DiscrepancyListPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/discrepancies/DiscrepancyListPage.jsx @@ -8,7 +8,7 @@ export function DiscrepancyListPage() { const load = useWorkflowData("discrepancies"), [status, setStatus] = useState(""); const rows = (load.data || []).filter(x => !status || x.status === status); return
- - {rows.map(r => Xem báo cáo}>

Hệ thống: {money(r.expected)} · Thực nhận: {money(r.actual)}

{r.note}

)}{!rows.length && !load.error && }
+ + {rows.map(r => {r.status === "PENDING" ? "Xem báo cáo" : "Mở chi tiết đối soát"}}>

Hệ thống: {money(r.expected)} · Thực nhận: {money(r.actual)}

{r.note}

)}{!rows.length && !load.error && }
; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/DepositRefundPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/DepositRefundPage.jsx index bc0dc8b..cc95196 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/DepositRefundPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/DepositRefundPage.jsx @@ -8,15 +8,16 @@ import { SettlementSummary } from "../../facility-operations/settlements/Settlem import { amountLabel,timeLabel } from "../../facility-operations/damage/DamageComponents.jsx"; import { vnDateTimeInput } from "../../facility-operations/damage/damageModel.js"; import "../../../shared/styles/customer-detail.css"; +import { go } from "../../../app/router.js"; function TransferForm({item,load,ask}) { const [ref,setRef]=useState(""),[at,setAt]=useState(""),[confirmed,setConfirmed]=useState(false),[error,setError]=useState(""); const payload={id:item.id,transactionRef:ref,transferredAt:at,confirmed,expectedVersion:item.version},disabled=load.busy||load.needsRefresh; let valid=false;try{transferProof(item,payload);valid=true;}catch{} - return {e.preventDefault();if(disabled)return;try{transferProof(item,payload);setError("");ask("CONFIRM_DEPOSIT_REFUND",payload,"Ghi nhận đã chuyển tiền?",`Chỉ ghi nhận sau khi đã chuyển ${amountLabel(item.amount)} vào đúng tài khoản. Thao tác không thực hiện chuyển tiền.`);}catch(error){setError(error.message);}}} noValidate>

Ghi nhận chuyển khoản

Hạn hoàn: 3–5 ngày làm việc từ khi chốt đối soát. Chuyển đúng số tiền vào tài khoản chính chủ rồi ghi nhận.
setRef(e.target.value)}/>setAt(e.target.value)}/>
{error&&{error}}

Thiếu tài khoản chính chủ, thời gian, mã giao dịch hoặc xác nhận thì không được ghi nhận.

Xem biên bản & ảnh
; + return
{e.preventDefault();if(disabled)return;try{transferProof(item,payload);setError("");ask("CONFIRM_DEPOSIT_REFUND",payload,`Ghi nhận đã chuyển ${amountLabel(item.amount)}?`,`Chỉ ghi nhận sau khi đã chuyển ${amountLabel(item.amount)} vào đúng tài khoản. Thao tác không thực hiện chuyển tiền.`,{confirmLabel:"Xác nhận đã chuyển",successTitle:`Đã hoàn cọc ${amountLabel(item.amount)}`,failTitle:"Chưa ghi nhận được chuyển khoản",doneLabel:"Về hợp đồng & quá hạn",onDone:()=>go("manager/contracts")});}catch(error){setError(error.message);}}} noValidate>

Ghi nhận chuyển khoản

Hạn hoàn: 3–5 ngày làm việc từ khi chốt đối soát. Chuyển đúng số tiền vào tài khoản chính chủ rồi ghi nhận.
setRef(e.target.value)}/>setAt(e.target.value)}/>
{error&&{error}}

Thiếu tài khoản chính chủ, thời gian, mã giao dịch hoặc xác nhận thì không được ghi nhận.

Xem biên bản & ảnh
; } export function DepositRefundPage({query=new URLSearchParams()}) { const base=useWorkflowData("depositRefunds"),{ops,source,run,saving,needsRefresh}=useOps(),[selected,setSelected]=useState(query.get("id")||""); const load=source==="local"?{...base,data:ops.deposit_refunds||[],loading:false,error:"",busy:saving,needsRefresh,demo:true,run:(action,payload)=>run(action,payload)}:base; const [dialog,ask]=useWorkflowChange(load),item=load.data?.find(r=>r.id===selected); - return

SafeSpace / Quản lý cơ sở / Hợp đồng & quá hạn

{!selected?
{(load.data||[]).map(r=>

{r.customer} · Kho {r.unit}

{r.contractId} · {amountLabel(r.amount)}

{r.status==="PAID"?"Đã hoàn":r.status==="PENDING"?"Chờ hoàn":r.status==="NO_REFUND"?"Không còn khoản hoàn":"Chưa rõ trạng thái"}
)}{!load.data?.length&&}
:!item?:<>
{item.status==="PENDING"&&knownMoney(item.amount)&&item.amount>0?:{item.status==="PAID"?`Đã ghi nhận chuyển tiền lúc ${timeLabel(item.paidAt)}.`:knownMoney(item.amount)&&item.amount===0?"Không còn khoản hoàn; không tạo giao dịch chuyển tiền.":"Chưa có đủ dữ liệu khoản hoàn để thao tác."}}
}
{dialog}
; + return

SafeSpace / Quản lý cơ sở / Hợp đồng & quá hạn

{!selected?
{(load.data||[]).map(r=>

{r.customer} · Kho {r.unit}

{r.contractId} · {amountLabel(r.amount)}

{r.status==="PAID"?"Đã hoàn":r.status==="PENDING"?"Chờ hoàn":r.status==="NO_REFUND"?"Không còn khoản hoàn":"Chưa rõ trạng thái"}
)}{!load.data?.length&&}
:!item?:<>
{item.status==="PENDING"&&knownMoney(item.amount)&&item.amount>0?:{item.status==="PAID"?`Đã ghi nhận chuyển tiền lúc ${timeLabel(item.paidAt)}.`:knownMoney(item.amount)&&item.amount===0?"Không còn khoản hoàn; không tạo giao dịch chuyển tiền.":"Chưa có đủ dữ liệu khoản hoàn để thao tác."}}
}
{dialog}
; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/overdue/OverdueRemovalPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/overdue/OverdueRemovalPage.jsx index 32484b5..d726d90 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/overdue/OverdueRemovalPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/overdue/OverdueRemovalPage.jsx @@ -2,7 +2,8 @@ import ReturnPhotoInput from "../../../shared/components/ReturnPhotoInput.jsx"; import { actualVnTime } from "../../facility-operations/settlements/settlementModel.js"; import { vnDateTimeInput } from "../../facility-operations/damage/damageModel.js"; import React, { useState } from "react"; -import { Button, Field, PageHeader } from "../../../shared/components/UI.jsx"; +import { Button, Field, LinkButton, PageHeader } from "../../../shared/components/UI.jsx"; +import { go } from "../../../app/router.js"; import { useApp } from "../../../app/state/AppProvider.jsx"; import { useWorkflowData } from "../../facility-operations/workflows/useWorkflowData.js"; import { InfoTiles, RecordCard, useWorkflowChange, WorkflowEmpty, WorkflowState } from "../../facility-operations/workflows/WorkflowComponents.jsx"; @@ -14,11 +15,11 @@ export function OverdueRemovalPage() { const [dialog, ask] = useWorkflowChange(load); return
{(load.data || []).map(item => {setSelected(selected === item.id ? "" : item.id);setForm({performedAt:"",inventory:"",location:"",unitStatus:"INSPECTION",confirmed:false});setBeforePhotos([]);setAfterPhotos([]);setError("");}}>{item.record ? "Xem biên bản" : "Lập biên bản"}}> - {selected === item.id && (item.record ? :
{ e.preventDefault(); if (!form.inventory.trim() || !form.location.trim() || !form.performedAt) return setError("Điền đầy đủ thời gian, tình trạng đồ và vị trí thực tế."); setError(""); ask("RECORD_REMOVAL", { id: item.id, ...form,beforePhotos,afterPhotos }, "Kiểm tra & lưu biên bản?", "Xác nhận danh sách đồ và vị trí thực tế trước khi lưu."); }}> + {selected === item.id && (item.record ? : { e.preventDefault(); if (!form.inventory.trim() || !form.location.trim() || !form.performedAt) return setError("Điền đầy đủ thời gian, tình trạng đồ và vị trí thực tế."); setError(""); ask("RECORD_REMOVAL", { id: item.id, ...form,beforePhotos,afterPhotos }, `Lưu biên bản xử lý đồ ${item.unit}?`, "Biên bản và ảnh không sửa được sau khi lưu. Kiểm tra danh sách đồ và vị trí thực tế trước khi lưu.", { confirmLabel: "Lưu biên bản", successTitle: "Đã lưu biên bản xử lý đồ", failTitle: "Chưa lưu được biên bản", doneLabel: "Về công việc trong ngày", onDone: () => go("staff") }); }}> setForm({ ...form, performedAt: e.target.value })} />