feat: add mobile-based patient lookup for appointment booking
- Implemented a new endpoint `/api/v1/my/appointment/patient-lookup` to search for patients by mobile number before booking an appointment. - Updated the `NewAppointmentModal` component to utilize the new patient lookup feature, allowing for direct booking if the patient is found with a national code. - Enhanced the appointment booking form to handle mobile input normalization and display relevant fields based on the search results. - Added tests for the new patient lookup functionality, ensuring proper behavior for found and not found cases, as well as validation for mobile input. - Updated sidebar tests to reflect changes in the sidebar component structure and functionality.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,63 +1,78 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { screen, fireEvent } from '@testing-library/react';
|
||||
import { renderWithProviders } from '../../test/utils';
|
||||
import { fireEvent, screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { renderWithProviders } from "../../test/utils";
|
||||
|
||||
vi.mock('../../hooks/useSubscription', () => ({
|
||||
useSubscription: () => ({ hasFeature: () => true }),
|
||||
vi.mock("../../hooks/useSubscription", () => ({
|
||||
useSubscription: () => ({ hasFeature: () => true }),
|
||||
}));
|
||||
|
||||
import Sidebar from './Sidebar';
|
||||
import { useAuthStore } from '../../stores/authStore';
|
||||
import { useAuthStore } from "../../stores/authStore";
|
||||
import Sidebar from "./Sidebar";
|
||||
|
||||
describe('Sidebar — expandable نوبتها menu', () => {
|
||||
beforeEach(() => {
|
||||
useAuthStore.setState({
|
||||
primaryRole: 'admin', dbUuid: 'c1', userName: 'ادمین',
|
||||
availableContexts: [], context: null,
|
||||
} as any);
|
||||
});
|
||||
describe("Sidebar — expandable نوبتها menu", () => {
|
||||
beforeEach(() => {
|
||||
useAuthStore.setState({
|
||||
primaryRole: "admin",
|
||||
dbUuid: "c1",
|
||||
userName: "ادمین",
|
||||
availableContexts: [],
|
||||
context: null,
|
||||
} as any);
|
||||
});
|
||||
|
||||
it('renders نوبتها as a collapsible parent and reveals sub-items on click', () => {
|
||||
renderWithProviders(<Sidebar />, { route: '/admin/dashboard' });
|
||||
it("renders نوبتها as a collapsible parent and reveals sub-items on click", () => {
|
||||
renderWithProviders(<Sidebar />, { route: "/admin/dashboard" });
|
||||
|
||||
// منوی والد به شکل دکمه
|
||||
const parent = screen.getByRole('button', { name: /نوبتها/ });
|
||||
expect(parent).toBeInTheDocument();
|
||||
// منوی والد به شکل دکمه
|
||||
const parent = screen.getByRole("button", { name: /نوبتها/ });
|
||||
expect(parent).toBeInTheDocument();
|
||||
|
||||
// در ابتدا (مسیر داشبورد) بسته است → زیرمنوها نیستند
|
||||
expect(screen.queryByText('نوبت های تایید شده')).toBeNull();
|
||||
// در ابتدا (مسیر داشبورد) بسته است → زیرمنوها نیستند
|
||||
expect(screen.queryByText("نوبت ها")).toBeNull();
|
||||
|
||||
fireEvent.click(parent);
|
||||
fireEvent.click(parent);
|
||||
|
||||
// پس از باز شدن، دو زیرمنو دیده میشوند
|
||||
expect(screen.getByText('نوبت های تایید شده')).toBeInTheDocument();
|
||||
expect(screen.getByText('افزودن نوبت')).toBeInTheDocument();
|
||||
});
|
||||
// پس از باز شدن، دو زیرمنو دیده میشوند
|
||||
expect(screen.getByText("نوبت ها")).toBeInTheDocument();
|
||||
expect(screen.getByText("افزودن نوبت")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('auto-expands when a child route is active', () => {
|
||||
renderWithProviders(<Sidebar />, { route: '/admin/appointments/new' });
|
||||
// چون «افزودن نوبت» فعال است، منو باید خودکار باز باشد
|
||||
expect(screen.getByText('افزودن نوبت')).toBeInTheDocument();
|
||||
expect(screen.getByText('نوبت های تایید شده')).toBeInTheDocument();
|
||||
});
|
||||
it("auto-expands when a child route is active", () => {
|
||||
renderWithProviders(<Sidebar />, { route: "/admin/appointments/new" });
|
||||
// چون «افزودن نوبت» فعال است، منو باید خودکار باز باشد
|
||||
expect(screen.getByText("افزودن نوبت")).toBeInTheDocument();
|
||||
expect(screen.getByText("نوبت ها")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Sidebar — خدمات در منوی اصلی (نه تنظیمات)', () => {
|
||||
it('shows خدمات in the clinic main menu linking to /admin/clinic-services', () => {
|
||||
useAuthStore.setState({
|
||||
primaryRole: 'clinic', dbUuid: 'c1', userName: 'کلینیک',
|
||||
availableContexts: [], context: null,
|
||||
} as any);
|
||||
renderWithProviders(<Sidebar />, { route: '/admin/dashboard' });
|
||||
expect(screen.getByText('سرویس ها').closest('a')).toHaveAttribute('href', '/admin/clinic-services');
|
||||
});
|
||||
describe("Sidebar — خدمات در منوی اصلی (نه تنظیمات)", () => {
|
||||
it("shows خدمات in the clinic main menu linking to /admin/clinic-services", () => {
|
||||
useAuthStore.setState({
|
||||
primaryRole: "clinic",
|
||||
dbUuid: "c1",
|
||||
userName: "کلینیک",
|
||||
availableContexts: [],
|
||||
context: null,
|
||||
} as any);
|
||||
renderWithProviders(<Sidebar />, { route: "/admin/dashboard" });
|
||||
expect(screen.getByText("سرویس ها").closest("a")).toHaveAttribute(
|
||||
"href",
|
||||
"/admin/clinic-services",
|
||||
);
|
||||
});
|
||||
|
||||
it('shows خدمات in the doctor main menu linking to /admin/clinic-services', () => {
|
||||
useAuthStore.setState({
|
||||
primaryRole: 'doctor', dbUuid: null, userName: 'پزشک',
|
||||
availableContexts: [], context: null,
|
||||
} as any);
|
||||
renderWithProviders(<Sidebar />, { route: '/admin/dashboard' });
|
||||
expect(screen.getByText('سرویس ها').closest('a')).toHaveAttribute('href', '/admin/clinic-services');
|
||||
});
|
||||
it("shows خدمات in the doctor main menu linking to /admin/clinic-services", () => {
|
||||
useAuthStore.setState({
|
||||
primaryRole: "doctor",
|
||||
dbUuid: null,
|
||||
userName: "پزشک",
|
||||
availableContexts: [],
|
||||
context: null,
|
||||
} as any);
|
||||
renderWithProviders(<Sidebar />, { route: "/admin/dashboard" });
|
||||
expect(screen.getByText("سرویس ها").closest("a")).toHaveAttribute(
|
||||
"href",
|
||||
"/admin/clinic-services",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,12 +22,12 @@ import {
|
||||
StarIcon,
|
||||
TagIcon,
|
||||
UserCircleIcon,
|
||||
WrenchScrewdriverIcon,
|
||||
UserGroupIcon,
|
||||
UsersIcon,
|
||||
WrenchScrewdriverIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { NavLink, useLocation, useNavigate } from "react-router-dom";
|
||||
import { useState } from "react";
|
||||
import { NavLink, useLocation, useNavigate } from "react-router-dom";
|
||||
import { useSubscription } from "../../hooks/useSubscription";
|
||||
import { useAuthStore } from "../../stores/authStore";
|
||||
import { useUiStore } from "../../stores/uiStore";
|
||||
@@ -45,7 +45,7 @@ type Section = { label: string; items: SectionItem[] };
|
||||
|
||||
/** زیرمنوهای مشترکِ «نوبتها» (نوبتهای تأییدشده + افزودن نوبت). */
|
||||
const APPOINTMENTS_CHILDREN: SubItem[] = [
|
||||
{ to: "/admin/appointments", label: "نوبت های تایید شده", icon: CalendarDaysIcon },
|
||||
{ to: "/admin/appointments", label: "نوبت ها", icon: CalendarDaysIcon },
|
||||
{ to: "/admin/appointments/new", label: "افزودن نوبت", icon: PlusIcon },
|
||||
];
|
||||
|
||||
@@ -61,8 +61,17 @@ function buildSections(
|
||||
{
|
||||
label: "عمومی",
|
||||
items: [
|
||||
{ to: "/admin/dashboard", icon: ChartBarIcon, label: "داشبورد" },
|
||||
{ to: "/admin/appointments", icon: CalendarDaysIcon, label: "نوبتهای من", children: APPOINTMENTS_CHILDREN },
|
||||
{
|
||||
to: "/admin/dashboard",
|
||||
icon: ChartBarIcon,
|
||||
label: "داشبورد",
|
||||
},
|
||||
{
|
||||
to: "/admin/appointments",
|
||||
icon: CalendarDaysIcon,
|
||||
label: "نوبتهای من",
|
||||
children: APPOINTMENTS_CHILDREN,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -84,7 +93,11 @@ function buildSections(
|
||||
label: "کاربران",
|
||||
},
|
||||
{ to: "/admin/doctors", icon: HeartIcon, label: "پزشکان" },
|
||||
{ to: "/admin/doctor-claims", icon: HeartIcon, label: "تصاحب پروفایل" },
|
||||
{
|
||||
to: "/admin/doctor-claims",
|
||||
icon: HeartIcon,
|
||||
label: "تصاحب پروفایل",
|
||||
},
|
||||
{
|
||||
to: "/admin/clinics",
|
||||
icon: BuildingOffice2Icon,
|
||||
@@ -399,27 +412,47 @@ function buildSections(
|
||||
{
|
||||
label: "عمومی",
|
||||
items: [
|
||||
{ to: "/admin/dashboard", icon: ChartBarIcon, label: "داشبورد" },
|
||||
{
|
||||
to: "/admin/dashboard",
|
||||
icon: ChartBarIcon,
|
||||
label: "داشبورد",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "مدیریت",
|
||||
items: [
|
||||
{ to: "/admin/doctors", icon: HeartIcon, label: "پزشکان" },
|
||||
{ to: "/admin/clinics", icon: BuildingOffice2Icon, label: "کلینیکها" },
|
||||
{
|
||||
to: "/admin/clinics",
|
||||
icon: BuildingOffice2Icon,
|
||||
label: "کلینیکها",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "مالی",
|
||||
items: [
|
||||
{ to: "/admin/representation-finance", icon: CreditCardIcon, label: "گزارش مالی" },
|
||||
{ to: "/admin/representation-settlement", icon: BanknotesIcon, label: "تسویه حساب" },
|
||||
{
|
||||
to: "/admin/representation-finance",
|
||||
icon: CreditCardIcon,
|
||||
label: "گزارش مالی",
|
||||
},
|
||||
{
|
||||
to: "/admin/representation-settlement",
|
||||
icon: BanknotesIcon,
|
||||
label: "تسویه حساب",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "حساب",
|
||||
items: [
|
||||
{ to: "/admin/representation-profile", icon: UserCircleIcon, label: "پروفایل" },
|
||||
{
|
||||
to: "/admin/representation-profile",
|
||||
icon: UserCircleIcon,
|
||||
label: "پروفایل",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -581,8 +614,14 @@ function NavItem({
|
||||
|
||||
export default function Sidebar({ mobileOpen: _m, onMobileClose: _c }: Props) {
|
||||
const sidebarOpen = useUiStore((s) => s.sidebarOpen);
|
||||
const { logout, primaryRole, userName, availableContexts, dbUuid, context } =
|
||||
useAuthStore();
|
||||
const {
|
||||
logout,
|
||||
primaryRole,
|
||||
userName,
|
||||
availableContexts,
|
||||
dbUuid,
|
||||
context,
|
||||
} = useAuthStore();
|
||||
const { hasFeature } = useSubscription();
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -594,7 +633,11 @@ export default function Sidebar({ mobileOpen: _m, onMobileClose: _c }: Props) {
|
||||
{/* Brand */}
|
||||
<div className="sidebar-brand">
|
||||
<div className="brand-logo">
|
||||
<img src="/logo.svg" alt="Clinic Pro" className="brand-img" />
|
||||
<img
|
||||
src="/logo.svg"
|
||||
alt="Clinic Pro"
|
||||
className="brand-img"
|
||||
/>
|
||||
</div>
|
||||
<div className="brand-text">
|
||||
<b>ClinicPro</b>
|
||||
|
||||
Reference in New Issue
Block a user