fix(appointments): stay on the same day after edit/create
AppointmentsPage now reads an optional ?date=YYYY-MM-DD query param as its initial selected date. AppointmentEditPage and AppointmentCreatePage navigate back to /admin/appointments?date=<the appointment's day> on save (and the edit page's back link carries the date too), so the user returns to the day they were viewing instead of today. Test: AppointmentsPage honors ?date= and fetches that day. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -116,7 +116,8 @@ export default function AppointmentCreatePage() {
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['appointments'] });
|
||||
toast.success('نوبت با موفقیت ثبت شد');
|
||||
navigate('/admin/appointments');
|
||||
// به همان روزِ نوبت برگرد، نه امروز.
|
||||
navigate(`/admin/appointments?date=${date}`);
|
||||
},
|
||||
onError: (e: any) => toast.error(e.message || 'خطا در ثبت نوبت'),
|
||||
});
|
||||
|
||||
@@ -93,7 +93,8 @@ export default function AppointmentEditPage() {
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['appointments'] });
|
||||
toast.success('نوبت بهروزرسانی شد');
|
||||
navigate('/admin/appointments');
|
||||
// به همان روزِ نوبت برگرد، نه امروز.
|
||||
navigate(`/admin/appointments?date=${date}`);
|
||||
},
|
||||
onError: (e: any) => toast.error(e.message || 'خطا در ذخیره اطلاعات'),
|
||||
});
|
||||
@@ -111,7 +112,7 @@ export default function AppointmentEditPage() {
|
||||
return (
|
||||
<div className="fade-in" style={{ maxWidth: 860, margin: '0 auto' }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', marginBottom: 14 }}>
|
||||
<Link to="/admin/appointments" className="btn sm ghost" style={{ color: 'var(--text-2)' }}>
|
||||
<Link to={`/admin/appointments?date=${date}`} className="btn sm ghost" style={{ color: 'var(--text-2)' }}>
|
||||
<ChevronRightIcon style={{ width: 16 }} /> بازگشت
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
@@ -39,6 +39,13 @@ describe('AppointmentsPage — طرح نوبتها', () => {
|
||||
expect(await screen.findByText('این روز تعطیل است')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('honors the ?date= query param (returns to the same day after edit)', async () => {
|
||||
renderWithProviders(<AppointmentsPage />, { route: '/admin/appointments?date=2024-06-01' });
|
||||
await screen.findByText('این روز تعطیل است');
|
||||
const usedDate = get.mock.calls.some((c: any[]) => typeof c[0] === 'string' && c[0].includes('date=2024-06-01'));
|
||||
expect(usedDate).toBe(true);
|
||||
});
|
||||
|
||||
it('independent doctor profile does NOT show doctor tabs', async () => {
|
||||
renderWithProviders(<AppointmentsPage />);
|
||||
await screen.findByText('این روز تعطیل است');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import {
|
||||
PlusIcon, ChevronRightIcon, ChevronLeftIcon, CalendarDaysIcon,
|
||||
AdjustmentsHorizontalIcon,
|
||||
@@ -200,8 +200,10 @@ export default function AppointmentsPage() {
|
||||
const isDoctor = primaryRole === 'doctor';
|
||||
const isRepresentation = primaryRole === 'representation';
|
||||
|
||||
const [params] = useSearchParams();
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const [selectedDate, setSelectedDate] = useState(today);
|
||||
// پس از ویرایش/ثبت، صفحه با ?date=... باز میشود تا همان روز نمایش داده شود.
|
||||
const [selectedDate, setSelectedDate] = useState(params.get('date') || today);
|
||||
const [viewMode, setViewMode] = useState<TurnsViewMode>('timeline');
|
||||
const [selectedDoctorUuid, setSelectedDoctorUuid] = useState<string>(isDoctor && dbUuid ? dbUuid : '');
|
||||
const [bookingSlot, setBookingSlot] = useState<BookingSlot | null>(null);
|
||||
|
||||
Reference in New Issue
Block a user