Skip to content

Commit

Permalink
handle invalid states in getArgs()
Browse files Browse the repository at this point in the history
  • Loading branch information
vd1992 committed Jan 16, 2025
1 parent 2e5709a commit a3ff69b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,8 @@ const GovFields = ({ labels }: SubExperienceFormProps) => {
resetDirtyField("classificationLevel");
}

/**
* Wipe position type field if employment type changes, setting it to null rather than just reset incase the user default is bad
*/
if (
watchGovEmploymentType !== WorkExperienceGovEmployeeType.Indeterminate
) {
resetField("govPositionType", { keepDirty: false, defaultValue: null });
if (watchGovEmploymentType) {
resetDirtyField("govPositionType");
}

if (watchGovEmploymentType !== WorkExperienceGovEmployeeType.Contractor) {
Expand Down
13 changes: 12 additions & 1 deletion apps/web/src/hooks/useExperienceMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CreateEducationExperienceMutation,
CreatePersonalExperienceMutation,
CreateWorkExperienceMutation,
GovEmployeeType,
graphql,
} from "@gc-digital-talent/graphql";

Expand Down Expand Up @@ -158,10 +159,20 @@ export const useExperienceMutations = (
id: string,
values: ExperienceDetailsSubmissionData,
): ExperienceMutationArgs => {
// users may have invalid WorkExperience state with govEmploymentType TERM and non-null govPositionType
let massagedValues = values;

Check failure on line 163 in apps/web/src/hooks/useExperienceMutations.ts

View workflow job for this annotation

GitHub Actions / Lint

'massagedValues' is never reassigned. Use 'const' instead
if (
experienceType === "work" &&
!!massagedValues.govEmploymentType &&
massagedValues.govEmploymentType !== GovEmployeeType.Indeterminate
) {
massagedValues.govPositionType = null;
}

return {
id,
...(!!experienceType && {
[args[experienceType]]: values,
[args[experienceType]]: massagedValues,
}),
} as ExperienceMutationArgs;
};
Expand Down

0 comments on commit a3ff69b

Please sign in to comment.