modified: index.html
modified: src/App.jsx modified: src/components/AppShell.jsx modified: src/components/featureStateStyles.js modified: src/config/permissions.js modified: src/hooks/useAgenda.js modified: src/mappers/reportMapper.js modified: src/pages/AgendaPage.jsx modified: src/pages/AnalyticsPage.jsx modified: src/pages/AuthPages.jsx modified: src/pages/HomePage.jsx modified: src/pages/MedicalRecordsPage.jsx modified: src/pages/MessagesPage.jsx modified: src/pages/PatientsPage.jsx modified: src/pages/ReportsPage.jsx modified: src/pages/SettingsPage.jsx deleted: src/pages/TeamPage.jsx modified: src/pages/UsersPage.jsx modified: src/repositories/availabilityRepository.js modified: src/repositories/patientRepository.js modified: src/repositories/professionalRepository.js modified: src/repositories/reportRepository.js modified: src/repositories/settingsRepository.js
This commit is contained in:
@@ -23,6 +23,9 @@ export function useAgenda() {
|
||||
const [activeView, setActiveView] = useState('Dia')
|
||||
const [baseDate, setBaseDate] = useState(new Date())
|
||||
const [status, setStatus] = useState('Todos')
|
||||
const [doctorFilter, setDoctorFilter] = useState('Todos')
|
||||
const [doctorSearch, setDoctorSearch] = useState('')
|
||||
const [unitFilter, setUnitFilter] = useState('')
|
||||
const [modalOpen, setModalOpen] = useState(false)
|
||||
|
||||
const [form, setForm] = useState({
|
||||
@@ -53,7 +56,7 @@ export function useAgenda() {
|
||||
if (!active) return
|
||||
|
||||
const agendaScope = currentProfile?.isDoctor ? 'doctor' : 'global'
|
||||
const resolvedProfessional = resolveCurrentProfessional(currentProfile, professionalsData)
|
||||
const resolvedProfessional = professionalRepository.resolveCurrentProfessional(currentProfile, professionalsData)
|
||||
const initialProfessionalId =
|
||||
agendaScope === 'doctor'
|
||||
? resolvedProfessional?.id || ''
|
||||
@@ -128,6 +131,7 @@ export function useAgenda() {
|
||||
const slots = await availabilityRepository.getAvailableSlots({
|
||||
doctorId: targetProfessionalId,
|
||||
date: formatLocalDateInput(baseDate),
|
||||
appointmentType: form.mode,
|
||||
})
|
||||
|
||||
if (!active) return
|
||||
@@ -156,7 +160,7 @@ export function useAgenda() {
|
||||
return () => {
|
||||
active = false
|
||||
}
|
||||
}, [agendaScope, baseDate, currentProfessional?.id, form.professionalId, modalOpen])
|
||||
}, [agendaScope, baseDate, currentProfessional?.id, form.mode, form.professionalId, modalOpen])
|
||||
|
||||
const visibleAppointments = useMemo(() => {
|
||||
let filtered = localAppointments
|
||||
@@ -165,6 +169,30 @@ export function useAgenda() {
|
||||
filtered = filtered.filter((appointment) => appointment.status === status)
|
||||
}
|
||||
|
||||
if (agendaScope !== 'doctor' && doctorFilter !== 'Todos') {
|
||||
filtered = filterAppointmentsByProfessional(filtered, doctorFilter)
|
||||
}
|
||||
|
||||
if (agendaScope !== 'doctor') {
|
||||
const normalizedDoctorSearch = normalizeValue(doctorSearch)
|
||||
const normalizedUnit = normalizeValue(unitFilter)
|
||||
|
||||
if (normalizedDoctorSearch || normalizedUnit) {
|
||||
filtered = filtered.filter((appointment) => {
|
||||
const professional = professionals.find(
|
||||
(item) => normalizeValue(item.id) === normalizeValue(appointment.professionalId),
|
||||
)
|
||||
const professionalName = normalizeValue(professional?.name || appointment.professional)
|
||||
const professionalUnit = normalizeValue(professional?.unit || appointment.unit)
|
||||
|
||||
return (
|
||||
(!normalizedDoctorSearch || professionalName.includes(normalizedDoctorSearch)) &&
|
||||
(!normalizedUnit || professionalUnit === normalizedUnit)
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (activeView === 'Dia') {
|
||||
filtered = filtered.filter((appointment) => {
|
||||
if (!appointment.date) return false
|
||||
@@ -177,7 +205,7 @@ export function useAgenda() {
|
||||
}
|
||||
|
||||
return sortAppointmentsByTime(filtered)
|
||||
}, [localAppointments, status, activeView, baseDate])
|
||||
}, [localAppointments, status, agendaScope, doctorFilter, doctorSearch, unitFilter, professionals, activeView, baseDate])
|
||||
|
||||
function updateForm(field, value) {
|
||||
setForm((current) => ({ ...current, [field]: value }))
|
||||
@@ -230,6 +258,12 @@ export function useAgenda() {
|
||||
setBaseDate,
|
||||
status,
|
||||
setStatus,
|
||||
doctorFilter,
|
||||
setDoctorFilter,
|
||||
doctorSearch,
|
||||
setDoctorSearch,
|
||||
unitFilter,
|
||||
setUnitFilter,
|
||||
modalOpen,
|
||||
setModalOpen,
|
||||
form,
|
||||
@@ -242,20 +276,6 @@ export function useAgenda() {
|
||||
}
|
||||
}
|
||||
|
||||
function resolveCurrentProfessional(profile, professionals) {
|
||||
const doctorId = normalizeValue(profile?.doctorId)
|
||||
const userId = normalizeValue(profile?.id)
|
||||
const email = normalizeValue(profile?.email)
|
||||
|
||||
return (
|
||||
professionals.find((professional) => normalizeValue(professional.id) === doctorId) ||
|
||||
professionals.find((professional) => normalizeValue(professional.userId) === userId) ||
|
||||
professionals.find((professional) => normalizeValue(professional.id) === userId) ||
|
||||
professionals.find((professional) => normalizeValue(professional.email) === email) ||
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
function filterAppointmentsByProfessional(appointments, professionalId) {
|
||||
const normalizedProfessionalId = normalizeValue(professionalId)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user