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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ Theo yêu cầu nhóm, dùng src/app, src/features/<role>/<feature>, src/shared,
- Thay thế: quy định "phí hủy 10% tiền thuê" trong BACKEND-TODO (H1) và CANCEL_FEE_RATE (appReducer.js) không còn áp dụng; phải đổi theo D27. Chưa triển khai code.


## D28 — Kiểm thử giao diện C12/C12b/C13 bằng Playwright

Bổ sung @playwright/test trong devDependencies để kiểm thao tác biểu mẫu và giao diện tiến trình. Bộ kiểm thử giả lập DTO chỉ xác nhận FE; dùng thêm host Kestrel/JWT/SQLite cho HTTP và trình duyệt với backend thật. Giữ D26/D27 và endpoint vận hành chuẩn trên main. Không lưu browser binary hoặc test-results trong git. Các SVG của C12/C13 được tái sử dụng từ gói frontend Ngọc Mai đã cung cấp; phiên này không sửa Figma.
## PROCESS-2026-10-24 — Quy trình AI, Git và kiểm chứng — Áp dụng khi nhóm tích hợp bản vá

- Theo yêu cầu cập nhật quy định của thành viên ngày 24/10/2026; không khẳng định cả nhóm đã biểu quyết. Việc merge bản vá ghi nhận nhóm chấp nhận áp dụng.
Expand Down
3 changes: 3 additions & 0 deletions SafeSpace-Customer-UI/SafeSpace-Customer-UI/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ Thumbs.db
.env.local
.env.production
*.tsbuildinfo

test-results/
playwright-report/
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Nguồn: file Figma "SafeSpace - Modern UI" (section Khách hàng + Trang chủ
| C09 / C09b Trả kho | `#/units/:id/return` | `src/features/customer/contracts/RentedUnitListPage.jsx` | Ngày (lịch), khung giờ, ghi chú, đối chiếu cọc |
| C10 Yêu cầu đã gửi | `#/sent?type=&contract=` | `src/features/customer/contracts/RentedUnitListPage.jsx` | |
| 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` | Có ảnh đính kèm (tối đa 3, 5 MB); danh sách yêu cầu bên phải; khối "Phản hồi của nhân viên" từ `responses[]` của `GET /api/tickets/{id}` |
| 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" |
| 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` | |
Expand Down
2 changes: 2 additions & 0 deletions SafeSpace-Customer-UI/SafeSpace-Customer-UI/FRONTEND-MAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
| Khách hàng / Đặt chỗ — ReservationDetailPage | `src/features/customer/reservations/ReservationDetailPage.jsx` |
| Khách hàng / Đặt chỗ — ReservationListPage | `src/features/customer/reservations/ReservationListPage.jsx` |
| Khách hàng / Hỗ trợ — SupportPage | `src/features/customer/support/SupportPage.jsx` |
| Khách hàng / Tiến trình hỗ trợ — SupportTicketDetailPage | `src/features/customer/support/SupportTicketDetailPage.jsx` |
| Quản lý cơ sở / Phân bổ kho — UnitAllocationPage | `src/features/manager/allocations/UnitAllocationPage.jsx` |
| Quản lý cơ sở / Phân công — StaffAssignmentPage | `src/features/manager/assignments/StaffAssignmentPage.jsx` |
| Quản lý cơ sở / Hợp đồng / kho đang thuê — ContractListPage | `src/features/manager/contracts/ContractListPage.jsx` |
Expand All @@ -74,6 +75,7 @@
|---|---|
| Tìm cơ sở / bản đồ / chi tiết | `#/find`, `#/find/map`, `#/find/:id` |
| Đặt chỗ / thanh toán / kết quả | `#/reservations`, `#/checkout/:id`, `#/confirmation/:id` |
| Hỗ trợ / tiến trình / hồ sơ | `#/support`, `#/support/:id`, `#/profile` |
| Kho thuê / gia hạn / trả kho | `#/units`, `#/units/:id/renew`, `#/units/:id/return` |
| Nhân viên thu tiền / xác minh / nhận chìa khóa | `#/staff/reconcile`, `#/staff/verify`, `#/staff/keys` (alias cũ: `#/staff/handover`) |
| Quản lý ô / phân bổ / gia hạn | `#/manager/units`, `#/manager/allocate`, `#/manager/renewals` |
Expand Down
46 changes: 46 additions & 0 deletions SafeSpace-Customer-UI/SafeSpace-Customer-UI/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion SafeSpace-Customer-UI/SafeSpace-Customer-UI/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"type": "module",
"scripts": {
"dev:business": "node scripts/dev-business.mjs",
"test:auth-support": "playwright test",
"test:business": "node --test tests/business-frontend.test.mjs",
"dev": "vite --host 127.0.0.1",
"build": "vite build --base=./",
"preview": "vite preview --host 127.0.0.1",
"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",
"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"
Expand All @@ -22,6 +23,7 @@
"react-dom": "^19.3.0"
},
"devDependencies": {
"@playwright/test": "^1.64.1",
"vite": "^8.3.0"
},
"engines": {
Expand Down
23 changes: 23 additions & 0 deletions SafeSpace-Customer-UI/SafeSpace-Customer-UI/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineConfig } from "@playwright/test";

export default defineConfig({
testDir: "./tests",
testMatch: "auth-support.spec.js",
fullyParallel: false,
workers: 1,
reporter: "list",
use: {
baseURL: "http://127.0.0.1:5273",
browserName: "chromium",
viewport: { width: 1440, height: 922 },
launchOptions: process.env.PLAYWRIGHT_EXECUTABLE_PATH
? { executablePath: process.env.PLAYWRIGHT_EXECUTABLE_PATH, args: ["--no-sandbox", "--disable-dev-shm-usage"] }
: {},
},
webServer: {
command: "npm run dev -- --port 5273 --strictPort",
url: "http://127.0.0.1:5273",
reuseExistingServer: false,
env: { VITE_USE_API: "true", VITE_API_URL: "http://127.0.0.1:5273" },
},
});
6 changes: 4 additions & 2 deletions SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "@fontsource/inter/vietnamese-700.css";
import "@fontsource/inter/latin-800.css";
import "@fontsource/inter/vietnamese-800.css";
import "../shared/styles/ss.css";
import "../shared/styles/auth-support.css";
import React, { useEffect } from "react";
import Header from "../shared/components/Header.jsx";
import { Button, Empty, Icon, LinkButton } from "../shared/components/UI.jsx";
Expand All @@ -35,6 +36,7 @@ import FacilityOperationsRoutes from "../features/facility-operations/FacilityOp
import { OpsProvider } from "../features/facility-operations/state/FacilityOperationsProvider.jsx";
import ReservationListPage from "../features/customer/reservations/ReservationListPage.jsx";
import SupportPage from "../features/customer/support/SupportPage.jsx";
import SupportTicketDetailPage from "../features/customer/support/SupportTicketDetailPage.jsx";
import { RenewalRequestPage } from "../features/customer/contracts/RenewalRequestPage.jsx";
import { ReturnRequestPage } from "../features/customer/contracts/ReturnRequestPage.jsx";
import { RequestSentPage } from "../features/customer/requests/RequestSentPage.jsx";
Expand Down Expand Up @@ -87,7 +89,7 @@ function renderPage({ page, parts, query }) {
return a ? <RentedUnitDetailPage id={a} /> : <RentedUnitListPage />;
case "sent": return <RequestSentPage query={query} />;
case "payments": return <PaymentListPage />;
case "support": return <SupportPage query={query} />;
case "support": return a ? <SupportTicketDetailPage id={a} /> : <SupportPage query={query} />;
case "profile": return <CustomerProfilePage />;
// 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ở
case "door": return <DoorScannerPage query={query} />;
Expand Down Expand Up @@ -152,7 +154,7 @@ function Shell() {
) : null;

return (
<div className={`app${!isAdminPage && !isOpsPage && !isBusinessPage ? " customer-app" : ""}`}>
<div className={`app${!isAdminPage && !isOpsPage && !isBusinessPage ? " customer-app" : ""}${["profile", "support"].includes(route.page) ? " app--auth-support" : ""}`}>
<a className="skip" href="#main" onClick={(e) => { e.preventDefault(); document.getElementById("main")?.focus(); }}>Chuyển đến nội dung</a>
{!(isAdminPage && !adminBody && authed) && !(isOpsPage && authed && opsAllowed) && !(isBusinessPage && !businessBody && authed) && <Header page={route.page} />}
<div id="main" tabIndex={-1} key={route.raw.split("?")[0]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ function LocalProvider({ children }) {

// =====================================================================
// Chế độ API (VITE_USE_API=true)
// Luồng backend đã có → gọi API. Luồng backend chưa có (trả kho, lịch trả kho,
// thông báo, đổi tên hiển thị) → lưu trong trình duyệt theo từng tài khoản ("overlay").
// Hồ sơ, mật khẩu, hỗ trợ và trả kho gọi API thật.
// Thông báo phía khách và dữ liệu phụ dùng overlay riêng theo từng tài khoản.
// =====================================================================
function readSession() {
const s = readJson(SESSION_KEY);
Expand Down Expand Up @@ -304,13 +304,19 @@ function ApiProvider({ children }) {
}, []);

const loadCustomer = useCallback(async () => {
const activeSession = refs.current.session;
const [reservations, contracts, tickets] = await Promise.all([api.reservations(), api.contracts(), api.tickets()]);
const [reservationDetails, contractDetails, ticketDetails] = await Promise.all([
Promise.all(reservations.filter((r) => r.status !== "CANCELLED").map((r) => api.reservation(r.reservationId).catch(() => null))),
Promise.all(contracts.map((c) => api.contract(c.contractId).catch(() => ({ ...c, payments: [], renewals: [] })))),
Promise.all(tickets.map((t) => api.ticket(t.ticketId).catch(() => t))),
Promise.all(tickets.map((t) => api.ticket(t.ticketId).catch(e => {
if (e.status === 401) throw e;
const previous = refs.current.session?.token === activeSession?.token
? refs.current.remote?.tickets.find(x => x.ticketId === t.ticketId) : null;
return { ...previous, ...t, responsesError: true };
}))),
]);
if (!refs.current.session) return;
if (!activeSession || refs.current.session?.token !== activeSession.token) return;
const next = {
reservations,
reservationDetails: Object.fromEntries(reservationDetails.filter(Boolean).map((d) => [d.reservationId, d])),
Expand Down Expand Up @@ -352,19 +358,38 @@ function ApiProvider({ children }) {
[endSession],
);

const applyProfile = useCallback((profile, activeSession) => {
if (!activeSession || refs.current.session?.token !== activeSession.token) return false;
if (String(profile.userId) !== String(activeSession.user.userId)) return false;
const next = { ...refs.current.session, user: { ...refs.current.session.user, ...profile } };
refs.current.session = next;
setStorageError(!writeJson(SESSION_KEY, next));
setSession(next);
updateOverlay(o => ({ ...o, name: null }));
return true;
}, [updateOverlay]);

const loadProfile = useCallback(async () => {
const current = refs.current.session;
if (!current) return;
const profile = await api.getProfile();
applyProfile(profile, current);
}, [applyProfile]);

const loadAll = useCallback(async () => {
setLoadError(null);
try {
await loadCatalog();
if (refs.current.session) {
await loadProfile();
if (isAdminRoles(refs.current.session.roles) || isOpsRoles(refs.current.session.roles) || isBusinessRoles(refs.current.session.roles)) setRemote(EMPTY_REMOTE);
else await loadCustomer();
}
} catch (e) {
if (e instanceof ApiError && e.status === 401) endSession("expired");
else setLoadError(e?.message || "Không tải được dữ liệu.");
}
}, [loadCatalog, loadCustomer, endSession]);
}, [loadCatalog, loadCustomer, loadProfile, endSession]);

useEffect(() => {
loadAll();
Expand Down Expand Up @@ -402,12 +427,13 @@ function ApiProvider({ children }) {
refs.current.overlay = saved;
setOverlay(saved);
setSession(next);
await loadProfile();
if (isAdminRoles(next.roles) || isOpsRoles(next.roles) || isBusinessRoles(next.roles)) {
refs.current.remote = EMPTY_REMOTE;
setRemote(EMPTY_REMOTE);
} else await loadCustomer();
},
[loadCustomer],
[loadCustomer, loadProfile],
);

const login = useCallback(
Expand Down Expand Up @@ -607,20 +633,19 @@ function ApiProvider({ children }) {
return { ok: true };
}
case "CHANGE_PASSWORD": {
await api.changePassword({ currentPassword: p.current_password, newPassword: p.new_password });
notify("Đã đổi mật khẩu thành công.");
try {
await api.changePassword({ currentPassword: p.current, newPassword: p.next });
} catch (e) {
if (e instanceof ApiError && (e.data?.code === "BAD_PASSWORD" || (e.status === 400 && /mật khẩu hiện tại/i.test(e.message)))) return fail(e.message, "BAD_PASSWORD");
throw e;
}
return { ok: true };
}
case "UPDATE_NAME": {
const profile = await api.updateProfile({ fullName: p.name, phone: session?.user?.phone || null });
if (session) {
const updatedUser = { ...session.user, fullName: profile.fullName };
const updatedSession = { ...session, user: updatedUser };
writeJson(SESSION_KEY, updatedSession);
refs.current.session = updatedSession;
setSession(updatedSession);
}
runLocal(type, p);
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() });
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 };
}
case "REQUEST_RETURN": {
Expand All @@ -644,7 +669,7 @@ function ApiProvider({ children }) {
return handleError(e);
}
},
[loadCustomer, updateOverlay, remember, runLocal, handleError],
[loadCustomer, updateOverlay, remember, runLocal, handleError, applyProfile],
);

const checkAvailability = useCallback(async ({ facility_id, offer, start_date, months }) => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading