feat: add past slot validation to appointment controllers and update SlotCard component

This commit is contained in:
hamed
2026-06-11 20:00:02 +03:30
parent c1df5b73e7
commit c05ac7ca51
3 changed files with 27 additions and 0 deletions
+19
View File
@@ -292,6 +292,8 @@ function CancelledBadge({ appt }: { appt: Appointment }) {
}
function SlotCard({ slot, queryKey, onBook }: { slot: SlotItem; queryKey: unknown[]; onBook: (slot: SlotItem) => void }) {
const isPast = slot.start < Math.floor(Date.now() / 1000);
if (!slot.is_available && slot.appointment) {
const a = slot.appointment;
const sm = statusMeta(a.status);
@@ -299,6 +301,7 @@ function SlotCard({ slot, queryKey, onBook }: { slot: SlotItem; queryKey: unknow
<div style={{
border: `1.5px solid ${sm.color}40`, borderRadius: 'var(--r)',
background: sm.bg, overflow: 'hidden',
opacity: isPast ? 0.6 : 1,
}}>
<div style={{
padding: '8px 12px', display: 'flex', alignItems: 'center', justifyContent: 'space-between',
@@ -324,6 +327,22 @@ function SlotCard({ slot, queryKey, onBook }: { slot: SlotItem; queryKey: unknow
}
// Available slot — possibly with cancelled history
if (isPast) {
return (
<div style={{ display: 'flex', flexDirection: 'column' }}>
{slot.cancelled_appointment && <CancelledBadge appt={slot.cancelled_appointment} />}
<div style={{
border: '1.5px dashed #d1d5db', borderRadius: 'var(--r)', padding: '10px 16px',
display: 'flex', alignItems: 'center', justifyContent: 'center',
cursor: 'not-allowed', color: '#9ca3af', fontSize: 13, fontWeight: 600,
background: '#f9fafb', gap: 6,
}}>
<span style={{ fontSize: 15 }}></span> گذشته
</div>
</div>
);
}
return (
<div style={{ display: 'flex', flexDirection: 'column' }}>
{slot.cancelled_appointment && <CancelledBadge appt={slot.cancelled_appointment} />}
@@ -173,6 +173,10 @@ class AppointmentController extends BaseController
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'doctor_uuid، slot_start و slot_end الزامی است', 422);
}
if ($slotStart < time()) {
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'زمان این اسلات گذشته است', 422);
}
$doctor = $this->doctorRepo->findByUuid($doctorUuid);
if ($doctor === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'دکتر یافت نشد', 404);
@@ -45,6 +45,10 @@ class MyAppointmentsController extends BaseController
return $this->error('VALIDATION', 'همه فیلدها الزامی است', 422);
}
if ($slotStart < time()) {
return $this->error('SLOT_PAST', 'زمان این اسلات گذشته است', 422);
}
$doctor = $this->doctorRepo->findByUuid($doctorUuid);
if (!$doctor) return $this->error('DOCTOR_NOT_FOUND', 'پزشک یافت نشد', 404);