From 5da63492ff2be04bb85ed6dbe5e63c8784e26b34 Mon Sep 17 00:00:00 2001 From: Kailasdevdas Date: Wed, 24 Jun 2026 16:43:14 +0530 Subject: [PATCH] feat: featured doctor toggle --- backend/src/routes/doctor.routes.js | 2 +- frontend/src/api/doctor.ts | 3 +- frontend/src/pages/Doctor.tsx | 48 ++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/backend/src/routes/doctor.routes.js b/backend/src/routes/doctor.routes.js index 9d0a5b7..86b8dfd 100644 --- a/backend/src/routes/doctor.routes.js +++ b/backend/src/routes/doctor.routes.js @@ -19,8 +19,8 @@ router.get('/getAll', getAllDoctors); router.get('/search', getDoctorsByDepartmentId); router.get('/getTimings', getDoctorTimings); router.get('/getTimings/:doctorId', getDoctorTimingById); -router.get('/:doctorId', getDoctorByDoctorId); router.get('/featured', getFeaturedDoctors); +router.get('/:doctorId', getDoctorByDoctorId); router.post('/', jwtAuthMiddleware, createDoctor); router.patch('/:doctorId/:action', jwtAuthMiddleware, updateDoctor); diff --git a/frontend/src/api/doctor.ts b/frontend/src/api/doctor.ts index 1f5a3e4..7180c5a 100644 --- a/frontend/src/api/doctor.ts +++ b/frontend/src/api/doctor.ts @@ -9,6 +9,7 @@ export interface Doctor { workingStatus?: string; qualification?: string; isActive: boolean; + isFeatured: boolean; globalSortOrder: number; departments?: { @@ -53,7 +54,7 @@ export const createDoctorApi = async (data: Doctor) => { export const updateDoctorApi = async ( doctorId: string, data: Partial, - action: 'toggleStatus' | 'updateDetails' = 'updateDetails' + action: 'toggleStatus' | 'toggleFeatured' | 'updateDetails' = 'updateDetails' ) => { try { const res = await apiClient.patch(`/doctors/${doctorId}/${action}`, data); diff --git a/frontend/src/pages/Doctor.tsx b/frontend/src/pages/Doctor.tsx index 1a147fb..099d112 100644 --- a/frontend/src/pages/Doctor.tsx +++ b/frontend/src/pages/Doctor.tsx @@ -51,6 +51,7 @@ export default function DoctorPage() { workingStatus: '', qualification: '', isActive: true, + isFeatured: false, globalSortOrder: 0, departments: [], professionalSummary: '', @@ -156,6 +157,22 @@ export default function DoctorPage() { } }; + const handleToggleFeatured = async (doc: any) => { + try { + const newFeaturedStatus = !doc.isFeatured; + + const payload = { + isFeatured: newFeaturedStatus, + }; + + await updateDoctorApi(doc.doctorId, payload, 'toggleFeatured'); + + fetchAll(); + } catch (err) { + console.error('Failed to update featured status', err); + } + }; + function handleDepartmentToggle(depId: string) { const exists = form.departments.find((d: any) => d.departmentId === depId); if (exists) { @@ -201,6 +218,7 @@ export default function DoctorPage() { experience: '', professionalSummary: '', isActive: true, + isFeatured: false, globalSortOrder: 0, specializations: [ { @@ -235,6 +253,7 @@ export default function DoctorPage() { workingStatus: doc.workingStatus, qualification: doc.qualification, isActive: doc.isActive ?? true, + isFeatured: doc.isFeatured ?? false, globalSortOrder: doc.globalSortOrder ?? 0, experience: doc.experience || '', professionalSummary: doc.professionalSummary || '', @@ -353,14 +372,15 @@ export default function DoctorPage() {
- +
Priority Doctor Info Designation Departments (Hierarchy) - Status (Active) + Status (Active) + Featured Actions @@ -368,13 +388,13 @@ export default function DoctorPage() { {loading ? ( - + ) : currentItems.length === 0 ? ( - + No doctors found @@ -423,6 +443,15 @@ export default function DoctorPage() { + +
+ handleToggleFeatured(doc)} /> + + {doc.isFeatured ? 'Featured' : 'Hidden'} + +
+
+
+
+ + setForm({ ...form, isFeatured: val })} + /> +
+