diff --git a/DECISIONS.md b/DECISIONS.md index c20e8b0..307b6ae 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -198,6 +198,9 @@ Theo yêu cầu nhóm, dùng src/app, src/features//, 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. diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/.gitignore b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/.gitignore index e5fb60a..d49f9e0 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/.gitignore +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/.gitignore @@ -8,3 +8,6 @@ Thumbs.db .env.local .env.production *.tsbuildinfo + +test-results/ +playwright-report/ 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 a5e6a13..8978e68 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/CUSTOMER-FLOW-COVERAGE.md +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/CUSTOMER-FLOW-COVERAGE.md @@ -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` | | diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/FRONTEND-MAP.md b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/FRONTEND-MAP.md index c1f2add..bc1c1b2 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/FRONTEND-MAP.md +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/FRONTEND-MAP.md @@ -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` | @@ -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` | diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package-lock.json b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package-lock.json index 124f8cc..815f6da 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package-lock.json +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package-lock.json @@ -15,6 +15,7 @@ "react-dom": "^19.3.0" }, "devDependencies": { + "@playwright/test": "^1.64.1", "vite": "^8.3.0" }, "engines": { @@ -40,6 +41,22 @@ "url": "https://github.com/sponsors/oxc-project" } }, + "node_modules/@playwright/test": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.64.1.tgz", + "integrity": "sha512-IaYGml/nSOiZWROfPtuIL7neuu9qDOZ3TNvNljUIrhDMxiGTgPjzj/g9p9RxpS2tSepPDRY+UwAaEeiKtUvIAg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.64.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/@rolldown/binding-android-arm-eabi": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.8.tgz", @@ -822,6 +839,35 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/playwright": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.64.1.tgz", + "integrity": "sha512-HCrVhHr5QQuwYoswEUGTb7gGp522yflbv/ST8nF4sFWGuLjQCt17Q/EubpGGSNKYn1tsTCPZxqHhHCfVURu7UA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.64.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/playwright-core": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz", + "integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/pngjs": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz", diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package.json b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package.json index be29a32..93791f0 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package.json +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/package.json @@ -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" @@ -22,6 +23,7 @@ "react-dom": "^19.3.0" }, "devDependencies": { + "@playwright/test": "^1.64.1", "vite": "^8.3.0" }, "engines": { diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/playwright.config.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/playwright.config.js new file mode 100644 index 0000000..b8b85e6 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/playwright.config.js @@ -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" }, + }, +}); 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 08d0a1f..f4ed57a 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/app/App.jsx @@ -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"; @@ -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"; @@ -87,7 +89,7 @@ function renderPage({ page, parts, query }) { return a ? : ; case "sent": return ; case "payments": return ; - case "support": return ; + 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ở case "door": return ; @@ -152,7 +154,7 @@ function Shell() { ) : null; return ( -
+
{ e.preventDefault(); document.getElementById("main")?.focus(); }}>Chuyển đến nội dung {!(isAdminPage && !adminBody && authed) && !(isOpsPage && authed && opsAllowed) && !(isBusinessPage && !businessBody && authed) &&
}
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 78f606f..012507e 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 @@ -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); @@ -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])), @@ -352,11 +358,30 @@ 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(); } @@ -364,7 +389,7 @@ function ApiProvider({ children }) { 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(); @@ -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( @@ -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": { @@ -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 }) => { diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/brand.svg b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/brand.svg new file mode 100644 index 0000000..52ecefe --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/brand.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/notification.svg b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/notification.svg new file mode 100644 index 0000000..22246d8 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/notification.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/timeline-blue.svg b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/timeline-blue.svg new file mode 100644 index 0000000..90afc78 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/timeline-blue.svg @@ -0,0 +1,3 @@ + + + diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/timeline-green.svg b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/timeline-green.svg new file mode 100644 index 0000000..9ccd061 --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/timeline-green.svg @@ -0,0 +1,3 @@ + + + diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/timeline-pending.svg b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/timeline-pending.svg new file mode 100644 index 0000000..7e2bd0b --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/assets/customer/auth-support/timeline-pending.svg @@ -0,0 +1,3 @@ + + + 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 38b326d..27b90e8 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,4 +1,4 @@ -import React, { useState } from "react"; +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"; @@ -12,13 +12,29 @@ export default function CustomerProfilePage() { const [pw, setPw] = useState({ current: "", next: "", confirm: "" }); const [pwErrors, setPwErrors] = useState({}); const [dialog, setDialog] = useState(null); + const [savingName, setSavingName] = useState(false); + const [savingPassword, setSavingPassword] = useState(false); + const namePending = useRef(false); + const passwordPending = useRef(false); + useEffect(() => setName(user.full_name), [user.user_id, user.full_name]); const saveName = async (e) => { e.preventDefault(); - const res = await dispatch("UPDATE_NAME", { name }); - 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 (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ự."); + namePending.current = true; + setSavingName(true); + setNameError(""); + try { + const res = await dispatch("UPDATE_NAME", { name: fullName }); + 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." }); + } finally { + namePending.current = false; + setSavingName(false); + } }; const setPwField = (k, v) => { @@ -27,6 +43,7 @@ export default function CustomerProfilePage() { }; const changePassword = async (e) => { e.preventDefault(); + if (passwordPending.current) return; const err = {}; if (!pw.current) err.current = "Vui lòng nhập mật khẩu hiện tại."; if (!pw.next) err.next = "Vui lòng nhập mật khẩu mới."; @@ -37,11 +54,23 @@ export default function CustomerProfilePage() { err.confirm = "Mật khẩu xác nhận chưa khớp"; err.confirmHint = "Nhập lại đúng mật khẩu mới để tiếp tục."; } + if (!pw.current && !pw.next && !pw.confirm) { + err.summary = "Bạn chưa nhập đủ thông tin"; + err.summaryHint = "Vui lòng nhập mật khẩu hiện tại, mật khẩu mới và xác nhận mật khẩu mới."; + } if (Object.keys(err).length) return setPwErrors(err); - const res = await dispatch("CHANGE_PASSWORD", { current: pw.current, next: pw.next }); - if (!res.ok) return setPwErrors(res.code === "BAD_PASSWORD" ? { current: res.error } : res.code === "UNSUPPORTED" ? { form: res.error } : { next: res.error }); - setPw({ current: "", next: "", confirm: "" }); - setDialog({ title: "Đổi mật khẩu thành công", message: "Mật khẩu mới của bạn đã được cập nhật." }); + passwordPending.current = true; + setSavingPassword(true); + setPwErrors({}); + try { + const res = await dispatch("CHANGE_PASSWORD", { current: pw.current, next: pw.next }); + if (!res.ok) return setPwErrors(res.code === "BAD_PASSWORD" ? { current: res.error } : { form: res.error }); + setPw({ current: "", next: "", confirm: "" }); + setDialog({ title: "Đổi mật khẩu thành công", message: "Mật khẩu mới của bạn đã được cập nhật." }); + } finally { + passwordPending.current = false; + setSavingPassword(false); + } }; return ( @@ -51,7 +80,7 @@ export default function CustomerProfilePage() {

Thông tin cá nhân

- { setName(e.target.value); setNameError(""); }} /> + { setName(e.target.value); setNameError(""); }} /> @@ -61,24 +90,26 @@ export default function CustomerProfilePage() {

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.

- +
-
+

Đổi mật khẩu

- setPwField("current", e.target.value)} /> + setPwField("current", e.target.value)} /> - setPwField("next", e.target.value)} /> + setPwField("next", e.target.value)} /> - setPwField("confirm", e.target.value)} /> + setPwField("confirm", e.target.value)} /> {pwErrors.confirmHint &&

{pwErrors.confirmHint}

} + {pwErrors.summary && <>

{pwErrors.summary}

{pwErrors.summaryHint}

} + {!Object.keys(pwErrors).length && <>

Xác nhận để tránh nhập sai

Mật khẩu mới và phần xác nhận phải giống nhau.

} {!supports.changePassword &&

Đổi mật khẩu đang tạm ngưng trên hệ thống. Liên hệ quản trị viên SafeSpace nếu cần đặt lại mật khẩu.

} {pwErrors.form &&

{pwErrors.form}

} - +
+ Xem chi tiết {t.status === "OPEN" && ( )} @@ -79,7 +52,8 @@ function TicketCard({ t }) { } export default function SupportPage({ query }) { - const { data, dispatch, mode } = useApp(); + const { data, dispatch, mode, retry, loadError } = useApp(); + const [refreshing, setRefreshing] = useState(false); const [busy, setBusy] = useState(false); const preContract = query.get("contract"); const preTopic = query.get("topic"); @@ -129,7 +103,13 @@ export default function SupportPage({ query }) { return (
- + + {mode === "api" && } + + {loadError && {loadError}}
diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/support/SupportTicketDetailPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/support/SupportTicketDetailPage.jsx new file mode 100644 index 0000000..9f6e12e --- /dev/null +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/customer/support/SupportTicketDetailPage.jsx @@ -0,0 +1,57 @@ +import React from "react"; +import { Button, Empty, Icon, LinkButton, Notice, StatusTag } from "../../../shared/components/UI.jsx"; +import { useApp } from "../../../app/state/AppProvider.jsx"; +import { facilityOf } from "../../../app/state/appSelectors.js"; +import { href } from "../../../app/router.js"; +import { dateTimeLabel } from "../../../shared/utils/format.js"; +import { TICKET_STATUS, TICKET_TOPICS } from "../../../shared/utils/status.js"; +import bluePoint from "../../../assets/customer/auth-support/timeline-blue.svg"; +import greenPoint from "../../../assets/customer/auth-support/timeline-green.svg"; +import pendingPoint from "../../../assets/customer/auth-support/timeline-pending.svg"; + +function TimelineStep({ title, at, by, pending, success, children }) { + return
  • +
    +
    +
    {title}{[at && dateTimeLabel(at), by].filter(Boolean).map((text) => ` · ${text}`).join("")}
    + {children} +
    +
  • ; +} + +export default function SupportTicketDetailPage({ id }) { + const { data, retry, loadError } = useApp(); + const ticket = data.tickets.find((t) => t.ticket_id === id || String(t.api_id) === id); + if (!ticket) return
    Quay lại Hỗ trợ
    ; + const contract = data.contracts.find((c) => c.contract_id === ticket.contract_id); + const facility = contract && facilityOf(data, contract.facility_id, contract.facility_name); + const replies = ticket.responses || []; + return
    + Quay lại Hỗ trợ +

    {ticket.ticket_id} · {ticket.title || TICKET_TOPICS[ticket.topic]?.title}

    +

    Gửi lúc {dateTimeLabel(ticket.created_at)}

    +
    +

    Tiến trình xử lý

    +
    +
    Loại sự cố
    {TICKET_TOPICS[ticket.topic]?.label || ticket.topic}
    +
    Kho
    {[contract?.unit_number || ticket.unit_number, facility?.name].filter(Boolean).join(" · ") || "Chưa có thông tin kho"}
    +
    Nhân viên phản hồi
    {replies.at(-1)?.by || "Chưa có phản hồi"}
    +
    + {(ticket.responses_error || loadError) && {loadError || "Chưa tải được phản hồi. Vui lòng cập nhật lại yêu cầu."}} + +
      + +

      {ticket.description}

      + {ticket.attachments?.length > 0 &&
      Ảnh đính kèm ({ticket.attachments.length})
        {ticket.attachments.map((name, i) =>
      • {name}
      • )}
      } +
      + + {replies.map((reply, index) => +
      Phản hồi của nhân viên

      {reply.text}

      +
      )} + {replies.length === 0 && !ticket.responses_error && } + +
    +

    Chỉ hủy được yêu cầu khi nhân viên chưa tiếp nhận. Nếu đang đứng tại cổng cơ sở, liên hệ nhân viên trực để được hỗ trợ ngay.

    +
    +
    ; +} diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/api/facilityOperationsApi.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/api/facilityOperationsApi.js index 224038d..3dcdf92 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/api/facilityOperationsApi.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/facility-operations/api/facilityOperationsApi.js @@ -30,6 +30,7 @@ export async function loadBoard(role) { } } const data = fromApi(res); + const lists = ["payments", "allocations", "verifications", "handovers", "returns", "tickets", "renewals", "contracts", "assignments", "units", "staff"]; return { version: 1, log: [], @@ -37,6 +38,8 @@ export async function loadBoard(role) { renewals: [], contracts: [], assignments: [], units: [], staff: [], revenue: { months: [], by_type: [], as_of: null }, ...data, + ...Object.fromEntries(lists.map(key => [key, Array.isArray(data[key]) ? data[key] : []])), + revenue: data.revenue ?? { months: [], by_type: [], as_of: null }, }; } diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/support/StaffSupportPage.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/support/StaffSupportPage.jsx index dbcc165..5a7c286 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/support/StaffSupportPage.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/features/staff/support/StaffSupportPage.jsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useRef, useState } from "react"; import { Select } from "../../../shared/components/Pickers.jsx"; import { Button, Empty, Field, LinkButton, Notice, Tag } from "../../../shared/components/UI.jsx"; import { dateTimeLabel } from "../../../shared/utils/format.js"; @@ -24,6 +24,8 @@ export function StaffSupportPage({ query }) { const [reason, setReason] = useState(""); const [credentialBusy, setCredentialBusy] = useState(false); const [err, setErr] = useState(""); + const [busy, setBusy] = useState(false); + const pending = useRef(false); if (!t) return (
    @@ -35,9 +37,20 @@ export function StaffSupportPage({ query }) { const assignee = ops.staff.find((s) => s.staff_id === t.assignee); const submit = async (e) => { e.preventDefault(); - const r = await run("TICKET_RESPONSE", { id: t.id, note, next, staff: me.staff_id }, `Đã lưu phản hồi ${t.id}`); - if (!r.ok) return setErr(r.error); - go("staff/done?kind=support"); + if (pending.current) return; + if (!note.trim()) return setErr("Vui lòng nhập nội dung phản hồi."); + pending.current = true; + setBusy(true); + setErr(""); + try { + const r = await run("TICKET_RESPONSE", { id: t.id, note: note.trim(), next, staff: me.staff_id }, `Đã lưu phản hồi ${t.id}`); + if (r.cancelled) return; + if (!r.ok) return setErr(r.error); + go("staff/done?kind=support"); + } finally { + pending.current = false; + setBusy(false); + } }; const reissue = async () => { if (!reason.trim()) return setErr("Nhập lý do cấp lại mã hoặc chìa khóa."); @@ -77,7 +90,7 @@ export function StaffSupportPage({ query }) { {NEXT_STATES.map(([k, l]) => )} - +

    Cấp lại QR, PIN & chìa khóa

    Kiểm tra danh tính khách trước khi cấp lại. QR/PIN cũ cùng loại sẽ bị vô hiệu hóa. Chìa khóa nhận tại quầy.

    diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/api/apiMappers.js b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/api/apiMappers.js index b0101d2..939a629 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/api/apiMappers.js +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/api/apiMappers.js @@ -5,6 +5,7 @@ import { localDate, timeoutLabel } from "../utils/format.js"; import { TICKET_TOPICS } from "../utils/status.js"; const TICKET_TOPIC_KEYS = Object.keys(TICKET_TOPICS); +const TICKET_TOPIC_ALIASES = { ACCESS_CARD: "ACCESS", ACCESS_CODE: "ACCESS", STORED_ITEM: "ITEMS" }; // ASP.NET trả DateTime đọc từ DB không kèm múi giờ nhưng thực chất là UTC → thêm "Z" export function parseUtc(value) { @@ -159,7 +160,7 @@ export function composeData({ catalog, remote, overlay: ov, session, timeoutSeco username: session.user.username, full_name: overlay.name || session.user.fullName, email: session.user.email, - phone: overlay.phone || "", + phone: session.user.phone ?? overlay.phone ?? "", } : null; const base = { @@ -362,19 +363,24 @@ export function composeData({ catalog, remote, overlay: ov, session, timeoutSeco ticket_id: ticketCode(t.ticketId), api_id: t.ticketId, contract_id: contractCodeById.get(t.contractId) || null, - topic: TICKET_TOPIC_KEYS.includes(t.issueType) ? t.issueType : "OTHER", + topic: TICKET_TOPIC_ALIASES[t.issueType] || (TICKET_TOPIC_KEYS.includes(t.issueType) ? t.issueType : "OTHER"), title: t.title, description: t.description || "", attachments: overlay.attachments[t.ticketId] || [], status, staff_note: TICKET_NOTE[status], + responses_error: Boolean(t.responsesError), + assigned_at: isoOf(t.assignedAt), + resolved_at: isoOf(t.resolvedAt), + closed_at: isoOf(t.closedAt), + raw_status: t.status, // C12: phản hồi của nhân viên (S05). Backend trả mảng responses trong GET /api/tickets/{id} (BACKEND-TODO.md mục R) responses: (t.responses || []) .map((x) => ({ text: x.message ?? x.note ?? x.content ?? "", by: x.staffName ?? x.responderName ?? null, at: isoOf(x.createdAt ?? x.respondedAt) })) .filter((x) => x.text), unit_number: t.contractUnitNumber || null, created_at: isoOf(t.createdAt), - updated_at: isoOf(t.closedAt || t.resolvedAt || t.assignedAt || t.createdAt), + updated_at: isoOf(t.responses?.at(-1)?.createdAt || t.closedAt || t.resolvedAt || t.assignedAt || t.createdAt), }; }); diff --git a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/Header.jsx b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/Header.jsx index ad8df27..756a5ac 100644 --- a/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/Header.jsx +++ b/SafeSpace-Customer-UI/SafeSpace-Customer-UI/src/shared/components/Header.jsx @@ -5,6 +5,8 @@ import { useApp } from "../../app/state/AppProvider.jsx"; import PendingBadge from "./PendingBadge.jsx"; import StickyHeader from "./StickyHeader.jsx"; import { Icon } from "./UI.jsx"; +import accountBrand from "../../assets/customer/auth-support/brand.svg"; +import accountNotification from "../../assets/customer/auth-support/notification.svg"; const PUBLIC_LINKS = [ ["home", "Trang chủ"], @@ -102,6 +104,7 @@ export default function Header({ page }) { const anchor = useRef(null); const customer = authed && roles.includes("CUSTOMER"); const unread = customer ? unreadCount(data) : 0; + const accountScreen = ["profile", "support"].includes(page); useEffect(() => setOpen(false), [page]); @@ -110,7 +113,7 @@ export default function Header({ page }) {
    - + {accountScreen ? : } SafeSpace