From 725cb1a3cf0b707011c54af6ff7b307afba31757 Mon Sep 17 00:00:00 2001 From: Vector Date: Sun, 25 Oct 2026 11:07:25 +0700 Subject: [PATCH] =?UTF-8?q?feat(fe):=20b=E1=BB=95=20sung=20c=C3=A1c=20m?= =?UTF-8?q?=C3=A0n=20=C4=91=C3=A3=20duy=E1=BB=87t=20cho=205=20vai=20tr?= =?UTF-8?q?=C3=B2=20(ch=C3=ADnh=20s=C3=A1ch,=20qu=C3=A1=20h=E1=BA=A1n,=20?= =?UTF-8?q?=C4=91=E1=BB=91i=20so=C3=A1t,=20ho=C3=A0n=20c=E1=BB=8Dc,=20h?= =?UTF-8?q?=E1=BB=97=20tr=E1=BB=A3,=20l=E1=BB=8Bch=20s=E1=BB=AD=20thanh=20?= =?UTF-8?q?to=C3=A1n)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DECISIONS.md | 9 ++ .../SafeSpace-Customer-UI/.env.example | 3 + .../APPROVED-FE-API-GAPS.md | 24 +++++ .../APPROVED-FE-README.md | 59 ++++++++++ .../SafeSpace-Customer-UI/FRONTEND-MAP.md | 5 + .../SafeSpace-Customer-UI/mock/mock-api.mjs | 22 +++- .../SafeSpace-Customer-UI/package.json | 8 +- .../scripts/check-api-pending.mjs | 12 +++ .../scripts/check-approved-ui.mjs | 41 +++++++ .../scripts/check-password-reset.mjs | 30 ++++++ .../scripts/check-workflow-actions.mjs | 24 +++++ .../scripts/dev-demo.mjs | 4 + .../SafeSpace-Customer-UI/src/app/App.jsx | 23 +++- .../src/app/state/AppProvider.jsx | 11 ++ .../src/app/state/appReducer.js | 7 +- .../src/features/auth/PasswordResetPage.jsx | 15 +++ .../src/features/auth/RegisterPage.jsx | 10 +- .../src/features/auth/api/passwordResetApi.js | 10 ++ .../auth/components/ForgotPasswordDialog.jsx | 69 ++---------- .../src/features/business/BusinessRoutes.jsx | 8 ++ .../src/features/business/business.css | 4 +- .../business/policies/PolicySettingsPage.jsx | 3 +- .../business/policies/PolicyStatusPage.jsx | 14 +++ .../policies/RentalPolicyEditorPage.jsx | 17 +++ .../business/pricing/FacilityRatePage.jsx | 19 ++++ .../features/business/pricing/PricingPage.jsx | 3 +- .../business/reports/BusinessReportPage.jsx | 4 +- .../business/reports/ReportExportPage.jsx | 26 +++++ .../features/customer/access/useAccessQr.js | 1 + .../customer/contracts/DepositLedgerPage.jsx | 22 ++++ .../customer/contracts/RenewalStatusPage.jsx | 18 ++++ .../contracts/RentedUnitDetailPage.jsx | 3 +- .../customer/contracts/ReturnProgressPage.jsx | 17 +++ .../customer/contracts/ReturnRequestPage.jsx | 10 +- .../customer/history/PaymentHistoryPage.jsx | 15 +++ .../customer/payments/PaymentListPage.jsx | 1 + .../customer/payments/RefundTrackingPage.jsx | 14 +++ .../customer/policies/RentalPolicyPage.jsx | 15 +++ .../customer/support/InquiryDetailPage.jsx | 11 ++ .../customer/support/InquiryListPage.jsx | 17 +++ .../features/customer/support/SupportPage.jsx | 3 +- .../FacilityOperationsLayout.jsx | 5 +- .../FacilityOperationsRoutes.jsx | 17 +++ .../api/facilityOperationsApi.js | 2 +- .../workflows/InquiryThread.jsx | 14 +++ .../workflows/WorkflowComponents.jsx | 22 ++++ .../workflows/useWorkflowData.js | 51 +++++++++ .../workflows/workflowApi.js | 14 +++ .../workflows/workflowModel.js | 101 ++++++++++++++++++ .../discrepancies/DiscrepancyDetailPage.jsx | 13 +++ .../discrepancies/DiscrepancyListPage.jsx | 14 +++ .../manager/overdue/OverdueCasePage.jsx | 20 ++++ .../refunds/CancellationRefundPage.jsx | 86 +++------------ .../manager/refunds/DepositRefundPage.jsx | 16 +++ .../staff/overdue/OverdueRemovalPage.jsx | 20 ++++ .../staff/payments/PaymentDiscrepancyPage.jsx | 29 +++++ .../staff/payments/RenewalCollectionPage.jsx | 12 +++ .../staff/support/StaffInquiryPage.jsx | 12 +++ .../src/shared/api/apiMappers.js | 2 + .../src/shared/api/customerApi.js | 1 + .../src/shared/components/Header.jsx | 10 +- .../src/shared/styles/workflows.css | 36 +++++++ .../src/shared/utils/access.js | 2 +- .../tests/approved-workflows.test.js | 84 +++++++++++++++ .../tests/auth-support.spec.js | 5 +- .../tests/render.test.mjs | 8 +- docs/sprints/FE-approved-2026-10-25.md | 17 +++ feature_list.json | 10 ++ progress.md | 12 +++ 69 files changed, 1100 insertions(+), 166 deletions(-) create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/APPROVED-FE-API-GAPS.md create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/APPROVED-FE-README.md create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-api-pending.mjs create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-approved-ui.mjs create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-password-reset.mjs create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-workflow-actions.mjs create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/dev-demo.mjs create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/PasswordResetPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/api/passwordResetApi.js create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/PolicyStatusPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/RentalPolicyEditorPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/pricing/FacilityRatePage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/reports/ReportExportPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/contracts/DepositLedgerPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/contracts/RenewalStatusPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/contracts/ReturnProgressPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/history/PaymentHistoryPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/payments/RefundTrackingPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/policies/RentalPolicyPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/support/InquiryDetailPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/support/InquiryListPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/InquiryThread.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/WorkflowComponents.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/useWorkflowData.js create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/workflowApi.js create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/workflows/workflowModel.js create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/discrepancies/DiscrepancyDetailPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/discrepancies/DiscrepancyListPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/overdue/OverdueCasePage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/manager/refunds/DepositRefundPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/overdue/OverdueRemovalPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/payments/PaymentDiscrepancyPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/payments/RenewalCollectionPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/support/StaffInquiryPage.jsx create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/styles/workflows.css create mode 100644 SafeSpace-Customer-UI/SafeSpace-Customer-UI/tests/approved-workflows.test.js create mode 100644 docs/sprints/FE-approved-2026-10-25.md diff --git a/DECISIONS.md b/DECISIONS.md index a43672b..b82df6e 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -217,3 +217,12 @@ Bổ sung @playwright/test trong devDependencies để kiểm thao tác biểu m - Kiểm chứng theo phạm vi, cho phép làm phần độc lập khi môi trường thiếu; ghi rõ phần chưa kiểm chứng. Trước merge code chạy đủ bộ liên quan và kiểm thử tích hợp; chỉ tài liệu không bắt buộc build ứng dụng. AI review không thay review của thành viên khác. - Không commit bí mật; cấu hình mẫu/dùng chung không chứa bí mật được phép. Không sửa migration đã merge/áp dụng trên DB dùng chung; migration chưa chia sẻ được sửa trong nhánh riêng. Không tự xóa/reset DB. - Không thay D26/D27, tính tiền, phân quyền, schema, API hoặc trạng thái passing của bất kỳ tính năng sản phẩm nào. + + +## D29 — 2026-10-25: FE các màn đã duyệt và chính sách người dùng mới chốt + +- Theo yêu cầu người dùng: hoàn thiện FE kể cả chưa có BE. Thêm demo opt-in `dev:demo`, có nhãn rõ. API thường không fallback thành công. Không sửa backend, migration hoặc số tiền settlement hiện hành. +- Người dùng chốt chính sách mới cho bản cập nhật tiếp theo: mỗi ngày trễ trừ 5% cọc ban đầu, cap100%; ngày20 nhân viên đưa đồ ra ngoài, khách tự chịu trách nhiệm. Nội dung FE này thay hướng mô tả quá hạn theo giá thuê trong D27/D28; BE chưa được chuyển đổi trong task FE này. Ledger luôn là bản xem trước đến khi BE cung cấp quyết toán/phiên bản áp dụng. +- Khách đọc chính sách chi tiết; OPERATIONS sửa và xem trước. Không làm trang thu hồi QR; FE chặn mở cửa ngay sau trả kho thành công/hết hạn. Server/thiết bị phải kiểm tra quyền thực tế. Không tạo trang thông báo riêng; dùng chuông trên header. +- Mỗi khách/đơn một thẻ, tên/chi tiết nằm gần nhau, hành động ở bên phải và căn giữa; form gọn, tránh hai cột thông tin cách quá xa. +- Giữ source trên nhánh local để chủ repo review; không commit/push/PR và không đánh dấu passing trước owner duyệt. diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/.env.example b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/.env.example index b1c3eaf..fc2cf02 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/.env.example +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/.env.example @@ -13,3 +13,6 @@ VITE_BANK_BIN=970422 VITE_BANK_NAME=MB Bank VITE_BANK_ACCOUNT=0901234567890 VITE_BANK_HOLDER=CONG TY TNHH SAFESPACE + +# Demo nghiệp vụ bổ sung chỉ bật bằng npm run dev:demo; API thường giữ false. +VITE_WORKFLOW_DEMO=false diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/APPROVED-FE-API-GAPS.md b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/APPROVED-FE-API-GAPS.md new file mode 100644 index 0000000..b71d863 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/APPROVED-FE-API-GAPS.md @@ -0,0 +1,24 @@ +# Hợp đồng BE cần bổ sung — không phải API đã triển khai + +FE đã có adapter; 404/405 hiện thông báo chưa hỗ trợ. Cần BE review schema, quyền, dữ liệu và giao dịch trước tích hợp. Không dùng localStorage để quyết toán thật. + +| Resource | GET dự kiến | POST action | +|---|---|---| +| discrepancies | /api/ops/discrepancies | REPORT_DISCREPANCY, RESOLVE_DISCREPANCY | +| overdue | /api/ops/overdue-cases | ASSIGN_REMOVAL, RECORD_REMOVAL | +| depositRefunds | /api/ops/deposit-refunds | CONFIRM_DEPOSIT_REFUND | +| counterRenewals | /api/ops/counter-renewals | COLLECT_RENEWAL | +| inquiries | /api/support/inquiries | CREATE_INQUIRY, REPLY_INQUIRY | +| policy | /api/rental-policy | SAVE_RENTAL_POLICY | + +POST gửi tới `/actions`, JSON `{action, ...payload}`, trả JSON xác nhận; sau đó FE GET lại. GET danh sách trả mảng trực tiếp; policy trả object `{rate,sections,version,updatedAt}`. Thuộc tính đầy đủ và payload tham khảo `src/features/facility-operations/workflows/workflowModel.js` (fixture/model FE), và các Page gọi `run` trong cùng feature. ID hồ sơ hiện là string. Cần thống nhất DTO thật trước mở API. + +Máy chủ phải lọc cơ sở của staff/manager và owner của khách, tự tính tiền theo hợp đồng, kiểm tra transition và chống ghi nhận lặp. Giá trị/role từ FE không là nguồn tin cậy. POST hoàn tiền cần transactionRef; POST biên bản cần id, performedAt, inventory, location, unitStatus (INSPECTION/MAINTENANCE). Hoàn tiền ở đây ghi nhận chuyển khoản thủ công, không gọi ngân hàng. + +- POST /api/auth/password-reset/request `{email}`: trả thông báo chung; không lộ tồn tại tài khoản. BE cần gửi email, rate limit, mã có TTL/số lượt thử. `demoCode` chỉ tồn tại trong mock. +- POST /api/auth/password-reset/confirm `{email,code,newPassword}`: mã một lần, kiểm tra TTL, hash mật khẩu, xem xét thu hồi phiên cũ. +- POST /api/renewals/{id}/counter-payment: khách chọn tại quầy cho yêu cầu APPROVED thuộc mình; chưa ghi nhận đã thu/chưa đổi ngày. Mock đã có endpoint; BE thật chưa xác nhận hỗ trợ. +- Chính sách mới: trừ 5% cọc BAN ĐẦU mỗi ngày trễ, cap100%, ngày20 đưa đồ ra ngoài. Ledger FE là bản xem trước, không thay settlement BE. Cần thống nhất ngày hiệu lực/phiên bản và cập nhật BE riêng, không tự áp lại hợp đồng cũ. D27 cũ khác cơ sở tính. +- QR/PIN đã phát cần BE từ chối ngay sau REQUEST_RETURN thành công hoặc hết hạn. FE đã khóa nút/call; chưa chứng minh credential cũ bị backend/thiết bị từ chối. Không có màn thu hồi thủ công. +- Các API giá cơ sở, trạng thái chính sách, báo cáo CSV tái sử dụng businessApi hiện có; vẫn cần kiểm tra với BE thật trước dùng sản xuất. +- GET policy là công khai; POST chỉ OPERATIONS. Chính sách fallback khi GET chưa hỗ trợ được gắn nhãn tài liệu tham khảo, không khẳng định là phiên bản đang áp dụng. diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/APPROVED-FE-README.md b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/APPROVED-FE-README.md new file mode 100644 index 0000000..89ab733 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/APPROVED-FE-README.md @@ -0,0 +1,59 @@ +# FE bổ sung theo thiết kế đã duyệt — 25/10/2026 + +Bản gốc: main 54abba6 (đã gồm PR #39 sửa C11, C14a, S04, S09, M07; gói ban đầu làm trên c5aa79a và đã được gộp lại). Nhánh local: feature/figma-approved-fe-completion. Figma: https://www.figma.com/design/SX8EvOf1TJkxfMl90bZsGN + +## Chạy kiểm duyệt + +Yêu cầu Node >=22.12. Trong PowerShell: + +```powershell +cd SafeSpace-Customer-UI\SafeSpace-Customer-UI +npm ci +npm run dev:demo +``` + +Mở http://127.0.0.1:5173. Tài khoản demo: customer01 / Customer@123; staff01 / Staff@123; manager01 / Manager@123; ops01 / Ops@123; admin / Admin@123. Demo hiện nhãn rõ, dữ liệu nghiệp vụ bổ sung nằm trong localStorage `safespace.approved-workflows.demo.v1`. Xoá khóa này để bắt đầu lại; khởi động lại server để reset dữ liệu API mô phỏng. Không dùng demo cho giao dịch thật. Các fixture bổ sung là kịch bản độc lập, chưa đồng bộ hạch toán với mọi hợp đồng API mô phỏng. + +Chạy API hiện có: cấu hình theo .env.example rồi `npm run dev`. Không bật VITE_WORKFLOW_DEMO. Endpoint thiếu báo lỗi; không tự chuyển sang demo. Không có thay đổi backend, DB hoặc migration trong gói này. + +## Các màn bổ sung + +| Vai trò | Đường dẫn sau #/ | Hành vi | +|---|---|---| +| Công khai | reset-password | Nhập email, mã xác nhận, mật khẩu mới, gửi lại, lỗi, thành công | +| Khách | policies | 7 nhóm chính sách chi tiết | +| Khách | payments/history | Lọc lịch sử và xem chi tiết giao dịch | +| Khách | refunds | Tiến độ hoàn cọc, chi tiết, trạng thái chưa hoàn/đã hoàn/0đ | +| Khách | units/:id/deposit | Lịch trừ cọc theo ngày; ghi rõ bản xem trước chính sách | +| Khách | units/:id/progress | Tiến độ trả kho và đối soát | +| Khách | units/:id/renewal-status | Chờ duyệt/từ chối/thanh toán/gia hạn tại quầy | +| Khách | inquiries, inquiries/:id | Hỗ trợ chưa có hợp đồng, chọn cơ sở, trao đổi | +| Nhân viên | staff/mismatch | Báo sai lệch thực nhận và lý do | +| Nhân viên | staff/renewal-payments | Thu gia hạn tại quầy, chặn thu lần hai | +| Nhân viên | staff/overdue | Biên bản đưa đồ ra ngoài sau 20 ngày | +| Nhân viên | staff/inquiries | Tiếp nhận và phản hồi yêu cầu tư vấn | +| Quản lý | manager/discrepancies, manager/discrepancy-detail?id=… | Danh sách và kết luận đối soát | +| Quản lý | manager/overdue | Khấu trừ cọc, phân công, xem biên bản | +| Quản lý | manager/deposit-refunds | Đối soát và xác nhận hoàn cọc; bắt buộc mã giao dịch | +| Vận hành KD | business/policy-content | Sửa 7 nhóm nội dung, tỷ lệ, xem trước và lưu | +| Vận hành KD | business/policy-status | Theo dõi chính sách; ngừng áp dụng/xóa bản nháp | +| Vận hành KD | business/rates | Bảng giá cơ sở, lọc, tạo/sửa giá theo ngày | +| Vận hành KD | business/export | Chọn phạm vi, xác nhận, xuất CSV | + +Các màn sẵn có vẫn giữ đủ 5 vai trò. Đăng ký thêm thông báo thành công. Hoàn đơn hủy đổi thành từng thẻ khách hàng với chi tiết và nút đúng từng hồ sơ. Không có trang thông báo khách hàng riêng hoặc trang thu hồi QR; khách dùng chuông trên header. QR bị chặn trên FE ngay khi yêu cầu trả kho thành công hoặc hợp đồng hết hạn. + +## Kiểm chứng + +- `TZ=Asia/Ho_Chi_Minh bash init.sh --fe-only`: test 81/81, render 115 route, build đạt. Bộ mapper cũ phụ thuộc múi giờ Việt Nam; host UTC có một kỳ vọng ngày cũ lệch ngày. +- `npm run check:structure`: đạt; `npm run test:business`: 9/9; `npm run test:workflows`: 10/10. +- `npm run test:auth-support`: 14/14 luồng auth/hỗ trợ đạt. Cập nhật bài kiểm tra S05 theo modal xác nhận/kết quả và quay về danh sách hiện hành trên main. +- `node scripts/check-approved-ui.mjs`: 25 route trên desktop/mobile; không tràn ngang hoặc lỗi runtime trong lượt kiểm tra. +- `node scripts/check-workflow-actions.mjs`: 10 nhóm thao tác xác nhận/hủy/lỗi/lặp/cross-role/CSV. +- `node scripts/check-api-pending.mjs`: API thiếu không giả thành công, giữ nội dung đang nhập. +- `node scripts/check-password-reset.mjs`: sai OTP, đúng OTP, đăng nhập bằng mật khẩu mới. + +Các script trình duyệt dùng Chromium của Playwright (`npx playwright install chromium`). Có thể truyền PLAYWRIGHT_EXECUTABLE_PATH nếu máy đã có binary. Script tự mở server; đóng server dev đang chạy cổng 5173 trước khi kiểm tra. Những kiểm tra này dùng API mô phỏng/DTO, chưa chứng minh tích hợp SQL Server, PayOS thật hoặc thiết bị mở cửa. Build còn cảnh báo bundle lớn hơn 500kB. Không đổi trạng thái tính năng sang passing thay người phụ trách. + +## Tích hợp + +Gói có toàn bộ source FE, changes.patch và repo-changes chứa các file sửa/thêm theo đường dẫn gốc. Dùng trên main 54abba6; nếu main đã đổi, review diff trước khi áp dụng. Không chép node_modules/dist. Cài lại bằng npm ci. AI không commit/push/PR; thành viên đọc diff, kiểm tra API gap rồi tự tích hợp. diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/FRONTEND-MAP.md b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/FRONTEND-MAP.md index ab6bf44..8da5054 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/FRONTEND-MAP.md +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/FRONTEND-MAP.md @@ -179,3 +179,8 @@ | `src/pages/Checkout.jsx` | `src/features/customer/reservations/components/ReservationNotFound.jsx`, `src/features/customer/payments/CheckoutPage.jsx`, `src/features/customer/payments/CheckoutFailedPage.jsx`, `src/features/customer/reservations/ReservationDetailPage.jsx` | | `src/pages/Auth.jsx` | `src/features/auth/utils/safeNext.js`, `src/features/auth/components/ForgotPasswordDialog.jsx`, `src/features/auth/LoginPage.jsx`, `src/features/auth/RegisterPage.jsx` | | `src/pages/Public.jsx` | `src/features/customer/pricing/PublicPricingPage.jsx`, `src/features/customer/help/HelpPage.jsx` | + + +## FE bổ sung 25/10/2026 + +Xem `SafeSpace-Customer-UI/SafeSpace-Customer-UI/APPROVED-FE-README.md` để có bảng route đầy đủ. Các API dự kiến, giới hạn demo và yêu cầu BE ở `APPROVED-FE-API-GAPS.md`. Feature dùng chung: `src/features/facility-operations/workflows`; style: `src/shared/styles/workflows.css`. diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/mock/mock-api.mjs b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/mock/mock-api.mjs index 6b4f744..22e58c5 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/mock/mock-api.mjs +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/mock/mock-api.mjs @@ -120,8 +120,10 @@ const camel = (k) => k.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase()); const snake = (k) => k.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`); const mapKeys = (v, fn) => Array.isArray(v) ? v.map((x) => mapKeys(x, fn)) : v && typeof v === "object" ? Object.fromEntries(Object.entries(v).map(([k, x]) => [fn(k), mapKeys(x, fn)])) : v; -const STAFF_PARTS = ["facility", "staff", "units", "payments", "verifications", "handovers", "returns", "tickets"]; +const STAFF_PARTS = ["facility", "staff", "units", "payments", "verifications", "handovers", "returns", "tickets", "fee_collections"]; const OPS_ROUTES = [ + ["POST", /^\/api\/(?:ops|manager)\/reservations\/([^/]+)\/refund$/, "MANAGER", "CONFIRM_RESERVATION_REFUND", (b, id) => ({ id, method: b?.method, transaction_ref: b?.transactionRef })], + ["POST", /^\/api\/(?:ops|staff)\/fees\/([^/]+)\/confirm$/, "STAFF", "CONFIRM_FEE_COLLECTION", (b, id) => ({ id })], // [method, regex, role, action, payload(body, id)] ["POST", /^\/api\/(?:ops|staff)\/payments\/([^/]+)\/confirm$/, "STAFF", "CONFIRM_PAYMENT", (b, id) => ({ id })], ["POST", /^\/api\/(?:ops|staff)\/payments\/([^/]+)\/mismatch$/, "STAFF", "REPORT_MISMATCH", (b, id) => ({ id, note: b?.note })], @@ -283,6 +285,18 @@ export function startMockApi( let m; // ---- Auth + if (req.method === "POST" && path === "/api/auth/password-reset/request") { + const user = S.users.find(u => u.email.toLowerCase() === String(body.email || "").trim().toLowerCase()); + if (user) user.demoReset = { code: "123456", expiresAt: Date.now() + 300000 }; + return send(200, { message: "Nếu email đã đăng ký, mã đã được gửi.", demoCode: "123456" }); + } + if (req.method === "POST" && path === "/api/auth/password-reset/confirm") { + const user = S.users.find(u => u.email.toLowerCase() === String(body.email || "").trim().toLowerCase()); + if (!user?.demoReset || user.demoReset.code !== body.code || user.demoReset.expiresAt < Date.now()) return bad("Mã xác nhận không hợp lệ hoặc đã hết hạn."); + if (String(body.newPassword || "").length < 8) return bad("Mật khẩu mới phải có ít nhất 8 ký tự."); + user.password = body.newPassword; delete user.demoReset; + return send(200, { message: "Đã đặt lại mật khẩu." }); + } if (req.method === "POST" && path === "/api/auth/register") { if (S.users.some((u) => u.username === body.username || u.email === body.email)) return bad("Tên đăng nhập hoặc email đã tồn tại trong hệ thống."); const user = { userId: S.users.length + 1, username: body.username, email: body.email, password: body.password, fullName: body.fullName, phone: body.phone, status: "ACTIVE", createdAt: new Date(), updatedAt: new Date() }; @@ -655,6 +669,12 @@ export function startMockApi( const h = S.handovers.find((x) => x.contractId === c.contractId); return send(200, { ...contractSummary(c), terminationReason: null, createdAt: dbTime(c.createdAt), completedAt: null, handover: h ? { handoverId: h.handoverId, status: h.status, scheduledAt: dbTime(h.scheduledAt), handoverAt: dbTime(h.handoverAt), customerConfirmed: h.customerConfirmed, staffConfirmed: h.staffConfirmed } : null, payments: S.payments.filter((p) => p.contractId === c.contractId).map(payDto), renewals: S.renewals.filter((r) => r.contractId === c.contractId).map(renDto) }); } + if (req.method === "POST" && (m = path.match(/^\/api\/renewals\/(\d+)\/counter-payment$/))) { + const renewal = S.renewals.find(x => x.renewalId === Number(m[1]) && S.contracts.some(c => c.contractId === x.contractId && c.customerId === me)); + if (!renewal || renewal.status !== "APPROVED") return bad("Yêu cầu chưa được duyệt hoặc đã thanh toán."); + renewal.atCounter = true; + return send(200, { ok: true }); + } if (req.method === "POST" && (m = path.match(/^\/api\/contracts\/(\d+)\/renewals$/))) { if (!(body.renewalPeriodMonths > 0)) return bad("Thời gian gia hạn phải lớn hơn 0 tháng."); const c = S.contracts.find((x) => x.contractId === +m[1] && x.customerId === me); diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package.json b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package.json index 93791f0..97ad6f3 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package.json +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package.json @@ -13,7 +13,13 @@ "test": "node --test 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", "test:render": "node tests/render.test.mjs", "dev:mock": "node scripts/dev-mock.mjs", - "check:structure": "node scripts/check-structure.mjs" + "check:structure": "node scripts/check-structure.mjs", + "dev:demo": "node scripts/dev-demo.mjs", + "test:workflows": "node --test tests/approved-workflows.test.js", + "test:approved-ui": "node scripts/check-approved-ui.mjs", + "test:workflow-actions": "node scripts/check-workflow-actions.mjs", + "test:api-pending": "node scripts/check-api-pending.mjs", + "test:password-reset": "node scripts/check-password-reset.mjs" }, "dependencies": { "@fontsource/inter": "^5.3.0", diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-api-pending.mjs b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-api-pending.mjs new file mode 100644 index 0000000..174fc69 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-api-pending.mjs @@ -0,0 +1,12 @@ +import { chromium } from '@playwright/test'; +import assert from 'node:assert/strict'; +import { spawn } from 'node:child_process'; +const server=spawn(process.execPath,['scripts/dev-business.mjs'],{env:{...process.env,MOCK_API_PORT:'5299',VITE_WORKFLOW_DEMO:'false'},stdio:'ignore'}); +process.on('exit',()=>server.kill('SIGTERM')); +for(let i=0;i<100;i++){try{await fetch('http://127.0.0.1:5173');break;}catch{await new Promise(r=>setTimeout(r,150));}} +const browser=await chromium.launch({executablePath:process.env.PLAYWRIGHT_EXECUTABLE_PATH,args:['--no-sandbox','--disable-dev-shm-usage']}),page=await browser.newPage(); +await page.goto('http://127.0.0.1:5173/#/login');await page.locator('input').first().fill('staff01');await page.locator('input[type=password]').fill('Staff@123');await page.getByRole('button',{name:'Đăng nhập',exact:true}).click();await page.waitForFunction(()=>!location.hash.includes('/login')); +await page.goto('http://127.0.0.1:5173/#/staff/mismatch');await page.getByText(/Máy chủ chưa cung cấp dữ liệu/).waitFor(); +assert.equal(await page.getByText('MÔ PHỎNG FE · Dữ liệu thử nghiệm, không thanh toán / chuyển tiền thật.').count(),0); +await page.getByLabel('Số tiền thực nhận').fill('100000');await page.getByLabel('Lý do / nội dung cần kiểm tra').fill('Giữ nguyên nội dung khi API chưa có.');await page.getByRole('button',{name:'Kiểm tra & gửi báo cáo'}).click();await page.getByRole('dialog').getByRole('button',{name:'Xác nhận',exact:true}).click();await page.getByRole('dialog').getByText(/Máy chủ chưa hỗ trợ lưu màn này/).waitFor();assert.equal(await page.getByRole('dialog').getByText('Đã lưu kết quả',{exact:true}).count(),0);await page.getByRole('dialog').getByRole('button',{name:'Quay lại',exact:true}).click();assert.equal(await page.getByLabel('Lý do / nội dung cần kiểm tra').inputValue(),'Giữ nguyên nội dung khi API chưa có.');assert.equal(await page.evaluate(()=>localStorage.getItem('safespace.approved-workflows.demo.v1')),null); +console.log(JSON.stringify({apiPending:true,noDemoFallback:true,preservedInput:true}));await browser.close();server.kill('SIGTERM'); diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-approved-ui.mjs b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-approved-ui.mjs new file mode 100644 index 0000000..57e6abb --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-approved-ui.mjs @@ -0,0 +1,41 @@ +import { chromium } from '@playwright/test'; +import assert from 'node:assert/strict'; +import fs from 'node:fs/promises'; +import { spawn } from 'node:child_process'; +const server = !process.env.QA_EXTERNAL_SERVER ? spawn(process.execPath, ['scripts/dev-demo.mjs'], { env: { ...process.env, MOCK_API_PORT: '5299' }, stdio: 'ignore' }) : null; +if (server) { for (let i=0;i<100;i++) { try { await fetch('http://127.0.0.1:5173'); break; } catch { await new Promise(r=>setTimeout(r,150)); } } } +process.on('exit',()=>server?.kill('SIGTERM')); +const output = process.env.QA_OUTPUT || 'test-results/approved-ui'; +await fs.mkdir(output,{recursive:true}); +const browser=await chromium.launch({executablePath:process.env.PLAYWRIGHT_EXECUTABLE_PATH,args:['--no-sandbox','--disable-dev-shm-usage']}); +const context=await browser.newContext({viewport:{width:1440,height:1000}}),page=await context.newPage(); +const errors=[];page.on('pageerror',e=>errors.push(e.message)); +const roles=[ + ['manager01','Manager@123',['manager/refunds','manager/discrepancies','manager/discrepancy-detail?id=SL-0001','manager/overdue','manager/deposit-refunds']], + ['staff01','Staff@123',['staff/mismatch','staff/renewal-payments','staff/overdue','staff/inquiries']], + ['customer01','Customer@123',['refunds','policies','payments/history','inquiries','inquiries/HT-0091','units/HĐ-2026-0001/deposit','units/HĐ-2026-0001/progress','units/HĐ-2026-0001/renewal-status']], + ['ops01','Ops@123',['business/policy-content','business/policy-status','business/rates','business/export']], + ['admin','Admin@123',['admin','admin/new','admin/permissions','admin/logs']], +]; +const results=[]; +for(const [name,password,routes] of roles){ + await page.goto('http://127.0.0.1:5173/#/login');await page.evaluate(()=>{localStorage.removeItem('safespace.customer.session');});await page.reload(); + await page.locator('input').first().fill(name);await page.locator('input[type=password]').fill(password);await page.getByRole('button',{name:'Đăng nhập',exact:true}).click(); + await page.waitForFunction(()=>!location.hash.includes('/login')); + for(const route of routes){ + await page.goto('http://127.0.0.1:5173/#/'+route);await page.waitForTimeout(250); + const text=await page.locator('body').innerText();assert.ok(!/Không tìm thấy trang|Cannot read properties|undefined|NaN/.test(text),route); + assert.ok(await page.locator('main h1').count(),route+' missing title'); + const label=route.replaceAll('/','-').replaceAll('?','-').replaceAll('=','-'); + await page.screenshot({path:output+'/'+label+'.png',fullPage:true}); + await page.setViewportSize({width:390,height:844});await page.waitForTimeout(80); + const overflow=await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth+2); + results.push({route,mobileOverflow:overflow,title:await page.locator('main h1').first().innerText()}); + if(overflow)await page.screenshot({path:output+'/'+label+'-mobile.png',fullPage:true}); + await page.setViewportSize({width:1440,height:1000}); + } +} +assert.deepEqual(errors,[],'browser runtime errors'); +await fs.writeFile(output+'/results.json',JSON.stringify({results,errors},null,2));console.log(JSON.stringify({routes:results.length,overflow:results.filter(r=>r.mobileOverflow),errors})); +await browser.close(); +server?.kill("SIGTERM"); diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-password-reset.mjs b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-password-reset.mjs new file mode 100644 index 0000000..6ca576a --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-password-reset.mjs @@ -0,0 +1,30 @@ +import { chromium } from '@playwright/test'; +import assert from 'node:assert/strict'; +import { spawn } from 'node:child_process'; +const server = spawn(process.execPath, ['scripts/dev-demo.mjs'], { stdio: 'ignore' }); +process.on('exit', () => server.kill('SIGTERM')); +let browser; +try { + for (let i = 0; i < 100; i++) { try { await fetch('http://127.0.0.1:5173'); break; } catch { await new Promise(r => setTimeout(r, 150)); } } + browser = await chromium.launch({ executablePath: process.env.PLAYWRIGHT_EXECUTABLE_PATH, args: ['--no-sandbox', '--disable-dev-shm-usage'] }); + const page = await browser.newPage(); const errors = []; + page.on('pageerror', e => errors.push(e.message)); + await page.goto('http://127.0.0.1:5173/#/reset-password'); + await page.getByLabel('Email đã đăng ký').fill('an.nguyen@example.com'); + await page.getByRole('button', { name: 'Gửi mã xác nhận', exact: true }).click(); + await page.getByLabel('Mã xác nhận').fill('000000'); + await page.getByLabel('Mật khẩu mới', { exact: true }).fill('NewCustomer@123'); + await page.getByLabel('Nhập lại mật khẩu mới').fill('NewCustomer@123'); + await page.getByRole('button', { name: 'Đặt lại mật khẩu', exact: true }).click(); + await page.getByText('Mã xác nhận không hợp lệ hoặc đã hết hạn.', { exact: true }).waitFor(); + await page.getByLabel('Mã xác nhận').fill('123456'); + await page.getByRole('button', { name: 'Đặt lại mật khẩu', exact: true }).click(); + await page.getByRole('heading', { name: 'Đã đặt lại mật khẩu' }).waitFor(); + await page.getByRole('link', { name: 'Về đăng nhập', exact: true }).click(); + await page.locator('input').first().fill('customer01'); + await page.locator('input[type=password]').fill('NewCustomer@123'); + await page.getByRole('button', { name: 'Đăng nhập', exact: true }).click(); + await page.waitForFunction(() => !location.hash.includes('/login')); + assert.deepEqual(errors, []); + console.log('PASS: sai OTP giữ form; đúng OTP đổi mật khẩu; đăng nhập bằng mật khẩu mới; không lỗi runtime.'); +} finally { await browser?.close(); server.kill('SIGTERM'); } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-workflow-actions.mjs b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-workflow-actions.mjs new file mode 100644 index 0000000..b27ecd3 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/check-workflow-actions.mjs @@ -0,0 +1,24 @@ +import { chromium } from '@playwright/test'; +import assert from 'node:assert/strict'; +import { spawn } from 'node:child_process'; +const server=spawn(process.execPath,['scripts/dev-demo.mjs'],{env:{...process.env,MOCK_API_PORT:'5299'},stdio:'ignore'}); +process.on('exit',()=>server.kill('SIGTERM')); +for(let i=0;i<100;i++){try{await fetch('http://127.0.0.1:5173');break;}catch{await new Promise(r=>setTimeout(r,150));}} +const browser=await chromium.launch({executablePath:process.env.PLAYWRIGHT_EXECUTABLE_PATH,args:['--no-sandbox','--disable-dev-shm-usage']}),page=await browser.newPage({viewport:{width:1440,height:1000}}); +const errors=[];page.on('pageerror',e=>errors.push(e.message)); +async function login(name,password){await page.goto('http://127.0.0.1:5173/#/login');await page.evaluate(()=>localStorage.removeItem('safespace.customer.session'));await page.reload();await page.locator('input').first().fill(name);await page.locator('input[type=password]').fill(password);await page.getByRole('button',{name:'Đăng nhập',exact:true}).click();await page.waitForFunction(()=>!location.hash.includes('/login'));} +async function route(path){await page.goto('http://127.0.0.1:5173/#/'+path);await page.waitForTimeout(200);} +async function confirm(){await page.getByRole('dialog').getByRole('button',{name:'Xác nhận',exact:true}).click();await page.getByRole('dialog').getByRole('button',{name:'Về danh sách',exact:true}).click();} +const passed=[]; +await login('manager01','Manager@123');await route('manager/refunds'); +const han=page.locator('.record-card').filter({hasText:'Phạm Gia Hân'});await han.getByRole('button',{name:'Xem yêu cầu hoàn tiền'}).click();assert.match(await page.getByRole('dialog').innerText(),/2.166.000/);await page.getByRole('button',{name:'Đóng chi tiết',exact:true}).click(); +await han.getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).click();await page.getByRole('dialog').getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).click();assert.match(await page.getByRole('dialog').innerText(),/Nhập mã giao dịch/);await page.getByLabel('Mã giao dịch hoàn tiền').fill('QA-REF-0139');await page.getByRole('dialog').getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).click();await page.waitForTimeout(200);assert.equal(await han.getByRole('button',{name:'Xác nhận đã hoàn',exact:true}).count(),0);passed.push('Đúng khách / bắt buộc mã giao dịch / không xác nhận hoàn hai lần'); +await route('manager/discrepancy-detail?id=SL-0001');await page.getByLabel('Kết luận / nội dung phản hồi').fill('Đã đối chiếu chứng từ, thực nhận thiếu 50.000 đ.');await page.getByRole('button',{name:'Kiểm tra & lưu kết quả'}).click();await page.getByRole('dialog').getByRole('button',{name:'Quay lại',exact:true}).click();assert.equal(await page.getByLabel('Kết luận / nội dung phản hồi').count(),1);await page.getByRole('button',{name:'Kiểm tra & lưu kết quả'}).click();await confirm();assert.match(await page.locator('main').innerText(),/Đã xử lý/);passed.push('Huỷ đối soát không lưu; xác nhận mới đổi trạng thái'); +await route('manager/deposit-refunds');await page.getByRole('button',{name:'Xem khoản hoàn'}).click();await page.getByLabel('Mã giao dịch hoàn cọc').fill('QA-DEPOSIT-0098');await page.getByRole('button',{name:'Xác nhận đã hoàn cọc'}).click();await confirm();assert.equal(await page.getByRole('button',{name:'Xác nhận đã hoàn cọc'}).count(),0);passed.push('Hoàn cọc độc lập và chặn xác nhận lại'); +await login('customer01','Customer@123');await route('refunds');assert.match(await page.locator('main').innerText(),/Đã hoàn cọc/);passed.push('Khách nhìn thấy kết quả hoàn cọc sau khi quản lý xác nhận');await route('inquiries/HT-0091');await page.getByRole('button',{name:'Kiểm tra & gửi phản hồi'}).click();assert.match(await page.locator('main').innerText(),/Vui lòng nhập nội dung/);await page.getByLabel('Nội dung phản hồi').fill('Tôi cần kho cho 10 thùng đồ trong 3 tháng.');await page.getByRole('button',{name:'Kiểm tra & gửi phản hồi'}).click();await confirm();passed.push('Phản hồi khách: dữ liệu trống và gửi thành công'); +await login('staff01','Staff@123');await route('staff/inquiries');await page.getByRole('button',{name:'Xem yêu cầu',exact:true}).click();assert.match(await page.locator('main').innerText(),/Tôi cần kho cho 10 thùng đồ/);passed.push('Nhân viên nhận đúng phản hồi của khách qua dữ liệu demo chung'); +await route('staff/mismatch');await page.getByRole('button',{name:'Kiểm tra & gửi báo cáo'}).click();assert.match(await page.locator('main').innerText(),/số tiền thực nhận hợp lệ/);await page.getByLabel('Số tiền thực nhận').fill('100000');await page.getByLabel('Lý do / nội dung cần kiểm tra').fill('Khách chuyển thiếu; đề nghị quản lý đối soát.');await page.getByRole('button',{name:'Kiểm tra & gửi báo cáo'}).click();await confirm();passed.push('Báo sai lệch có xác nhận và kiểm tra đầu vào'); +await route('staff/renewal-payments');await page.getByRole('button',{name:'Xác nhận đã thu',exact:true}).click();await confirm();assert.equal(await page.getByRole('button',{name:'Xác nhận đã thu',exact:true}).count(),0);passed.push('Thu gia hạn tại quầy một lần'); +await login('ops01','Ops@123');await route('business/policy-content');await page.getByLabel('Nội dung hiển thị cho khách').first().fill('Nội dung kiểm tra đã duyệt cho khách.');await page.getByRole('button',{name:'Xem trước bản khách đọc'}).click();assert.match(await page.getByRole('dialog').innerText(),/Nội dung kiểm tra đã duyệt/);await page.getByRole('button',{name:'Quay lại chỉnh sửa'}).click();await page.getByRole('button',{name:'Kiểm tra & lưu thay đổi'}).click();await confirm();passed.push('Chính sách xem trước / xác nhận lưu'); +await route('business/export');await page.getByRole('button',{name:'Kiểm tra & xuất CSV'}).click();const download=page.waitForEvent('download');await page.getByRole('dialog').getByRole('button',{name:'Xuất CSV',exact:true}).click();assert.match((await download).suggestedFilename(),/\.csv$/);passed.push('Xuất CSV theo phạm vi'); +assert.deepEqual(errors,[]);console.log(JSON.stringify({passed,errors}));await browser.close();server.kill('SIGTERM'); diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/dev-demo.mjs b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/dev-demo.mjs new file mode 100644 index 0000000..38df685 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/scripts/dev-demo.mjs @@ -0,0 +1,4 @@ +process.env.VITE_WORKFLOW_DEMO = "true"; +process.env.MOCK_API_PORT ||= "5299"; +console.log("MÔ PHỎNG TOÀN BỘ FE: không dùng cho giao dịch thật. Dữ liệu bổ sung lưu trong trình duyệt."); +await import("./dev-business.mjs"); 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 f4ed57a..86e23f0 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx @@ -10,10 +10,21 @@ import "@fontsource/inter/latin-800.css"; import "@fontsource/inter/vietnamese-800.css"; import "../shared/styles/ss.css"; import "../shared/styles/auth-support.css"; +import "../shared/styles/workflows.css"; +import { WORKFLOW_DEMO } from "../features/facility-operations/workflows/useWorkflowData.js"; +import { RentalPolicyPage } from "../features/customer/policies/RentalPolicyPage.jsx"; +import { RefundTrackingPage } from "../features/customer/payments/RefundTrackingPage.jsx"; +import { PaymentHistoryPage } from "../features/customer/history/PaymentHistoryPage.jsx"; +import { DepositLedgerPage } from "../features/customer/contracts/DepositLedgerPage.jsx"; +import { RenewalStatusPage } from "../features/customer/contracts/RenewalStatusPage.jsx"; +import { ReturnProgressPage } from "../features/customer/contracts/ReturnProgressPage.jsx"; +import { InquiryListPage } from "../features/customer/support/InquiryListPage.jsx"; +import { InquiryDetailPage } from "../features/customer/support/InquiryDetailPage.jsx"; import React, { useEffect } from "react"; import Header from "../shared/components/Header.jsx"; import { Button, Empty, Icon, LinkButton } from "../shared/components/UI.jsx"; import { go, parseRoute, useRoute } from "./router.js"; +import { PasswordResetPage } from "../features/auth/PasswordResetPage.jsx"; import { LoginPage } from "../features/auth/LoginPage.jsx"; import { RegisterPage } from "../features/auth/RegisterPage.jsx"; import { CheckoutPage } from "../features/customer/payments/CheckoutPage.jsx"; @@ -68,12 +79,16 @@ const TITLES = { }; // Trang cần đăng nhập. Các trang công khai: home, login, register, pricing, guide, find (xem cơ sở). -const PRIVATE = ["overview", "units", "reservations", "payments", "support", "profile", "checkout", "confirmation", "sent"]; +const PRIVATE = ["refunds", "inquiries","overview", "units", "reservations", "payments", "support", "profile", "checkout", "confirmation", "sent"]; function renderPage({ page, parts, query }) { const [a, b] = parts; switch (page) { case "home": return ; + case "refunds": return ; + case "policies": return ; + case "inquiries": return a ? : ; + case "reset-password": return ; case "login": return ; case "register": return ; case "pricing": return ; @@ -84,11 +99,14 @@ function renderPage({ page, parts, query }) { case "overview": return ; case "reservations": return a ? : ; case "units": + if (a && b === "renewal-status") return ; + if (a && b === "deposit") return ; + if (a && b === "progress") return ; if (a && b === "renew") return ; if (a && b === "return") return ; return a ? : ; case "sent": return ; - case "payments": return ; + case "payments": return a === "history" ? : ; case "support": return a ? : ; case "profile": return ; // C07r: máy quét ở cửa kho (mô phỏng), không cần đăng nhập như thiết bị gắn tại cơ sở @@ -157,6 +175,7 @@ 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.

}
{needsLogin ? null : loadError && !ready ? (
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 e51d131..48ca9fb 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 @@ -178,6 +178,7 @@ function LocalProvider({ children }) { return { ok: true, paid: Boolean(r && ["CONFIRMED", "CHECKED_IN"].includes(r.status)), cancelled: r?.status === "CANCELLED" }; }, async accessQr(contract) { + if (ref.current.data.returns.some(r => r.contract_id === contract.contract_id && !["CANCELLED", "REJECTED"].includes(r.status))) return { ok: false, error: "QR đã hết hiệu lực do đã gửi trả kho." }; if (contract.access_issued === false || ["DRAFT", "ENDED"].includes(contract.status)) return { ok: false, error: "QR mở cửa chỉ được cấp khi hợp đồng đã được xác nhận." }; return { ok: true, access: localAccessCode(contract) }; }, @@ -190,6 +191,7 @@ function LocalProvider({ children }) { }); const now = new Date().toISOString(); if (!c) return { ok: true, scan: { result: "DENIED", unit: null, customer: null, contract: null, at: now, reason: "Mã không đúng. Kiểm tra lại mã trên ứng dụng hoặc mã dự phòng." } }; + if (d.returns.some(r => r.contract_id === c.contract_id && !["CANCELLED", "REJECTED"].includes(r.status))) return { ok: true, scan: { result: "DENIED", at: now, reason: "QR đã hết hiệu lực do đã gửi trả kho." } }; if (c.status === "ENDED") return { ok: true, scan: { result: "DENIED", unit: c.unit_number, customer: d.user.full_name, contract: c.contract_id, at: now, reason: "Mã đã hết hiệu lực — hợp đồng đã trả kho." } }; if (c.access_issued === false || c.start_date > localDate(new Date())) return { ok: true, scan: { result: "DENIED", unit: c.unit_number, customer: d.user.full_name, contract: c.contract_id, at: now, reason: "Chưa đến ngày bắt đầu hợp đồng hoặc mã chưa được cấp." } }; if (c.end_date <= localDate(new Date())) return { ok: true, scan: { result: "DENIED", unit: c.unit_number, customer: d.user.full_name, contract: c.contract_id, at: now, reason: "Hợp đồng đã quá hạn. Vui lòng gia hạn hoặc liên hệ cơ sở." } }; @@ -654,6 +656,7 @@ function ApiProvider({ children }) { if (pendingRenewal(d, c.contract_id)) return fail("Hợp đồng đang có yêu cầu gia hạn."); if (p.date < localDate(new Date())) return fail("Ngày hẹn không được ở quá khứ."); await api.requestMoveOut(c.api_id, { date: p.date, slot: p.slot, note: p.notes }); + updateOverlay(o => ({ ...o, returns: [{ return_id: `TK-${c.api_id}`, contract_id: c.contract_id, date: p.date, slot: p.slot, notes: p.notes, status: "PENDING" }, ...o.returns.filter(r => r.contract_id !== c.contract_id)] })); remember("Đã đặt lịch trả kho", `Kho ${c.unit_number} · ${p.date} (${p.slot || "giờ hành chính"})`, `units/${c.contract_id}`, `Lịch trả kho ${c.unit_number} đã được ghi nhận`); await loadCustomer(); return { ok: true, return_id: `TK-${c.api_id}` }; @@ -663,6 +666,13 @@ function ApiProvider({ children }) { return out.error ? fail(out.error.message, out.error.code) : { ok: true, ...out.result }; } // 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."); + await api.chooseRenewalCounter(renewal.api_id); + await loadCustomer(); + return { ok: true }; + } case "CHOOSE_FEE_AT_COUNTER": { const rows = d.ledger.filter((l) => p.refs.includes(l.ref) && l.fee && ["UNPAID", "AT_COUNTER"].includes(l.status)); if (!rows.length) return fail("Không còn khoản phí cần thanh toán.", "NOT_FOUND"); @@ -735,6 +745,7 @@ function ApiProvider({ children }) { }), accessQr: (contract) => guard(async () => { + if (refs.current.data.returns?.some(r => r.contract_id === contract.contract_id && !["CANCELLED", "REJECTED"].includes(r.status))) return { ok: false, error: "QR đã hết hiệu lực do đã gửi trả kho." }; const access = normAccess(await api.accessQr(contract.api_id)); return access ? { ok: true, access } : fail("Máy chủ chưa trả mã mở cửa."); }), 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 6c71d28..1744653 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 @@ -186,6 +186,11 @@ const handlers = { // PayOS báo đã thanh toán (webhook ở backend; chế độ trình duyệt tự gọi để mô phỏng). // reservation_id → đơn đặt chỗ đã trả tiền thuê + cọc; ref → khoản gia hạn ở C11. // C11fc → C11fcp: khách chọn trả phí phát sinh tại quầy; công nợ chỉ giảm khi nhân viên xác nhận đã thu (S09f) + CHOOSE_RENEWAL_AT_COUNTER(state, { renewal_id }) { + const r = state.renewals.find(x => x.renewal_id === renewal_id); + if (!r || r.status !== "APPROVED") fail("Yêu cầu chưa được duyệt hoặc đã được thanh toán."); + return { state: { ...state, renewals: state.renewals.map(x => x === r ? { ...x, at_counter: true } : x) }, result: { renewal_id } }; + }, CHOOSE_FEE_AT_COUNTER(state, { refs }) { const rows = state.ledger.filter((l) => refs.includes(l.ref) && l.fee && ["UNPAID", "AT_COUNTER"].includes(l.status)); if (!rows.length) fail("Không còn khoản phí cần thanh toán.", "NOT_FOUND"); @@ -337,7 +342,7 @@ const handlers = { status: "PENDING", note: "Dọn hết đồ, trả thẻ / chìa khóa và có mặt để kiểm tra cùng nhân viên.", }; - let next = { ...state, returns: [ret, ...state.returns], appointments: [appointment, ...state.appointments] }; + let next = { ...state, returns: [ret, ...state.returns], appointments: [appointment, ...state.appointments], contracts: state.contracts.map(x => x.contract_id === c.contract_id ? { ...x, access_issued: false } : x) }; next = notify(next, "Đã gửi lịch trả kho", `Kho ${c.unit_number} · ${dateLabel(p.date)} · ${p.slot}. Chờ cơ sở xác nhận.`, "payments", ctx.now); next = log(next, `Yêu cầu trả kho ${c.unit_number} đã gửi — chờ xác nhận`, "amber", ctx.now); return { state: next, result: { return_id: ret.return_id } }; diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/PasswordResetPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/PasswordResetPage.jsx new file mode 100644 index 0000000..0154283 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/PasswordResetPage.jsx @@ -0,0 +1,15 @@ +import React, { useState } from "react"; +import { Button, Field, LinkButton, Notice, PageHeader } from "../../shared/components/UI.jsx"; +import { isEmail } from "../../shared/utils/format.js"; +import { passwordResetApi } from "./api/passwordResetApi.js"; + +export function PasswordResetPage() { + const [email, setEmail] = useState(""), [code, setCode] = useState(""), [password, setPassword] = useState(""), [confirm, setConfirm] = useState(""); + const [step, setStep] = useState("email"), [busy, setBusy] = useState(false), [error, setError] = useState(""), [demoCode, setDemoCode] = useState(""); + const sendCode = async () => { if (!isEmail(email)) return setError("Nhập email hợp lệ."); setBusy(true); setError(""); try { const res = await passwordResetApi.request(email.trim()); setDemoCode(res.demoCode || ""); setStep("code"); } catch (e) { setError(e.message); } finally { setBusy(false); } }; + const reset = async e => { e.preventDefault(); if (!/^\d{6}$/.test(code) || password.length < 8 || password !== confirm) return setError("Nhập mã 6 số, mật khẩu tối thiểu 8 ký tự và xác nhận khớp nhau."); setBusy(true); setError(""); try { await passwordResetApi.confirm({ email: email.trim(), code, newPassword: password }); setStep("done"); } catch (e) { setError(e.message); } finally { setBusy(false); } }; + return
+ {step === "email" ?
{ e.preventDefault(); sendCode(); }}> setEmail(e.target.value)} />
: step === "code" ?

Nếu email đã đăng ký, mã xác nhận đã được gửi tới {email}.

{demoCode && Chỉ trong API mô phỏng · Không gửi email thật. Mã thử nghiệm: {demoCode}} setCode(e.target.value)} /> setPassword(e.target.value)} /> setConfirm(e.target.value)} />
: Mật khẩu đã được cập nhật. Hãy đăng nhập bằng mật khẩu mới.} + {error && {error}}Về đăng nhập +
; +} diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/RegisterPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/RegisterPage.jsx index f5f2d07..4f4d710 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/RegisterPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/RegisterPage.jsx @@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react"; // Các thành phần giao diện dùng chung: // Button: nút bấm; Field: nhãn, ô nhập và thông báo lỗi; Icon: biểu tượng. -import { Button, Field, Icon } from "../../shared/components/UI.jsx"; +import { Button, Field, Icon, Modal, Notice } from "../../shared/components/UI.jsx"; // go(): chuyển trang bằng code. // href(): tạo đường dẫn dạng #/... để dùng trong thẻ . @@ -51,14 +51,15 @@ export function RegisterPage({ query }) { // busy = true khi đang chờ kết quả đăng ký. // Giao diện dùng giá trị này để khóa nút và đổi nội dung nút. const [busy, setBusy] = useState(false); + const [success, setSuccess] = useState(false); // Nếu người dùng đã đăng nhập thì chuyển khỏi trang đăng ký. // Effect chạy sau lần render đầu và khi authed hoặc next thay đổi. // replace: true thay thế mục hiện tại trong lịch sử trình duyệt, // giúp nút Back không quay lại đúng mục trang đăng ký vừa bị thay thế. useEffect(() => { - if (authed) go(next, { replace: true }); - }, [authed, next]); + if (authed && !busy && !success) go(next, { replace: true }); + }, [authed, next, busy, success]); /* * Cập nhật một ô nhập. @@ -100,7 +101,7 @@ export function RegisterPage({ query }) { if (!res.ok) return setErrors(res.errors); // Chỉ chuyển trang tại đây khi kết quả có ok = true. - go(next); + setSuccess(true); }; return ( @@ -171,6 +172,7 @@ export function RegisterPage({ query }) { Đã có tài khoản? Đăng nhập

+ {success && go(next)}>Tài khoản khách hàng đã được tạo. Bạn đã được đăng nhập.}
); } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/api/passwordResetApi.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/api/passwordResetApi.js new file mode 100644 index 0000000..5499320 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/api/passwordResetApi.js @@ -0,0 +1,10 @@ +import { request } from "../../../shared/api/httpClient.js"; + +async function call(path, body) { + try { return await request(path, { method: "POST", body, auth: false }); } + catch (error) { if ([404, 405].includes(error.status)) throw new Error("Chức năng đặt lại mật khẩu bằng mã chưa được hỗ trợ. Vui lòng liên hệ quản trị viên hoặc nhân viên cơ sở."); throw error; } +} +export const passwordResetApi = { + request: email => call("/api/auth/password-reset/request", { email }), + confirm: body => call("/api/auth/password-reset/confirm", body), +}; diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/components/ForgotPasswordDialog.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/components/ForgotPasswordDialog.jsx index 5f9c492..e81d182 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/components/ForgotPasswordDialog.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/auth/components/ForgotPasswordDialog.jsx @@ -1,66 +1,9 @@ -import React, { useState } from "react"; -import { Button, Field, Modal } from "../../../shared/components/UI.jsx"; -import { isEmail } from "../../../shared/utils/format.js"; -import { useApp } from "../../../app/state/AppProvider.jsx"; +import React from "react"; +import { Button, LinkButton, Modal } from "../../../shared/components/UI.jsx"; export function ForgotPassword({ onClose }) { - // Kiểm tra ứng dụng có hỗ trợ chức năng quên mật khẩu hay không. - // Nếu chưa hỗ trợ thì hướng dẫn người dùng liên hệ nhân viên. - const { supports } = useApp(); - - // Lưu email người dùng đang nhập. - const [email, setEmail] = useState(""); - - // Thông báo lỗi hiện bên dưới ô email. - const [error, setError] = useState(""); - - // Khi sent = true, ẩn form và hiện thông báo hướng dẫn. - const [sent, setSent] = useState(false); - - const submit = (e) => { - // Giữ nguyên trang hiện tại khi người dùng gửi form. - e.preventDefault(); - - // Email sai định dạng thì báo lỗi và dừng tại đây. - if (!isEmail(email)) return setError("Nhập email hợp lệ để nhận hướng dẫn."); - - // Hiện tại chỉ đổi trạng thái giao diện, chưa gọi API gửi email. - // Vì vậy, thấy thông báo thành công chưa có nghĩa email đã được gửi. - setSent(true); - }; - - // Hộp thoại hiển thị theo 3 trường hợp: - // 1. Chưa hỗ trợ quên mật khẩu: hướng dẫn liên hệ nhân viên. - // 2. Đã gửi form hợp lệ: hiện thông báo hướng dẫn đặt lại mật khẩu. - // 3. Còn lại: hiện form nhập email. - // - // onClose được truyền từ component cha để đóng hộp thoại. - // Form dùng noValidate để tự kiểm tra email bằng isEmail ở trên. - // Khi người dùng sửa email, onChange cập nhật giá trị và xóa lỗi cũ. - return ( - - {!supports.forgotPassword ? ( - <> -

Vui lòng liên hệ quản trị viên hoặc nhân viên cơ sở SafeSpace để được đặt lại mật khẩu.

- - - ) : sent ? ( - <> -

Nếu email đã đăng ký, SafeSpace sẽ gửi hướng dẫn đặt lại mật khẩu trong ít phút.

- - - ) : ( -
-

Nhập email đã đăng ký. Chúng tôi sẽ gửi hướng dẫn đặt lại mật khẩu.

- - { setEmail(e.target.value); setError(""); }} /> - -
- - -
-
- )} -
- ); + return +

Mở biểu mẫu để nhận mã xác nhận qua email. Nếu máy chủ chưa hỗ trợ, liên hệ quản trị viên hoặc nhân viên cơ sở.

+
Đặt lại mật khẩu
+
; } 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 0896d35..3124875 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 @@ -1,4 +1,8 @@ import React from "react"; +import { ReportExportPage } from "./reports/ReportExportPage.jsx"; +import { RentalPolicyEditorPage } from "./policies/RentalPolicyEditorPage.jsx"; +import { PolicyStatusPage } from "./policies/PolicyStatusPage.jsx"; +import { FacilityRatePage } from "./pricing/FacilityRatePage.jsx"; import { Empty, LinkButton } from "../../shared/components/UI.jsx"; import BusinessLayout from "./BusinessLayout.jsx"; import FacilityManagementPage from "./facilities/FacilityManagementPage.jsx"; @@ -14,6 +18,10 @@ export default function BusinessRoutes({ parts, query }) { let active = "business"; let body; if (!a) body = ; + else if (a === "export") { active = "business/reports"; body = ; } + else if (a === "policy-content") { active = "business/policies"; body = ; } + else if (a === "policy-status") { active = "business/policies"; body = ; } + else if (a === "rates") { active = "business/pricing"; body = ; } else if (a === "facilities") { active = "business/facilities"; 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 7a2d2ea..4d089f8 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 @@ -66,8 +66,8 @@ } /* Overrides are scoped to the business shell; other roles retain ss.css verbatim. */ -@font-face { font-family: 'Manrope'; font-style: normal; font-weight: 700; font-display: swap; src: url('../../public/fonts/manrope/manrope-latin-700-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; } -@font-face { font-family: 'Manrope'; font-style: normal; font-weight: 700; font-display: swap; src: url('../../public/fonts/manrope/manrope-vietnamese-700-normal.woff2') format('woff2'); unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; } +@font-face { font-family: 'Manrope'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/manrope/manrope-latin-700-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; } +@font-face { font-family: 'Manrope'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/manrope/manrope-vietnamese-700-normal.woff2') format('woff2'); unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; } .business-app { --bg: #f6f7f8; --purple: #7c3aed; background: var(--bg); min-height: 100vh; } .business-app .header__inner { padding-inline: 72px; } .business-app .brand { font-family: 'Manrope', sans-serif; letter-spacing: -.48px; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/PolicySettingsPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/PolicySettingsPage.jsx index 0556ab2..0774279 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/PolicySettingsPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/PolicySettingsPage.jsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { businessApi } from "../api/businessApi.js"; -import { Button, Field } from "../../../shared/components/UI.jsx"; +import { Button, Field, LinkButton } from "../../../shared/components/UI.jsx"; import { useLoad } from "../../admin/utils/adminUtils.js"; import { today } from "../../../shared/utils/format.js"; import { useApp } from "../../../app/state/AppProvider.jsx"; @@ -42,6 +42,7 @@ export default function PolicySettingsPage() { }; return

Chính sách cho thuê chung

Áp dụng cho toàn bộ cơ sở trong hệ thống, trừ khi có quy định riêng cho từng cơ sở.

+
Chính sách chi tiết khách đọcTrạng thái chính sách
{policies => <> {POLICY_SECTIONS.map(section =>

{section.title}

{section.fields.map(field => { diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/PolicyStatusPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/PolicyStatusPage.jsx new file mode 100644 index 0000000..27047fe --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/PolicyStatusPage.jsx @@ -0,0 +1,14 @@ +import React from "react"; +import { businessApi } from "../api/businessApi.js"; +import { useLoad } from "../../admin/utils/adminUtils.js"; +import { useApp } from "../../../app/state/AppProvider.jsx"; +import { useChangeFlow } from "../../../shared/components/ChangeFlowDialog.jsx"; +import { Button, PageHeader } from "../../../shared/components/UI.jsx"; +import { LoadState } from "../components/BusinessComponents.jsx"; +import { RecordCard } from "../../facility-operations/workflows/WorkflowComponents.jsx"; + +export function PolicyStatusPage() { + const { onApiError } = useApp(), load = useLoad(() => businessApi.policies({}), [], onApiError), [flow, runChange] = useChangeFlow(); + const change = async (p, remove) => { const out = await runChange({ action: remove ? "Xoá chính sách nháp" : "Ngừng áp dụng chính sách", scope: p.policyName, content: remove ? "Chỉ xoá bản DRAFT chưa áp dụng." : "Không sửa ngược các hợp đồng đang có.", perform: async () => { if (remove) { if (p.status !== "DRAFT") throw new Error("Chỉ được xoá bản nháp."); await businessApi.deletePolicy(p.policyId); } else await businessApi.deactivatePolicy(p.policyId); return true; } }); if (out.error) onApiError(out.error); load.reload(); }; + return
{rows => rows.map(p => change(p, false)}>Ngừng áp dụng : p.status === "DRAFT" ? : null}>

{p.ruleDescription}

)}
{flow}
; +} diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/RentalPolicyEditorPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/RentalPolicyEditorPage.jsx new file mode 100644 index 0000000..58d69d1 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/business/policies/RentalPolicyEditorPage.jsx @@ -0,0 +1,17 @@ +import React, { useState } from "react"; +import { Button, Field, LinkButton, Modal, Notice, PageHeader } from "../../../shared/components/UI.jsx"; +import { POLICY_SECTIONS, defaultRentalPolicy } from "../../facility-operations/workflows/workflowModel.js"; +import { useWorkflowData } from "../../facility-operations/workflows/useWorkflowData.js"; +import { useWorkflowChange, WorkflowState } from "../../facility-operations/workflows/WorkflowComponents.jsx"; + +export function RentalPolicyEditorPage() { + const load = useWorkflowData("policy"), [draft, setDraft] = useState(null), [preview, setPreview] = useState(false), [error, setError] = useState(""); + const policy = draft || load.data || defaultRentalPolicy(), [dialog, ask] = useWorkflowChange(load); + const update = (id, value) => setDraft({ ...policy, sections: { ...policy.sections, [id]: value } }); + const save = e => { e.preventDefault(); if (!(Number(policy.rate) > 0 && Number(policy.rate) <= 100) || POLICY_SECTIONS.some(([id]) => !policy.sections[id]?.trim())) return setError("Điền đủ nội dung và nhập tỷ lệ khấu trừ lớn hơn 0, tối đa 100%."); setError(""); ask("SAVE_RENTAL_POLICY", policy, "Lưu chính sách hiển thị cho khách?", "Chỉ bản đã lưu được hiển thị cho khách. Không thay đổi ngược các giao dịch đã được backend ghi nhận."); }; + return
+

Chính sách SafeSpace · Toàn hệ thống

{draft ? "Đang chỉnh sửa · Chưa lưu thay đổi" : "Bản nội dung đang hiển thị"}
setDraft({ ...policy, rate: e.target.value })} /> 0 ? `${Math.ceil(100 / policy.rate)} ngày` : "—"} />
+ {POLICY_SECTIONS.map(([id, title]) =>

{title}