diff --git a/api/app/Generators/ApplicationDocGenerator.php b/api/app/Generators/ApplicationDocGenerator.php index 89c85478901..11e4397261e 100644 --- a/api/app/Generators/ApplicationDocGenerator.php +++ b/api/app/Generators/ApplicationDocGenerator.php @@ -89,7 +89,22 @@ public function generate(): self } if (isset($snapshot['experiences'])) { - $experiences = Experience::hydrateSnapshot($snapshot['experiences']); + $snapshotExperiences = $snapshot['experiences']; + + // the snapshot stores the department and classification models connected by relation + // to render with GeneratesUserDoc, map the model to a string with the appropriate property name + foreach ($snapshotExperiences as &$experience) { + if ($experience['__typename'] === 'WorkExperience') { + if (isset($experience['department'])) { + $experience['departmentId'] = $experience['department']['id']; + } + if (isset($experience['classification'])) { + $experience['classificationId'] = $experience['classification']['id']; + } + } + } + + $experiences = Experience::hydrateSnapshot($snapshotExperiences); $this->experiences($section, collect($experiences), false, 2); } diff --git a/api/app/Models/WorkExperience.php b/api/app/Models/WorkExperience.php index d0e90997c42..c8ca1a0e902 100644 --- a/api/app/Models/WorkExperience.php +++ b/api/app/Models/WorkExperience.php @@ -2,6 +2,8 @@ namespace App\Models; +use App\Enums\CafForce; +use App\Enums\EmploymentCategory; use App\Models\Scopes\MatchExperienceType; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -83,7 +85,24 @@ class WorkExperience extends Experience public function getTitle(?string $lang = 'en'): string { - return sprintf('%s %s %s', $this->role, Lang::get('common.at', [], $lang), $this->organization); + if ($this->employment_category === EmploymentCategory::EXTERNAL_ORGANIZATION->name) { + return sprintf('%s %s %s', $this->role, Lang::get('common.with', [], $lang), $this->organization); + } + + if ($this->employment_category === EmploymentCategory::GOVERNMENT_OF_CANADA->name) { + /** @var Department | null $department */ + $department = $this->department_id ? Department::find($this->department_id) : null; + + return sprintf('%s %s %s', $this->role, Lang::get('common.with', [], $lang), $department ? $department->name[$lang] : Lang::get('common.not_found', [], $lang)); + } + + if ($this->employment_category === EmploymentCategory::CANADIAN_ARMED_FORCES->name) { + $caf_force = $this->caf_force ? CafForce::localizedString($this->caf_force)[$lang] : Lang::get('common.not_found', [], $lang); + + return sprintf('%s %s %s', $this->role, Lang::get('common.with', [], $lang), $caf_force); + } + + return sprintf('%s %s %s', $this->role, Lang::get('common.with', [], $lang), $this->organization); } // extends dateRange, check if the end date is in the future and append a message if needed diff --git a/api/app/Traits/Generator/GeneratesUserDoc.php b/api/app/Traits/Generator/GeneratesUserDoc.php index 8ac72a3b435..e0c14b18ae1 100644 --- a/api/app/Traits/Generator/GeneratesUserDoc.php +++ b/api/app/Traits/Generator/GeneratesUserDoc.php @@ -342,7 +342,7 @@ public function experience(Section $section, AwardExperience|CommunityExperience sprintf( '%s %s %s', $experience->role, - Lang::get('common.at', [], $this->lang), + Lang::get('common.with', [], $this->lang), $this->localizeEnum($experience->caf_force, CafForce::class), ), @@ -362,12 +362,12 @@ public function experience(Section $section, AwardExperience|CommunityExperience ); } elseif ($experience->employment_category === EmploymentCategory::GOVERNMENT_OF_CANADA->name) { /** @var Department | null $department */ - $department = Department::find($experience->department_id); + $department = $experience->department_id ? Department::find($experience->department_id) : null; $section->addTitle( sprintf( '%s %s %s', $experience->role, - Lang::get('common.at', [], $this->lang), + Lang::get('common.with', [], $this->lang), $department ? $department->name[$this->lang] : Lang::get('common.not_found', [], $this->lang), ), $headingRank diff --git a/api/lang/en/common.php b/api/lang/en/common.php index c29de0d4d66..00f493001a2 100644 --- a/api/lang/en/common.php +++ b/api/lang/en/common.php @@ -17,6 +17,7 @@ 'status' => 'Status', 'present' => 'Present', 'at' => 'at', + 'with' => 'with', 'not_provided' => 'Not provided', 'not_sure' => 'Not sure', 'expected_end_date' => '(Expected end date)', diff --git a/api/lang/fr/common.php b/api/lang/fr/common.php index 2aab12122e8..4a1e649502e 100644 --- a/api/lang/fr/common.php +++ b/api/lang/fr/common.php @@ -17,6 +17,7 @@ 'status' => 'Statut', 'present' => 'Aujourd’hui', 'at' => 'à', + 'with' => 'à', 'not_provided' => 'Renseignements manquants', 'not_sure' => 'Pas certain', 'expected_end_date' => '(Date de fin prévue)', diff --git a/apps/web/src/components/ExperienceFormFields/WorkFields/GovFields.tsx b/apps/web/src/components/ExperienceFormFields/WorkFields/GovFields.tsx index 9a60778f1dc..e8997c8a420 100644 --- a/apps/web/src/components/ExperienceFormFields/WorkFields/GovFields.tsx +++ b/apps/web/src/components/ExperienceFormFields/WorkFields/GovFields.tsx @@ -337,7 +337,7 @@ const GovFields = ({ labels }: SubExperienceFormProps) => { label={labels.classificationGroup} name="classificationGroup" nullSelection={intl.formatMessage( - uiMessages.nullSelectionOptionLevel, + uiMessages.nullSelectionOptionGroup, )} rules={{ required: intl.formatMessage(errorMessages.required), diff --git a/apps/web/src/components/ExperienceFormFields/WorkFields/WorkFields.tsx b/apps/web/src/components/ExperienceFormFields/WorkFields/WorkFields.tsx index af0083262f6..6db35638af4 100644 --- a/apps/web/src/components/ExperienceFormFields/WorkFields/WorkFields.tsx +++ b/apps/web/src/components/ExperienceFormFields/WorkFields/WorkFields.tsx @@ -1,7 +1,7 @@ import { useIntl, defineMessage, MessageDescriptor } from "react-intl"; import { useQuery } from "urql"; import { useFormContext, useWatch } from "react-hook-form"; -import { useEffect } from "react"; +import { useEffect, useRef } from "react"; import { FieldLabels, @@ -92,6 +92,9 @@ const WorkFields = ({ labels }: SubExperienceFormProps) => { const { resetField, formState } = useFormContext(); + const prevEmploymentCategory = useRef( + formState.defaultValues?.employmentCategory, + ); const watchEmploymentCategory = useWatch<{ employmentCategory: EmploymentCategory; }>({ @@ -118,7 +121,7 @@ const WorkFields = ({ labels }: SubExperienceFormProps) => { resetField(name, { keepDirty: false, defaultValue: null }); }; - if (formState.dirtyFields.employmentCategory) { + if (prevEmploymentCategory.current !== watchEmploymentCategory) { resetDirtyField("team"); // both external and goc // external fields @@ -146,7 +149,9 @@ const WorkFields = ({ labels }: SubExperienceFormProps) => { resetDirtyField("currentRole"); resetDirtyField("endDate"); } - }, [formState.dirtyFields, watchEmploymentCategory, resetField]); + + prevEmploymentCategory.current = watchEmploymentCategory; + }, [watchEmploymentCategory, resetField]); return (
diff --git a/apps/web/src/components/Profile/components/GovernmentInformation/FormFields.tsx b/apps/web/src/components/Profile/components/GovernmentInformation/FormFields.tsx index 0ee79b85742..0fcf6785a2d 100644 --- a/apps/web/src/components/Profile/components/GovernmentInformation/FormFields.tsx +++ b/apps/web/src/components/Profile/components/GovernmentInformation/FormFields.tsx @@ -251,11 +251,9 @@ const FormFields = ({ id="currentClassificationGroup" label={labels.currentClassificationGroup} name="currentClassificationGroup" - nullSelection={intl.formatMessage({ - defaultMessage: "Select a group", - id: "9Upe1V", - description: "Null selection for form.", - })} + nullSelection={intl.formatMessage( + uiMessages.nullSelectionOptionGroup, + )} rules={{ required: intl.formatMessage(errorMessages.required), }} diff --git a/apps/web/src/lang/fr.json b/apps/web/src/lang/fr.json index 964d42f373b..de86432d313 100644 --- a/apps/web/src/lang/fr.json +++ b/apps/web/src/lang/fr.json @@ -2263,10 +2263,6 @@ "defaultMessage": "Organisation", "description": "Label displayed on Work Experience form for organization input" }, - "9Upe1V": { - "defaultMessage": "Sélectionnez un groupe", - "description": "Null selection for form." - }, "9VPBwR": { "defaultMessage": "Homme danseur en régalia traditionnelle.", "description": "Indigenous Apprenticeship lower back image text alternative" diff --git a/apps/web/src/utils/experienceUtils.tsx b/apps/web/src/utils/experienceUtils.tsx index 59a9cdfd29b..e89287d2459 100644 --- a/apps/web/src/utils/experienceUtils.tsx +++ b/apps/web/src/utils/experienceUtils.tsx @@ -639,14 +639,41 @@ const getWorkExperienceDefaultValues = ( cafForce, cafRank, } = experience; + + const isIndeterminate = + govEmploymentType?.value === WorkExperienceGovEmployeeType.Indeterminate; + const indeterminateActing = + isIndeterminate && govPositionType?.value === GovPositionType.Acting; + const indeterminateAssignment = + isIndeterminate && govPositionType?.value === GovPositionType.Assignment; + const indeterminateSecondment = + isIndeterminate && govPositionType?.value === GovPositionType.Secondment; + + const expectedEndDate = + govEmploymentType?.value === WorkExperienceGovEmployeeType.Student || + govEmploymentType?.value === WorkExperienceGovEmployeeType.Casual || + govEmploymentType?.value === WorkExperienceGovEmployeeType.Term || + indeterminateActing || + indeterminateAssignment || + indeterminateSecondment; + + let currentRole = false; + + if (endDate) { + currentRole = false; + if (expectedEndDate) { + currentRole = endDate >= strToFormDate(new Date().toISOString()); + } + } else { + currentRole = true; + } + return { role, organization, team: division, startDate, - currentRole: endDate - ? endDate >= strToFormDate(new Date().toISOString()) // today's date - : true, + currentRole, endDate, employmentCategory: employmentCategory?.value, extSizeOfOrganization: extSizeOfOrganization?.value, diff --git a/packages/i18n/src/lang/fr.json b/packages/i18n/src/lang/fr.json index 883c5c238dd..22afa90a280 100644 --- a/packages/i18n/src/lang/fr.json +++ b/packages/i18n/src/lang/fr.json @@ -1139,6 +1139,10 @@ "defaultMessage": "Technologie de l’information", "description": "Full name of abbreviation for IT" }, + "nICORU": { + "defaultMessage": "Sélectionnez un groupe", + "description": "Null selection og group for select input." + }, "nMX0n8": { "defaultMessage": "Vous n’avez ajouté aucune expérience de ce type.", "description": "Message to user when no experiences of that type exist." diff --git a/packages/i18n/src/messages/uiMessages.ts b/packages/i18n/src/messages/uiMessages.ts index 00fdc520e79..245423c1b23 100644 --- a/packages/i18n/src/messages/uiMessages.ts +++ b/packages/i18n/src/messages/uiMessages.ts @@ -131,6 +131,11 @@ const uiMessages = defineMessages({ id: "xEkbvy", description: "Null selection of level for select input", }, + nullSelectionOptionGroup: { + defaultMessage: "Select a group", + id: "nICORU", + description: "Null selection og group for select input.", + }, }); export default uiMessages;