Skip to content

Commit

Permalink
Merge pull request #201 from InseeFr/v2-fixStateData
Browse files Browse the repository at this point in the history
fix: stateData on orchestrator > collector
  • Loading branch information
ORogel authored Dec 14, 2022
2 parents 15d501d + 259eb59 commit 4d28393
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stromae",
"version": "2.2.11",
"version": "2.2.12",
"description": "Web application for the management of questionnaires powered by Lunatic",
"repository": {
"type": "git",
Expand Down
20 changes: 13 additions & 7 deletions src/components/orchestrator/collector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export const Orchestrator = ({
const [validationConfirmation, setValidationConfirmation] = useState(false);

const { stateData, data, personalization } = stromaeData;
const [currentStateData, setCurrentStateData] = useState(stateData);

const [validated, setValidated] = useState(
stateData?.state === 'VALIDATED' ||
stateData?.state === 'EXTRACTED' ||
stateData?.state === 'TOEXTRACT'
stateData &&
(stateData.state === 'VALIDATED' ||
stateData.state === 'EXTRACTED' ||
stateData.state === 'TOEXTRACT')
);

const { lunaticFetcher: suggesterFetcher } = useLunaticFetcher();
Expand Down Expand Up @@ -81,13 +83,15 @@ export const Orchestrator = ({
date: new Date().getTime(),
currentPage: currentPage,
};
setCurrentStateData(newStateData);
return newStateData;
};

const logoutAndClose = async () => {
if (!validated) {
const logoutAndCloseUpdateState = updateStateData();
const dataToSave = {
stateData: updateStateData(),
stateData: logoutAndCloseUpdateState,
data: getData(),
};
await save(dataToSave);
Expand All @@ -114,8 +118,9 @@ export const Orchestrator = ({
};
const validateQuestionnaire = () => {
setValidated(true);
const validateUpdateState = updateStateData(VALIDATED);
const dataToSave = {
stateData: updateStateData(VALIDATED),
stateData: validateUpdateState,
data: getData(),
};
save(dataToSave);
Expand All @@ -125,8 +130,9 @@ export const Orchestrator = ({
const onNext = () => {
if (currentPage === WELCOME_PAGE) setCurrentPage(page);
else {
const onNextUpdateState = updateStateData();
const dataToSave = {
stateData: updateStateData(),
stateData: onNextUpdateState,
data: getData(),
};
if (!isLastPage) {
Expand Down Expand Up @@ -225,7 +231,7 @@ export const Orchestrator = ({
<EndPage
logoutAndClose={logoutAndClose}
metadata={metadata}
stateData={stateData}
stateData={currentStateData}
currentPage={currentPage}
personalization={personalization}
/>
Expand Down

0 comments on commit 4d28393

Please sign in to comment.