-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : individual phone tracking + identification refactoring (#184)
* fix: jsx to tsx * feat: testing a new way of computing identifications (writing a simpler code) with telephone as a mean * fix: RadioLineProps label as possibly undefined * fix: started refactoring * fix: continuing refactoring * fix: started refactoring for identification * fix : import * fix: updated translations * fix: IdentificationQuestionValueOption renamed to IdentificationQuestionOption * fix: partial records for unused questions id, type expansion for generalizing to other configurations * fix : formatting * fix : typo * fix: formatting * fix: continuing refactoring * fix: bug fixes * fix : continue debugging * feat: add identifications questioning as differents files * fix: removed logs * fix: checkAvailability parameters fix * fix: add new state only when all previous questions have been answered * fix: removed all obselete files * fix: deleted obselete useIdentificationQuestion * fix : imports update, removed obselete code * fix: update imports * feat: add tests for checkAvailibility * fix: update file names for vite test inclusion * fix: made button label as optional * fix : update seeder to match new identification model * fix: typo * fix: made clearer comments * fix : making sure persistence is done everytime user select a field * feat: transmission with rules support for INDTEL * fix: update use effect to match new identification objects construction * fix: removed obselete tests * fix: added todo * fix: minor code quality improvement * fix: update identifcation questions names and values * feat: add all identification configuration entries * fix: reorder contactOutcome options * fix : add an object defining for each identification a pair value/label * fix: making sure identification is never null in case value retrieved from the api is null * fix: updated code for HOUSEF2F options mapping * fix: removed log * fix : add IdentificationConfiguration.HOUSEF2F for validity checking * fix: adapted validation for iasco by using identificationQuestionsTree options * fix: fixed switch case * fix : cognitive complexity * fix : formatting * fix: updated empty undefined identification handling * fix : removed duplicated code * fix: cleaner syntax, null identification in seeder * fix : removed imports * fix: formatting * fix : identificationIsFinished safe return * fix: code refactoring for handleResponse * fix: moved identificationIsFinished as its the condition for updateStates to be called * fix : improved use of allAnswered * fix: setting dialog id after iterating over all questions * fix : removed Object.entries nesting in Object.fromEntries * fix moved up availableQuestionIds computation in parent scope for resolving nesting issue * fix: renamed hook to match script name * fix : add unit tests for useIdentificationQuestions.ts * fix : applying useIdentificationQuestions * feat: add HOUSETEL questions * chore: rebase branch * feat: use optionsMap * fix: NOT_APPLICABLE swapped with DEFINITLY_UNAVAILABLE * feat: add a missing label translation * fix: removed unused file * fix: removed useless boolean since disabled is always false as Button is called if selectedOption is true * fix: disclaimer message for deprecated outcomes * fix : updated tests * fix : removed useless condition * feat : identificationIsFinished unit tests * feat : updated package.json version * fix: made responses as undefined for following questions after the selected one * fix: no default option selected for each dialog * fix: fixed imports * fix : made clear distinction between house identification and occupant identification * fix : add missing option values for identification * fix : clearer translation object name for house identification * fix : simpler handling of selected responses update, we only need to update current selected question and next ones * fix: merged conditionnal branches * fix: removed deprecated test * fix: using dictionnary instead of hardcoded value * fix: add return true for any conclusive value since its means identification is finished * fix: playwright tests --------- Co-authored-by: Lea Renaux <lea.renaux@insee.fr> Co-authored-by: Simon Demaziere <simon.demaziere@insee.fr> Co-authored-by: Emmanuel <demey.emmanuel@gmail.com>
- Loading branch information
1 parent
00eba83
commit ca3cf89
Showing
32 changed files
with
1,364 additions
and
826 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Typography } from '../../Typography'; | ||
import D from 'i18n'; | ||
import { Row } from '../../Row'; | ||
import Stack from '@mui/material/Stack'; | ||
import { SurveyUnit } from 'types/pearl'; | ||
import { Card, CardContent } from '@mui/material'; | ||
import AssignmentIndOutlinedIcon from '@mui/icons-material/AssignmentIndOutlined'; | ||
import { ButtonLine } from 'ui/ButtonLine'; | ||
import { IdentificationQuestionsId } from 'utils/enum/identifications/IdentificationsQuestions'; | ||
import { useIdentificationQuestions } from 'utils/hooks/useIdentificationQuestions'; | ||
import { IdentificationDialog } from './IdentificationDialog'; | ||
|
||
type IdentificationCardProps = { | ||
surveyUnit: SurveyUnit; | ||
}; | ||
|
||
export function IdentificationCard({ surveyUnit }: Readonly<IdentificationCardProps>) { | ||
const { | ||
questions, | ||
responses, | ||
selectedDialogId, | ||
availableQuestions, | ||
setSelectedDialogId, | ||
handleResponse, | ||
} = useIdentificationQuestions(surveyUnit); | ||
|
||
return ( | ||
<Card elevation={0}> | ||
<CardContent> | ||
<Stack gap={3}> | ||
<Row gap={1}> | ||
<AssignmentIndOutlinedIcon fontSize="large" /> | ||
<Typography as="h2" variant="xl" fontWeight={700}> | ||
{D.identification} | ||
</Typography> | ||
</Row> | ||
<Stack gap={1}> | ||
{(Object.keys(questions) as IdentificationQuestionsId[]).map(questionId => ( | ||
<ButtonLine | ||
key={questionId} | ||
onClick={() => setSelectedDialogId(questionId)} | ||
label={responses[questionId]?.label ?? questions[questionId]?.text} | ||
checked={!!(responses[questionId] && availableQuestions[questionId])} | ||
disabled={!availableQuestions[questionId]} | ||
></ButtonLine> | ||
))} | ||
</Stack> | ||
</Stack> | ||
</CardContent> | ||
{selectedDialogId && ( | ||
<IdentificationDialog | ||
questionId={selectedDialogId} | ||
key={`dialog-${selectedDialogId}`} | ||
question={questions[selectedDialogId]} | ||
defaultOption={responses[selectedDialogId] ?? undefined} | ||
onSubmit={handleResponse} | ||
onClose={() => { | ||
setSelectedDialogId(undefined); | ||
}} | ||
/> | ||
)} | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { | ||
Dialog, | ||
DialogTitle, | ||
DialogContent, | ||
RadioGroup, | ||
Stack, | ||
DialogActions, | ||
Button, | ||
} from '@mui/material'; | ||
import { useState } from 'react'; | ||
import { RadioLine } from 'ui/RadioLine'; | ||
import { IdentificationQuestionsId } from 'utils/enum/identifications/IdentificationsQuestions'; | ||
import { | ||
IdentificationQuestionValue, | ||
IdentificationQuestionOption, | ||
} from 'utils/functions/identifications/identificationFunctions'; | ||
import D from 'i18n'; | ||
|
||
interface IdentificationDialogProps { | ||
question?: IdentificationQuestionValue; | ||
questionId: IdentificationQuestionsId; | ||
defaultOption?: IdentificationQuestionOption; | ||
onClose: () => void; | ||
onSubmit: (questionId: IdentificationQuestionsId, option: IdentificationQuestionOption) => void; | ||
} | ||
|
||
export function IdentificationDialog({ | ||
question, | ||
questionId, | ||
defaultOption, | ||
onClose, | ||
onSubmit, | ||
}: Readonly<IdentificationDialogProps>) { | ||
const options = question?.options; | ||
const [selectedOption, setSelectedOption] = useState(defaultOption); | ||
|
||
const handleChange = (newOption: IdentificationQuestionOption) => { | ||
setSelectedOption(newOption); | ||
}; | ||
|
||
return ( | ||
<Dialog maxWidth="sm" open={question ? question.text.length > 0 : false} onClose={onClose}> | ||
<DialogTitle id="identification-title">{question?.text}</DialogTitle> | ||
<DialogContent> | ||
<RadioGroup | ||
onChange={e => | ||
handleChange({ | ||
value: e.target.value, | ||
label: options?.find(o => o.value === e.target.value)?.label ?? D.missingLabel, | ||
concluding: | ||
options?.find(o => o.value === e.target.value)?.concluding ?? D.missingLabel, | ||
}) | ||
} | ||
defaultValue={selectedOption?.value} | ||
aria-labelledby="identification-title" | ||
name="identification-radio-group" | ||
> | ||
<Stack gap={1}> | ||
{options?.map((option: IdentificationQuestionOption) => ( | ||
<RadioLine | ||
value={option.value} | ||
key={option.value} | ||
label={option.label} | ||
disabled={false} | ||
/> | ||
))} | ||
</Stack> | ||
</RadioGroup> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button type="button" color="primary" variant="contained" onClick={onClose}> | ||
{D.cancelButton} | ||
</Button> | ||
{selectedOption && ( | ||
<Button | ||
variant="contained" | ||
type="button" | ||
disabled={false} | ||
onClick={() => { | ||
onClose(); | ||
onSubmit(questionId, selectedOption); | ||
}} | ||
> | ||
{D.confirmButton} | ||
</Button> | ||
)} | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
Oops, something went wrong.