diff --git a/client/src/components/center-calendar/CenterCalendar.js b/client/src/components/center-calendar/CenterCalendar.js index fd43078..2e09acc 100644 --- a/client/src/components/center-calendar/CenterCalendar.js +++ b/client/src/components/center-calendar/CenterCalendar.js @@ -23,13 +23,17 @@ import Select from 'react-select'; const EventsCalendar = () => { const navigate = useNavigate(); + const calendarTabOrder = ['medicalCalendar', 'activitiesCalendar', 'incidentsCalendar', 'mealPlanCalendar', 'reminderDatesCalendar']; + const getFirstVisibleCalendarTab = () => { + return calendarTabOrder.find((tabKey) => AuthService.canViewCalendarTab(tabKey) || AuthService.canEditCalendarTab(tabKey)) || 'medicalCalendar'; + }; const [events, setEvents] = useState([]); const calendarColumnRef = useRef(null); const [listHeight, setListHeight] = useState(null); const [allEvents, setAllEvents] = useState([]); const [targetedEventType, setTargetedEventType] = useState('medical'); - const [currentTab, setCurrentTab] = useState('medicalCalendar'); - const currentTabRef = useRef('medicalCalendar'); + const [currentTab, setCurrentTab] = useState(getFirstVisibleCalendarTab()); + const currentTabRef = useRef(getFirstVisibleCalendarTab()); const [customers, setCustomers] = useState([]); const [resources, setResources] = useState([]); const [fromDate, setFromDate] = useState(new Date(new Date().getFullYear(), new Date().getMonth(), 1)); @@ -126,6 +130,8 @@ const EventsCalendar = () => { const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const [deleteTargetId, setDeleteTargetId] = useState(null); const [showSpinner, setShowSpinner] = useState(false); + const visibleCalendarTabs = calendarTabOrder.filter((tabKey) => AuthService.canViewCalendarTab(tabKey) || AuthService.canEditCalendarTab(tabKey)); + const canEditCurrentTab = () => AuthService.canEditCalendarTab(currentTab); // Helper function to format name from "lastname, firstname" to "firstname lastname" const formatFullName = (name) => { @@ -245,7 +251,7 @@ const EventsCalendar = () => { setToDate(new Date(endDate.getFullYear(), endDate.getMonth() + 1, 0)); }, onClickDate(date) { - if (currentTabRef.current === 'medicalCalendar') return; + if (currentTabRef.current === 'medicalCalendar' || !AuthService.canEditCalendarTab(currentTabRef.current)) return; // Parse as local date to avoid UTC timezone offset shifting the day const [y, m, d] = date.split('-').map(Number); const localDate = new Date(y, m - 1, d); @@ -258,7 +264,7 @@ const EventsCalendar = () => { setShowCreationModal(true); }, onClickDateTime(dateTime) { - if (currentTabRef.current === 'medicalCalendar') return; + if (currentTabRef.current === 'medicalCalendar' || !AuthService.canEditCalendarTab(currentTabRef.current)) return; setNewEventStartDateTime(new Date(dateTime.replace(' ', 'T'))); setNewEventEndDateTime(new Date(dateTime.replace(' ', 'T'))); setShowCreationModal(true); @@ -343,6 +349,14 @@ const EventsCalendar = () => { }); }, []); + useEffect(() => { + if (!visibleCalendarTabs.includes(currentTab)) { + const nextTab = getFirstVisibleCalendarTab(); + setCurrentTab(nextTab); + currentTabRef.current = nextTab; + } + }, [currentTab]); + useEffect(() => { EventsService.getAllEvents({ from: EventsService.formatDate(fromDate), to: EventsService.formatDate(toDate) }).then(data => setAllEvents(data?.data)); EventsService.getAllEventRecurrences().then(data => setAllEventRecurrences(data?.data || [])); @@ -509,10 +523,12 @@ const EventsCalendar = () => { } const goToEdit = (id) => { + if (!AuthService.canEditMedicalEvents()) return; navigate(`/medical/events/edit/${id}?from=calendar`) } const goToCreateNew = () => { + if (!AuthService.canEditMedicalEvents()) return; navigate(`/medical/events`) } @@ -530,6 +546,7 @@ const EventsCalendar = () => { } const disableEvent = (id) => { + if (!AuthService.canEditCalendarTab(currentTab)) return; // Handle recurring event instances const isRecurInstance = typeof id === 'string' && id.startsWith('recur-'); if (isRecurInstance) { @@ -596,6 +613,7 @@ const EventsCalendar = () => { // Edit modal functions (for non-medical tabs) const openEditModal = (calendarEvent) => { + if (!AuthService.canEditCalendarTab(currentTab)) return; // Check if this is a recurring event instance (ID starts with 'recur-') const isRecurInstance = typeof calendarEvent.id === 'string' && calendarEvent.id.startsWith('recur-'); let eventData; @@ -676,6 +694,7 @@ const EventsCalendar = () => { }; const handleEditSave = () => { + if (!AuthService.canEditCalendarTab(currentTab)) return; const userName = localStorage.getItem('user') && JSON.parse(localStorage.getItem('user'))?.name; let data = { @@ -813,6 +832,7 @@ const EventsCalendar = () => { } const goToTab = (value) => { + if (!value || !visibleCalendarTabs.includes(value)) return; setTargetedEventType(eventTypeMap[value]); setCurrentTab(value); currentTabRef.current = value; @@ -834,13 +854,13 @@ const EventsCalendar = () => { {calendarEvent?.doctor &&
{`${calendarEvent?.doctor}`}
}
{`${calendarEvent?.start}`}
- currentTab === 'medicalCalendar' ? goToEdit(calendarEvent?.id) : openEditModal(calendarEvent)} style={{ cursor: 'pointer' }} title="Edit" - /> - {currentTab !== 'medicalCalendar' && } + {currentTab !== 'medicalCalendar' && AuthService.canEditCalendarTab(currentTab) && { setDeleteTargetId(calendarEvent?.id); setShowDeleteConfirm(true); }} style={{ cursor: 'pointer' }} @@ -1130,6 +1150,7 @@ const handleClose = () => { setNewReminderAssociatedEntity(null); } const handleSave = () => { + if ((currentTab === 'medicalCalendar' && !AuthService.canEditMedicalEvents()) || (currentTab !== 'medicalCalendar' && !AuthService.canEditCalendarTab(currentTab))) return; const userName = localStorage.getItem('user') && JSON.parse(localStorage.getItem('user'))?.name; let data = { @@ -1302,26 +1323,26 @@ const getReminderTitleLabel = (value) => {
- goToTab(k)}> - + goToTab(k)}> + {visibleCalendarTabs.includes('medicalCalendar') && - - + } + {visibleCalendarTabs.includes('activitiesCalendar') && - - + } + {visibleCalendarTabs.includes('incidentsCalendar') && - - + } + {visibleCalendarTabs.includes('mealPlanCalendar') && - - + } + {visibleCalendarTabs.includes('reminderDatesCalendar') && - + } { calendarView}
- {currentTab !== 'medicalCalendar' && ( + {currentTab !== 'medicalCalendar' && canEditCurrentTab() && ( + } ({ diff --git a/client/src/components/customers/UpdateCustomer.js b/client/src/components/customers/UpdateCustomer.js index ce91804..84c12c8 100644 --- a/client/src/components/customers/UpdateCustomer.js +++ b/client/src/components/customers/UpdateCustomer.js @@ -42,6 +42,9 @@ const UpdateCustomer = () => { const normalizedInitialTab = ['additionalInfo', 'complianceDeadlines'].includes(initialTab) ? 'personalInfo' : initialTab; const showDischargeButton = searchParams.get('fromEdit') === '1'; const [activeTab, setActiveTab] = useState(normalizedInitialTab || 'personalInfo'); + const customerTabOrder = ['personalInfo', 'careServices', 'medicalInsurance', 'confidentialDetails', 'formSubmission']; + const editableTabs = customerTabOrder.filter((tabKey) => AuthService.canEditCustomerTab(tabKey)); + const firstEditableTab = editableTabs[0] || 'personalInfo'; const [currentCustomer, setCurrentCustomer] = useState(undefined); // Basic Info @@ -191,7 +194,13 @@ const UpdateCustomer = () => { }; useEffect(() => { - if (!AuthService.canAddOrEditCustomers()) { + if (!editableTabs.includes(activeTab)) { + setActiveTab(firstEditableTab); + } + }, [activeTab]); + + useEffect(() => { + if (!AuthService.canEditAnyCustomerTab()) { window.alert('You haven\'t login yet OR this user does not have access to this page. Please change an admin account to login.') AuthService.logout(); navigate(`/login`); @@ -944,7 +953,7 @@ const UpdateCustomer = () => {
setActiveTab(k)} id="customers-tab"> - + {AuthService.canEditCustomerTab('personalInfo') && {/* Basic Info Section */}
Basic Info
@@ -1311,7 +1320,7 @@ const UpdateCustomer = () => { )}
)} - {!isCustomerActive() && ( + {!isCustomerActive() && AuthService.canReactivateCustomer() && (
- + } - + {AuthService.canEditCustomerTab('careServices') && {/* Care & Services Section */}
Care & Services
@@ -1442,9 +1451,9 @@ const UpdateCustomer = () => {
- + } - + {AuthService.canEditCustomerTab('medicalInsurance') && {/* Providers Section */}
Providers
@@ -1623,9 +1632,9 @@ const UpdateCustomer = () => {
- + } - + {AuthService.canEditCustomerTab('confidentialDetails') &&
Confidential Details
@@ -1653,10 +1662,10 @@ const UpdateCustomer = () => {
-
+
} - + {AuthService.canEditCustomerTab('formSubmission') && {/* Admission Forms Section */}
Admission Forms
@@ -1759,10 +1768,10 @@ const UpdateCustomer = () => {
- + } - {isCustomerActive() && showDischargeButton && ( + {isCustomerActive() && showDischargeButton && AuthService.canDischargeCustomer() && (
- + }
- + {AuthService.canEditAnyCustomerTab() && }
diff --git a/client/src/components/dashboard/DashboardCustomersList.js b/client/src/components/dashboard/DashboardCustomersList.js index 2dba328..42a7c36 100644 --- a/client/src/components/dashboard/DashboardCustomersList.js +++ b/client/src/components/dashboard/DashboardCustomersList.js @@ -348,7 +348,7 @@ const DashboardCustomersList = ({ additionalButtons, showBreadcrumb = false, tit /> ) )} - {AuthService.canAddOrEditCustomers() && isAllCustomersPage ? goToEdit(customer?.id) : goToView(customer?.id)} style={{ flexShrink: 0 }}>} + {AuthService.canEditAnyCustomerTab() && isAllCustomersPage ? goToEdit(customer?.id) : goToView(customer?.id)} style={{ flexShrink: 0 }}>} goToView(customer?.id)}>{customer?.name} } diff --git a/client/src/components/event-request/CreateEventRequest.js b/client/src/components/event-request/CreateEventRequest.js index 03c3164..db97e94 100644 --- a/client/src/components/event-request/CreateEventRequest.js +++ b/client/src/components/event-request/CreateEventRequest.js @@ -83,7 +83,7 @@ const CreateEventRequest = () => { useEffect(() => { - if (!AuthService.canViewMedicalSection()) { + if (!AuthService.canEditAppointmentRequests()) { window.alert('You haven\'t login yet OR this user does not have access to this page. Please change an admin account to login.') AuthService.logout(); navigate(`/login`); diff --git a/client/src/components/event-request/EventRequestList.js b/client/src/components/event-request/EventRequestList.js index 91d3283..b71e2ac 100644 --- a/client/src/components/event-request/EventRequestList.js +++ b/client/src/components/event-request/EventRequestList.js @@ -69,7 +69,7 @@ const EventRequestList = () => { ]); useEffect(() => { - if (!AuthService.canViewMedicalSection()) { + if (!AuthService.canViewAppointmentRequests()) { window.alert('You haven\'t login yet OR this user does not have access to this page. Please change an admin account to login.') AuthService.logout(); navigate(`/login`); @@ -293,10 +293,10 @@ const EventRequestList = () => { {eventRequest?.notes?.map((note) => { return

{`${note?.author}: ${note?.content}`}

})} -