-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: refactor modal opening in project area page #3211
Merged
RRanath
merged 5 commits into
main
from
NDT-282-Refactor-how-we-handle-project-area-modal-opening
May 3, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f1929b1
chore: refactor modal opening in project area page
RRanath 73a4ca1
chore: refactor type
RRanath 9aa8198
chore: refactor code
RRanath 43b0cda
Merge branch 'main' into NDT-282-Refactor-how-we-handle-project-area-…
RRanath a11dac3
Merge branch 'main' into NDT-282-Refactor-how-we-handle-project-area-…
RRanath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -379,6 +379,42 @@ const ApplicationForm: React.FC<Props> = ({ | |||||||||
const isOtherFundingSourcesPage = sectionName === 'otherFundingSources'; | ||||||||||
const isReviewPage = sectionName === 'review'; | ||||||||||
|
||||||||||
const allZoneIntake = | ||||||||||
isProjectAreaPage && | ||||||||||
acceptedProjectAreasArray.length === | ||||||||||
(sectionSchema.properties?.geographicArea as any)?.items?.enum?.length; | ||||||||||
|
||||||||||
const isZoneSelectionValid = ( | ||||||||||
geographicAreaInput: number[], | ||||||||||
firstNationsLed: boolean, | ||||||||||
nullAllowed: boolean = true | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here that bools should use the
Suggested change
|
||||||||||
) => { | ||||||||||
// null selection not allowed in submitted project area page | ||||||||||
if (!nullAllowed && geographicAreaInput?.length === 0) return false; | ||||||||||
return ( | ||||||||||
allZoneIntake || | ||||||||||
firstNationsLed || | ||||||||||
acceptedProjectAreasArray.includes(geographicAreaInput?.[0]) | ||||||||||
); | ||||||||||
}; | ||||||||||
|
||||||||||
const getProjectAreaModalType = ( | ||||||||||
geographicAreaInputChanged: boolean, | ||||||||||
firstNationsLedInputChanged: boolean | ||||||||||
) => { | ||||||||||
if (isSubmitted && geographicAreaInputChanged) { | ||||||||||
// display new modal saying | ||||||||||
// Invalid selection. You have indicated that this project is not led or supported by First Nations, therefore, you may only choose from zones 1,2,3 or 6. | ||||||||||
return 'invalid-geographic-area'; | ||||||||||
} | ||||||||||
if (isSubmitted && firstNationsLedInputChanged) { | ||||||||||
// display modal saying | ||||||||||
// Invalid selection. Please first choose from zones 1,2,3 or 6 if this project is not supported or led by First Nations | ||||||||||
return 'first-nations-led'; | ||||||||||
} | ||||||||||
return 'pre-submitted'; | ||||||||||
}; | ||||||||||
|
||||||||||
const isSubmitEnabled = useMemo(() => { | ||||||||||
if (isUpdating) return false; | ||||||||||
|
||||||||||
|
@@ -455,17 +491,6 @@ const ApplicationForm: React.FC<Props> = ({ | |||||||||
} | ||||||||||
if (isProjectAreaPage) { | ||||||||||
const firstNationsLed = newFormSectionData?.firstNationsLed || false; | ||||||||||
const isGeographicAreaEmpty = | ||||||||||
newFormSectionData?.geographicArea?.[0] === 'undefined' || | ||||||||||
newFormSectionData?.geographicArea?.length === 0; | ||||||||||
const projectAreaAccepted = | ||||||||||
firstNationsLed || | ||||||||||
(!isGeographicAreaEmpty && | ||||||||||
(firstNationsLed || | ||||||||||
acceptedProjectAreasArray.includes( | ||||||||||
newFormSectionData?.geographicArea?.[0] | ||||||||||
))); | ||||||||||
const isZoneSpecificIntake = latestIntakeNumber !== 4; | ||||||||||
const geographicAreaInputChanged = | ||||||||||
typeof newFormSectionData?.geographicArea?.[0] !== 'undefined' && | ||||||||||
newFormSectionData?.geographicArea[0] !== | ||||||||||
|
@@ -474,30 +499,29 @@ const ApplicationForm: React.FC<Props> = ({ | |||||||||
typeof newFormSectionData?.firstNationsLed !== 'undefined' && | ||||||||||
firstNationsLed !== jsonData.projectArea?.firstNationsLed; | ||||||||||
|
||||||||||
if (isSubmitted && !projectAreaAccepted) { | ||||||||||
// revert form data | ||||||||||
newFormData = { | ||||||||||
...jsonData, | ||||||||||
}; | ||||||||||
if (geographicAreaInputChanged && isZoneSpecificIntake) { | ||||||||||
// display new modal saying | ||||||||||
// Invalid selection. You have indicated that this project is not led or supported by First Nations, therefore, you may only choose from zones 1,2,3 or 6. | ||||||||||
setProjectAreaModalType('invalid-geographic-area'); | ||||||||||
const projectAreaAccepted = isZoneSelectionValid( | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should stick to the
Suggested change
|
||||||||||
newFormSectionData?.geographicArea, | ||||||||||
firstNationsLed, | ||||||||||
!isSubmitted | ||||||||||
); | ||||||||||
|
||||||||||
if (!projectAreaAccepted) { | ||||||||||
if (isSubmitted) { | ||||||||||
// revert form data | ||||||||||
newFormData = { | ||||||||||
...jsonData, | ||||||||||
}; | ||||||||||
} | ||||||||||
if (firstNationsLedInputChanged && isZoneSpecificIntake) { | ||||||||||
// display modal saying | ||||||||||
// Invalid selection. Please first choose from zones 1,2,3 or 6 if this project is not supported or led by First Nations | ||||||||||
setProjectAreaModalType('first-nations-led'); | ||||||||||
setProjectAreaModalType( | ||||||||||
getProjectAreaModalType( | ||||||||||
geographicAreaInputChanged, | ||||||||||
firstNationsLedInputChanged | ||||||||||
) | ||||||||||
); | ||||||||||
|
||||||||||
if (geographicAreaInputChanged || firstNationsLedInputChanged) { | ||||||||||
projectAreaModal.open(); | ||||||||||
} | ||||||||||
} else if (!isSubmitted && !projectAreaAccepted && isZoneSpecificIntake) { | ||||||||||
setProjectAreaModalType('pre-submitted'); | ||||||||||
} | ||||||||||
if ( | ||||||||||
!projectAreaAccepted && | ||||||||||
(geographicAreaInputChanged || | ||||||||||
(firstNationsLedInputChanged && isZoneSpecificIntake)) | ||||||||||
) { | ||||||||||
projectAreaModal.open(); | ||||||||||
} | ||||||||||
|
||||||||||
// Setting below properties to handle validation errors separately in submission page | ||||||||||
|
@@ -507,11 +531,11 @@ const ApplicationForm: React.FC<Props> = ({ | |||||||||
); | ||||||||||
// calculating project area selection validity to clearout temporary values | ||||||||||
// calculated for error handling/error modals | ||||||||||
const projectAreaValid = | ||||||||||
newFormData?.projectArea?.firstNationsLed || | ||||||||||
acceptedProjectAreasArray.includes( | ||||||||||
newFormData?.projectArea?.geographicArea?.[0] | ||||||||||
); | ||||||||||
const projectAreaValid = isZoneSelectionValid( | ||||||||||
newFormData?.projectArea?.geographicArea, | ||||||||||
newFormData?.projectArea?.firstNationsLed | ||||||||||
); | ||||||||||
|
||||||||||
setIsProjectAreaInvalid(!projectAreaValid); | ||||||||||
} | ||||||||||
|
||||||||||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a bool, we should rename this to
isAllZoneIntake