Skip to content

Commit

Permalink
fix: shows Review page and related for multi-group forms (#4091)
Browse files Browse the repository at this point in the history
* Initial commit

* Fixes tests

* Fixes logical error with showReviewPage

---------

Co-authored-by: Tim Arney <[email protected]>
  • Loading branch information
thiessenp-cds and timarney authored Jul 31, 2024
1 parent 10d7fd6 commit b6298c8
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 9 deletions.
360 changes: 360 additions & 0 deletions __fixtures__/testDataWithGroupsLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,360 @@
{
"titleEn": "show-hide-groups-test",
"titleFr": "[FR]show-hide-groups-test",
"introduction": {
"descriptionEn": "",
"descriptionFr": ""
},
"privacyPolicy": {
"descriptionEn": "Privacy statement",
"descriptionFr": "[FR]Privacy statement"
},
"confirmation": {
"descriptionEn": "Confirmation message",
"descriptionFr": "[FR]Confirmation message",
"referrerUrlEn": "",
"referrerUrlFr": ""
},
"layout": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"elements": [
{
"id": 8,
"type": "radio",
"properties": {
"choices": [
{
"en": "A",
"fr": "[FR]A"
},
{
"en": "B",
"fr": "[FR]B"
}
],
"titleEn": "P3-Q1",
"titleFr": "[FR]P3-Q1",
"validation": {
"required": false
},
"subElements": [],
"descriptionEn": "",
"descriptionFr": "",
"placeholderEn": "",
"placeholderFr": "",
"conditionalRules": []
}
},
{
"id": 9,
"type": "textField",
"properties": {
"choices": [
{
"en": "",
"fr": ""
}
],
"titleEn": "P3-Q1-A",
"titleFr": "[FR]P3-Q1-A",
"validation": {
"required": false
},
"subElements": [],
"descriptionEn": "",
"descriptionFr": "",
"placeholderEn": "",
"placeholderFr": "",
"conditionalRules": [
{
"choiceId": "8.0"
}
]
}
},
{
"id": 10,
"type": "textField",
"properties": {
"choices": [
{
"en": "",
"fr": ""
}
],
"titleEn": "P3-Q1-B",
"titleFr": "[FR]P3-Q1-B",
"validation": {
"required": false
},
"subElements": [],
"descriptionEn": "",
"descriptionFr": "",
"placeholderEn": "",
"placeholderFr": "",
"conditionalRules": [
{
"choiceId": "8.1"
}
]
}
},
{
"id": 5,
"type": "radio",
"properties": {
"choices": [
{
"en": "A",
"fr": "[FR]A"
},
{
"en": "B",
"fr": "[FR]B"
}
],
"titleEn": "P2-Q1",
"titleFr": "[FR]P2-Q1",
"validation": {
"required": false
},
"subElements": [],
"descriptionEn": "",
"descriptionFr": "",
"placeholderEn": "",
"placeholderFr": "",
"conditionalRules": []
}
},
{
"id": 6,
"type": "textField",
"properties": {
"choices": [
{
"en": "",
"fr": ""
}
],
"titleEn": "P2-Q1-A",
"titleFr": "[FR]P2-Q1-A",
"validation": {
"required": false
},
"subElements": [],
"descriptionEn": "",
"descriptionFr": "",
"placeholderEn": "",
"placeholderFr": "",
"conditionalRules": [
{
"choiceId": "5.0"
}
]
}
},
{
"id": 7,
"type": "textField",
"properties": {
"choices": [
{
"en": "",
"fr": ""
}
],
"titleEn": "P2-Q1-B",
"titleFr": "[FR]P2-Q1-B",
"validation": {
"required": false
},
"subElements": [],
"descriptionEn": "",
"descriptionFr": "",
"placeholderEn": "",
"placeholderFr": "",
"conditionalRules": [
{
"choiceId": "5.1"
}
]
}
},
{
"id": 2,
"type": "radio",
"properties": {
"choices": [
{
"en": "A",
"fr": "[FR]A"
},
{
"en": "B",
"fr": "[FR]B"
}
],
"titleEn": "P1-Q1",
"titleFr": "[FR]P1-Q1",
"validation": {
"required": false
},
"subElements": [],
"descriptionEn": "",
"descriptionFr": "",
"placeholderEn": "",
"placeholderFr": "",
"conditionalRules": []
}
},
{
"id": 3,
"type": "textField",
"properties": {
"choices": [
{
"en": "",
"fr": ""
}
],
"titleEn": "P1-Q1-A",
"titleFr": "[FR]P1-Q1-A",
"validation": {
"required": false
},
"subElements": [],
"descriptionEn": "",
"descriptionFr": "",
"placeholderEn": "",
"placeholderFr": "",
"conditionalRules": [
{
"choiceId": "2.0"
}
]
}
},
{
"id": 4,
"type": "textField",
"properties": {
"choices": [
{
"en": "",
"fr": ""
}
],
"titleEn": "P1-Q1-B",
"titleFr": "[FR]P1-Q1-B",
"validation": {
"required": false
},
"subElements": [],
"descriptionEn": "",
"descriptionFr": "",
"placeholderEn": "",
"placeholderFr": "",
"conditionalRules": [
{
"choiceId": "2.1"
}
]
}
},
{
"id": 1,
"type": "radio",
"properties": {
"choices": [
{
"en": "A",
"fr": "[FR]A"
},
{
"en": "B",
"fr": "[FR]B"
},
{
"en": "C",
"fr": "[FR]C"
}
],
"titleEn": "Q1",
"titleFr": "[FR]Q1",
"validation": {
"required": false
},
"subElements": [],
"descriptionEn": "",
"descriptionFr": "",
"placeholderEn": "",
"placeholderFr": "",
"conditionalRules": []
}
}
],
"groups": {
"start": {
"name": "Start",
"titleEn": "Beginning",
"titleFr": "Beginning",
"autoFlow": false,
"elements": ["1"],
"nextAction": [
{
"groupId": "84b36e7b-2c6c-40be-ad22-1abd24c38019",
"choiceId": "1.0"
},
{
"groupId": "6365ee9b-1caa-4a08-b53d-ecfc2a9dd08f",
"choiceId": "1.1"
},
{
"groupId": "1231e20c-080e-4119-9774-33d829f290da",
"choiceId": "1.2"
}
]
},
"84b36e7b-2c6c-40be-ad22-1abd24c38019": {
"name": "P1",
"titleEn": "P1",
"titleFr": "[FR]P1",
"autoFlow": false,
"elements": ["2", "3", "4"],
"nextAction": "review"
},
"6365ee9b-1caa-4a08-b53d-ecfc2a9dd08f": {
"name": "P2",
"titleEn": "P2",
"titleFr": "[FR]P2",
"autoFlow": false,
"elements": ["5", "6", "7"],
"nextAction": "review"
},
"1231e20c-080e-4119-9774-33d829f290da": {
"name": "P3",
"titleEn": "P3",
"titleFr": "[FR]P3",
"autoFlow": true,
"elements": ["8", "9", "10"],
"nextAction": "review"
},
"review": {
"name": "Review",
"titleEn": "Review",
"titleFr": "Review",
"elements": [],
"nextAction": "end"
},
"end": {
"name": "End",
"titleEn": "End",
"titleFr": "End",
"elements": []
}
},
"groupsLayout": [
"84b36e7b-2c6c-40be-ad22-1abd24c38019",
"6365ee9b-1caa-4a08-b53d-ecfc2a9dd08f",
"1231e20c-080e-4119-9774-33d829f290da"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { safeJSONParse } from "@lib/utils";
import { ErrorSaving } from "@formBuilder/components/shared/ErrorSaving";
import { toast } from "@formBuilder/components/shared";
import { defaultForm } from "@lib/store/defaults";
import { showReviewPage } from "@lib/utils/form-builder/showReviewPage";

export const Preview = ({
disableSubmit = true,
Expand Down Expand Up @@ -94,6 +95,8 @@ export const Preview = ({

const hasHydrated = useRehydrate();

const isShowReviewPage = showReviewPage(formRecord.form);

if (isPastClosingDate) {
return (
<div className="max-w-4xl">
Expand Down Expand Up @@ -205,7 +208,9 @@ export const Preview = ({
fallBack={() => {
return (
<>
{allowGrouping && <BackButton language={language} />}
{allowGrouping && isShowReviewPage && (
<BackButton language={language} />
)}
<Button
type="submit"
id="SubmitButton"
Expand Down
Loading

0 comments on commit b6298c8

Please sign in to comment.