From 7bed3638221a82fc102f325ddec022ade9776c52 Mon Sep 17 00:00:00 2001 From: RedAvocado Date: Thu, 26 Mar 2026 06:07:04 +0700 Subject: [PATCH] fix(ui): fix type violations and harden role string safety MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix getDepartments return type: Department[] → PaginatedResponse - Update CreateEmployeePage department dropdown to read .content - Add isError handling to MedicalRecordsPage (shows Alert on failure) - Extract all role string literals into src/constants/roles.ts (ROLES, ROLE_NAMES) - Replace hardcoded role strings across jwt.ts, MedicalRecordDetailPage, CreateEmployeePage, and EmployeeListPage --- hms-ui/src/api/departments.ts | 4 ++-- hms-ui/src/constants/roles.ts | 16 ++++++++++++++++ hms-ui/src/pages/admin/CreateEmployeePage.tsx | 11 ++++++----- hms-ui/src/pages/admin/EmployeeListPage.tsx | 19 ++++++++++--------- .../pages/shared/MedicalRecordDetailPage.tsx | 3 ++- .../src/pages/shared/MedicalRecordsPage.tsx | 13 +++++++++++-- hms-ui/src/utils/jwt.ts | 11 ++++++----- 7 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 hms-ui/src/constants/roles.ts diff --git a/hms-ui/src/api/departments.ts b/hms-ui/src/api/departments.ts index 7817b2a..ea075b4 100644 --- a/hms-ui/src/api/departments.ts +++ b/hms-ui/src/api/departments.ts @@ -1,5 +1,5 @@ import api from './axiosInstance'; -import type { ApiResponse, Department } from '../types'; +import type { ApiResponse, Department, PaginatedResponse } from '../types'; export const getDepartments = (params?: { page?: number; size?: number }) => - api.get>('/departments', { params }); + api.get>>('/departments', { params }); diff --git a/hms-ui/src/constants/roles.ts b/hms-ui/src/constants/roles.ts new file mode 100644 index 0000000..7b4f468 --- /dev/null +++ b/hms-ui/src/constants/roles.ts @@ -0,0 +1,16 @@ +export const ROLES = { + ADMIN: 'ROLE_ADMIN', + DOCTOR: 'ROLE_DOCTOR', + RECEPTIONIST: 'ROLE_RECEPTIONIST', + PHARMACIST: 'ROLE_PHARMACIST', + CASHIER: 'ROLE_CASHIER', + PATIENT: 'ROLE_PATIENT', +} as const; + +export const ROLE_NAMES = { + ADMIN: 'ADMIN', + DOCTOR: 'DOCTOR', + RECEPTIONIST: 'RECEPTIONIST', + PHARMACIST: 'PHARMACIST', + CASHIER: 'CASHIER', +} as const; diff --git a/hms-ui/src/pages/admin/CreateEmployeePage.tsx b/hms-ui/src/pages/admin/CreateEmployeePage.tsx index 6d85677..527034c 100644 --- a/hms-ui/src/pages/admin/CreateEmployeePage.tsx +++ b/hms-ui/src/pages/admin/CreateEmployeePage.tsx @@ -6,6 +6,7 @@ import { useState } from 'react'; import { createEmployee } from '../../api/employees'; import { getDepartments } from '../../api/departments'; import type { CreateEmployeeRequest } from '../../types'; +import { ROLE_NAMES } from '../../constants/roles'; import dayjs from 'dayjs'; const { Title } = Typography; @@ -154,17 +155,17 @@ export default function CreateEmployeePage() {