From 54119bfeb0c5eda3b12a2ff75a9c20c477f027a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Demazi=C3=A8re?= Date: Tue, 23 Apr 2024 18:14:40 +0200 Subject: [PATCH] Fix restore favorite mail (#138) * fix: states cohesion feat: person mail with star feat: contactAttempts ordered by date DESC * feat : refactor functions * feat: questionnaire availability checked with dates * fix: remove unused pathalue * fix: identification persist AOC state on answer handling * fix: update eventListener with latest addNewState --- package.json | 2 +- src/pages/Home.jsx | 17 +- src/pages/SuiviPage.jsx | 2 +- src/pages/SurveyUnitPage.jsx | 11 +- src/ui/Questionnaire/Questionnaires.jsx | 4 +- src/ui/SurveyCard.jsx | 3 +- src/ui/SurveyUnit/ContactAttemptForm.jsx | 13 +- src/ui/SurveyUnit/ContactOutcomeForm.jsx | 10 +- src/ui/SurveyUnit/ContactsCard.jsx | 18 +- src/ui/SurveyUnit/IdentificationCard.jsx | 10 +- src/ui/SurveyUnit/PersonsCard.jsx | 44 ++++- src/ui/SurveyUnit/SurveyUnitHeader.jsx | 12 +- src/ui/TextWithLabel.jsx | 7 +- src/utils/functions/convertSUStateInToDo.js | 2 +- src/utils/functions/seeder.js | 22 ++- src/utils/functions/surveyUnitFunctions.js | 166 ++++++++++-------- .../functions/surveyUnitFunctions.test.js | 56 +++--- src/utils/hooks/useIdentificationQuestions.js | 18 +- src/utils/hooks/useQueenListener.js | 7 +- 19 files changed, 258 insertions(+), 166 deletions(-) diff --git a/package.json b/package.json index 9c30790b5..7e5a4028d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pearl", - "version": "2.0.7", + "version": "2.0.8", "private": true, "dependencies": { "@emotion/react": "^11.11.1", diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index 18097f0a7..e563ddfd9 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import { SidebarLayout } from '../ui/SidebarLayout'; import Paper from '@mui/material/Paper'; import Stack from '@mui/material/Stack'; @@ -24,11 +24,24 @@ import { SurveyCard } from '../ui/SurveyCard'; import { Row } from '../ui/Row'; import { Select } from '../ui/Select'; import { seedData } from '../utils/functions/seeder'; +import { persistSurveyUnit, updateStateWithDates } from '../utils/functions'; export function Home() { const surveyUnits = useSurveyUnits(); const missingSurveyUnitIds = useMissingSurveyUnits().map(surveyUnit => surveyUnit.id); const filter = useSearchFilter(); + const [shouldCheckState, setShouldCheckState] = useState(true); + + useEffect(() => { + if (shouldCheckState && surveyUnits.length > 0) { + // persist state VIC when identificationStartDate is reached + setShouldCheckState(false); + surveyUnits.forEach(su => { + const newStates = updateStateWithDates(su); + persistSurveyUnit({ ...su, states: newStates }); + }); + } + }, [surveyUnits.length]); const filteredSurveyUnits = filterSurveyUnits(surveyUnits, filter); const isDev = filteredSurveyUnits.length === 0 && window.location.hostname === 'localhost'; @@ -235,7 +248,7 @@ function Sidebar({ surveyUnits }) {
diff --git a/src/pages/SuiviPage.jsx b/src/pages/SuiviPage.jsx index 214bc74a4..956d501a1 100644 --- a/src/pages/SuiviPage.jsx +++ b/src/pages/SuiviPage.jsx @@ -429,7 +429,7 @@ function SurveyUnitRow({ surveyUnit }) { {isActive ? ( - #{surveyUnit.id} + #{surveyUnit.id} ) : ( `#${surveyUnit.id}` )} diff --git a/src/pages/SurveyUnitPage.jsx b/src/pages/SurveyUnitPage.jsx index 5c479ca2e..120c3d745 100644 --- a/src/pages/SurveyUnitPage.jsx +++ b/src/pages/SurveyUnitPage.jsx @@ -16,7 +16,7 @@ import NotInterestedIcon from '@mui/icons-material/NotInterested'; import Button from '@mui/material/Button'; import { Typography } from '../ui/Typography'; import { Questionnaires } from '../ui/Questionnaire/Questionnaires'; -import { addNewState, getLastState } from '../utils/functions'; +import { addNewState, getLastState, persistSurveyUnit } from '../utils/functions'; import { useEffect } from 'react'; import { surveyUnitStateEnum } from '../utils/enum/SUStateEnum'; @@ -26,9 +26,10 @@ export function SurveyUnitPage() { useEffect(() => { if (surveyUnit !== undefined) { - const lastState = getLastState(surveyUnit); - if (lastState.type === surveyUnitStateEnum.VISIBLE_AND_CLICKABLE.type) { - addNewState(surveyUnit, surveyUnitStateEnum.IN_PREPARATION.type); + const lastState = getLastState(surveyUnit.states); + if (lastState?.type === surveyUnitStateEnum.VISIBLE_AND_CLICKABLE.type) { + const newStates = addNewState(surveyUnit, surveyUnitStateEnum.IN_PREPARATION.type); + persistSurveyUnit({ ...surveyUnit, states: newStates }); } } }, [surveyUnit]); @@ -74,7 +75,7 @@ export function SurveyUnitPage() { - + diff --git a/src/ui/Questionnaire/Questionnaires.jsx b/src/ui/Questionnaire/Questionnaires.jsx index 00ed06f45..ebfb60a01 100644 --- a/src/ui/Questionnaire/Questionnaires.jsx +++ b/src/ui/Questionnaire/Questionnaires.jsx @@ -8,10 +8,11 @@ import Button from '@mui/material/Button'; import LibraryBooksIcon from '@mui/icons-material/LibraryBooks'; import StickyNote2Icon from '@mui/icons-material/StickyNote2'; import D from 'i18n'; - +import { isQuestionnaireAvailable } from '../../utils/functions'; export function Questionnaires({ surveyUnit }) { const { id } = surveyUnit; + const isAvailable = isQuestionnaireAvailable(surveyUnit)(false); return ( @@ -25,6 +26,7 @@ export function Questionnaires({ surveyUnit }) {