diff --git a/dashboard/src/scenes/report/components/ActionsOrConsultationsReport.js b/dashboard/src/scenes/report/components/ActionsOrConsultationsReport.js index 3251113bc..754c705ba 100644 --- a/dashboard/src/scenes/report/components/ActionsOrConsultationsReport.js +++ b/dashboard/src/scenes/report/components/ActionsOrConsultationsReport.js @@ -10,6 +10,7 @@ import { useLocalStorage } from '../../../services/useLocalStorage'; import { useRecoilValue } from 'recoil'; import { userState } from '../../../recoil/auth'; import { dayjsInstance } from '../../../services/date'; +import EyeIcon from '../../../assets/icons/EyeIcon'; const formatEcheanceLabelPeriod = (period) => { if (!!period.startDate && !!period.endDate) { @@ -26,52 +27,54 @@ const formatEcheanceLabelPeriod = (period) => { }; export const ActionsOrConsultationsReport = ({ - actionsDueOrCompletedAt, + actionsCompletedAt, + actionsCanceledAt, actionsCreatedAt, - consultationsDueOrCompletedAt, + consultationsCompletedAt, + consultationsCanceledAt, consultationsCreatedAt, period, }) => { const history = useHistory(); const user = useRecoilValue(userState); - const [activeTab, setActiveTab] = useLocalStorage('reports-actions-consultation-toggle', 'Actions'); + const [activeTab, setActiveTab] = useLocalStorage('reports-actions-consultations-todo-done-toggle', 'Faites'); const canSeeMedicalData = ['admin', 'normal'].includes(user.role) && !!user.healthcareProfessional; + const [showActions, setShowActions] = useLocalStorage('reports-actions-consultations-show-actions', true); + const [showConsultations, setShowConsultations] = useLocalStorage('reports-actions-consultations-show-consults', canSeeMedicalData); const activeTabIndex = useMemo(() => { - if (activeTab.includes('Actions')) return 0; - if (activeTab.includes('Consultations')) return 1; - if (activeTab.includes('Créées')) { - if (canSeeMedicalData) return 2; - return 1; - } + if (activeTab.includes('Faites')) return 0; + if (activeTab.includes('Annulées')) return 1; + return 2; // activeTab.includes('Créées') }, [activeTab, canSeeMedicalData]); + const [fullScreen, setFullScreen] = useState(false); - const [filterStatus, setFilterStatus] = useLocalStorage('reports-actions-filter-status', []); - const data = useMemo(() => { - if (activeTab.includes('Action')) return actionsDueOrCompletedAt; - if (activeTab.includes('Consultations')) return consultationsDueOrCompletedAt; - return [...actionsCreatedAt, ...consultationsCreatedAt]; - }, [activeTab, actionsCreatedAt, consultationsCreatedAt, consultationsDueOrCompletedAt, actionsDueOrCompletedAt]); + const actions = useMemo(() => { + if (activeTab.includes('Faites')) return actionsCompletedAt; + if (activeTab.includes(`Annulées`)) return actionsCanceledAt; + return actionsCreatedAt; + }, [activeTab, actionsCompletedAt, actionsCanceledAt, actionsCreatedAt]); - const filteredActionsDueOrCompletedAt = actionsDueOrCompletedAt.filter((item) => !filterStatus.length || filterStatus.includes(item.status)); - const filteredConsultationsDueOrCompletedAt = consultationsDueOrCompletedAt.filter( - (item) => !filterStatus.length || filterStatus.includes(item.status) - ); - const filteredData = useMemo(() => { - if (activeTab.includes('Action')) return filteredActionsDueOrCompletedAt; - if (activeTab.includes('Consultations')) return filteredConsultationsDueOrCompletedAt; - return [...actionsCreatedAt, ...consultationsCreatedAt]; - }, [activeTab, actionsCreatedAt, consultationsCreatedAt, filteredConsultationsDueOrCompletedAt, filteredActionsDueOrCompletedAt]); + const consultations = useMemo(() => { + if (activeTab.includes('Faites')) return consultationsCompletedAt; + if (activeTab.includes(`Annulées`)) return consultationsCanceledAt; + return consultationsCreatedAt; + }, [activeTab, consultationsCompletedAt, consultationsCanceledAt, consultationsCreatedAt]); - const tabs = canSeeMedicalData - ? [ - `Actions (${filteredActionsDueOrCompletedAt.length})`, - `Consultations (${filteredConsultationsDueOrCompletedAt.length})`, - `Créées (${consultationsCreatedAt.length + actionsCreatedAt.length})`, - ] - : [`Actions (${filteredActionsDueOrCompletedAt.length})`, `Créées (${actionsCreatedAt.length})`]; + const data = useMemo(() => { + if (showActions && showConsultations) return [...actions, ...consultations]; + if (showActions) return actions; + if (showConsultations) return consultations; + return []; + }, [activeTab, showActions, showConsultations, actions, consultations]); + + const tabs = [ + `Faites (${canSeeMedicalData ? actionsCompletedAt.length + consultationsCompletedAt.length : actionsCompletedAt.length})`, + `Annulées (${canSeeMedicalData ? actionsCanceledAt.length + consultationsCanceledAt.length : actionsCanceledAt.length})`, + `Créées (${canSeeMedicalData ? actionsCreatedAt.length + consultationsCreatedAt.length : actionsCreatedAt.length})`, + ]; return ( <> @@ -82,17 +85,9 @@ export const ActionsOrConsultationsReport = ({ tabs={tabs} renderTab={(caption) =>

{caption}

} onClick={(_, index) => { - if (index === 0) setActiveTab('Actions'); - if (index === 1) { - if (canSeeMedicalData) { - setActiveTab('Consultations'); - } else { - setActiveTab('Créées'); - } - } - if (index === 2) { - setActiveTab('Créées'); - } + if (index === 0) setActiveTab('Faites'); + if (index === 1) setActiveTab('Annulées'); + if (index === 2) setActiveTab('Créées'); }} activeTabIndex={activeTabIndex} /> @@ -125,91 +120,37 @@ export const ActionsOrConsultationsReport = ({
- -
-
- -
- - - - {canSeeMedicalData && ( - <> - - - - )} setFullScreen(false)}> - setFullScreen(false)}> + setFullScreen(false)}>
- +
- + + diff --git a/dashboard/src/scenes/report/view.js b/dashboard/src/scenes/report/view.js index feeee5787..dfb7e90c3 100644 --- a/dashboard/src/scenes/report/view.js +++ b/dashboard/src/scenes/report/view.js @@ -5,7 +5,7 @@ import { HeaderStyled, Title as HeaderTitle } from '../../components/header'; import { ModalBody, ModalContainer, ModalFooter, ModalHeader } from '../../components/tailwind/Modal'; import dayjs from 'dayjs'; -import { TODO } from '../../recoil/actions'; +import { CANCEL, TODO, DONE } from '../../recoil/actions'; import ButtonCustom from '../../components/ButtonCustom'; import { currentTeamState, organisationState, teamsState, userState } from '../../recoil/auth'; import { reportsState } from '../../recoil/reports'; @@ -67,9 +67,11 @@ const itemsForReportsSelector = selectorFamily({ const personsCreated = {}; const personsUpdated = {}; - const actionsDueOrCompletedAt = {}; + const actionsCompletedAt = {}; + const actionsCanceledAt = {}; const actionsCreatedAt = {}; - const consultationsDueOrCompletedAt = {}; + const consultationsCompletedAt = {}; + const consultationsCanceledAt = {}; const consultationsCreatedAt = {}; const comments = {}; const commentsMedical = {}; @@ -99,25 +101,33 @@ const itemsForReportsSelector = selectorFamily({ for (const action of person.actions || []) { if (!filterItemByTeam(action, 'teams')) continue; if (Array.isArray(action.teams)) { - let isDueOrCompletedAt = false; + let isDoneAt = false; + let isCanceledAt = false; let isCreatedAt = false; for (const team of action.teams) { const { isoStartDate, isoEndDate } = selectedTeamsObjectWithOwnPeriod[team] ?? defaultIsoDates; - if (action.status !== TODO && action.completedAt >= isoStartDate && action.completedAt < isoEndDate) { - isDueOrCompletedAt = true; + if (action.completedAt >= isoStartDate && action.completedAt < isoEndDate) { + if (action.status === CANCEL) { + isCanceledAt = true; + continue; + } + if (action.status === DONE) { + isDoneAt = true; + continue; + } continue; } if (action.createdAt >= isoStartDate && action.createdAt < isoEndDate) { - isCreatedAt = true; + if (action.status === TODO) { + isCreatedAt = true; + continue; + } } - // if (action.status !== TODO) continue; - // if (action.dueAt >= isoStartDate && action.dueAt < isoEndDate) { - // isDueOrCompletedAt = true; - // continue; - // } } - if (isDueOrCompletedAt) { - actionsDueOrCompletedAt[action._id] = action; + if (isDoneAt) { + actionsCompletedAt[action._id] = action; + } else if (isCanceledAt) { + actionsCanceledAt[action._id] = action; } else if (isCreatedAt) { actionsCreatedAt[action._id] = action; } @@ -126,24 +136,33 @@ const itemsForReportsSelector = selectorFamily({ for (const consultation of person.consultations || []) { if (!filterItemByTeam(consultation, 'teams')) continue; if (Array.isArray(consultation.teams)) { - let isDueOrCompletedAt = false; + let isDoneAt = false; + let isCanceledAt = false; let isCreatedAt = false; for (const team of consultation.teams) { const { isoStartDate, isoEndDate } = selectedTeamsObjectWithOwnPeriod[team] ?? defaultIsoDates; - if (consultation.status !== TODO && consultation.completedAt >= isoStartDate && consultation.completedAt < isoEndDate) { - isDueOrCompletedAt = true; + if (consultation.completedAt >= isoStartDate && consultation.completedAt < isoEndDate) { + if (consultation.status === CANCEL) { + isCanceledAt = true; + continue; + } + if (consultation.status === DONE) { + isDoneAt = true; + continue; + } continue; } if (consultation.createdAt >= isoStartDate && consultation.createdAt < isoEndDate) { - isCreatedAt = true; + if (consultation.status === TODO) { + isCreatedAt = true; + continue; + } } - // if (consultation.status !== TODO) continue; - // if (consultation.dueAt >= isoStartDate && consultation.dueAt < isoEndDate) { - // isDueOrCompletedAt = true; - // } } - if (isDueOrCompletedAt) { - consultationsDueOrCompletedAt[consultation._id] = consultation; + if (isDoneAt) { + consultationsCompletedAt[consultation._id] = consultation; + } else if (isCanceledAt) { + consultationsCanceledAt[consultation._id] = consultation; } else if (isCreatedAt) { consultationsCreatedAt[consultation._id] = consultation; } @@ -206,9 +225,11 @@ const itemsForReportsSelector = selectorFamily({ return { personsCreated: Object.values(personsCreated), personsUpdated: Object.values(personsUpdated), - actionsDueOrCompletedAt: Object.values(actionsDueOrCompletedAt), + actionsCompletedAt: Object.values(actionsCompletedAt), + actionsCanceledAt: Object.values(actionsCanceledAt), actionsCreatedAt: Object.values(actionsCreatedAt), - consultationsDueOrCompletedAt: Object.values(consultationsDueOrCompletedAt), + consultationsCompletedAt: Object.values(consultationsCompletedAt), + consultationsCanceledAt: Object.values(consultationsCanceledAt), consultationsCreatedAt: Object.values(consultationsCreatedAt), comments: Object.values(comments), commentsMedical: Object.values(commentsMedical), @@ -265,9 +286,11 @@ const View = () => { const { personsCreated, - actionsDueOrCompletedAt, + actionsCompletedAt, + actionsCanceledAt, actionsCreatedAt, - consultationsDueOrCompletedAt, + consultationsCompletedAt, + consultationsCanceledAt, consultationsCreatedAt, comments, commentsMedical, @@ -390,9 +413,11 @@ const View = () => {