11<template >
22 <!-- add view -->
3- <div v-if =" icraWorkExperienceEligibilityFormMode === 'edit' || icraWorkExperienceEligibilityFormMode === 'add'" >
3+ <div v-if =" employmentExperienceFormMode === 'edit' || employmentExperienceFormMode === 'add'" >
44 <ECEHeader title =" Employment experience references" />
55 <br />
66 <p >
8484 </v-row >
8585 <v-row v-if =" Array.isArray(modelValue) && modelValue.length > 0" v-for =" (reference, index) in modelValue" :key =" index" >
8686 <v-col sm =" 12" md =" 10" lg =" 8" xl =" 6" >
87- <EceIcraWorkExperienceEligibilityCard
88- :reference =" reference"
89- @edit =" handleEdit"
90- @delete =" (internationalCertification) => handleDelete(internationalCertification, index)"
91- />
87+ <EceEmploymentExperienceCard :reference =" reference" @edit =" handleEdit" @delete =" (reference) => handleDelete(reference, index)" />
9288 </v-col >
9389 </v-row >
9490 <v-row v-else-if =" modelValue?.length === 0" >
10096 <v-row v-if =" showAddWorkExperienceEligibilityButton" >
10197 <v-col sm =" 12" md =" 10" lg =" 8" xl =" 6" >
10298 <v-btn
103- id =" btnAddInternationalCertification "
99+ id =" btnAddEmploymentExperience "
104100 prepend-icon =" mdi-plus"
105101 rounded =" lg"
106102 color =" primary"
134130
135131<script lang="ts">
136132import { mapWritableState } from " pinia" ;
137- import { defineComponent } from " vue" ;
133+ import { defineComponent , type PropType } from " vue" ;
138134import type { VForm , VInput } from " vuetify/components" ;
139135
140136import EceDateInput from " @/components/inputs/EceDateInput.vue" ;
@@ -153,28 +149,28 @@ import * as Rules from "@/utils/formRules";
153149import { removeElementByIndex , replaceElementByIndex } from " @/utils/functions" ;
154150
155151import ECEHeader from " ../ECEHeader.vue" ;
156- import EceIcraWorkExperienceEligibilityCard from " ../EceIcraWorkExperienceEligibilityCard .vue" ;
152+ import EceEmploymentExperienceCard from " ../EceEmploymentExperienceCard .vue" ;
157153import ProgressBar from " ../ProgressBar.vue" ;
158154import { useIcraStore } from " @/store/icra" ;
159155
160156const MAX_NUM_REFERENCES = 6 ;
161157
162- interface IcraWorkExperienceEligibilityData extends Components .Schemas .WorkExperienceReference {
158+ interface EmploymentExperienceData extends Components .Schemas .EmploymentReference {
163159 // other fields
164- icraWorkExperienceEligibilityFormMode : " add" | " edit" | undefined ; // TODO not supposed to be optional
160+ employmentExperienceFormMode : " add" | " edit" | undefined ;
165161}
166162
167163export default defineComponent ({
168- name: " EceIcraWorkExperienceEligibility " ,
169- components: { ProgressBar , EceIcraWorkExperienceEligibilityCard , EceDateInput , EceTextField , Callout , ECEHeader },
164+ name: " EceEmploymentExperience " ,
165+ components: { ProgressBar , EceEmploymentExperienceCard , EceDateInput , EceTextField , Callout , ECEHeader },
170166 props: {
171167 modelValue: {
172- type: Object as () => Components .Schemas .WorkExperienceReference [] ,
168+ type: Array as PropType < Components .Schemas .EmploymentReference []> ,
173169 required: true , // to switch to true
174170 },
175171 },
176172 emits: {
177- " update:model-value" : (_icraWorkExperienceEligibility : Components .Schemas .WorkExperienceReference []) => true ,
173+ " update:model-value" : (_icraWorkExperienceEligibility : Components .Schemas .EmploymentReference []) => true ,
178174 },
179175 setup : () => {
180176 const alertStore = useAlertStore ();
@@ -198,16 +194,16 @@ export default defineComponent({
198194 MAX_NUM_REFERENCES ,
199195 };
200196 },
201- data(): IcraWorkExperienceEligibilityData {
197+ data(): EmploymentExperienceData {
202198 return {
203- // international certification
204- id: " " ,
199+ // employment experience
200+ id: null ,
205201 lastName: " " ,
206202 firstName: " " ,
207203 emailAddress: " " ,
208204 phoneNumber: " " ,
209205 // other data
210- icraWorkExperienceEligibilityFormMode : undefined ,
206+ employmentExperienceFormMode : undefined ,
211207 };
212208 },
213209 computed: {
@@ -238,10 +234,10 @@ export default defineComponent({
238234 // Reset the form fields
239235 this .resetFormData ();
240236 this .mode = " add" ;
241- this .icraWorkExperienceEligibilityFormMode = " add" ;
237+ this .employmentExperienceFormMode = " add" ;
242238 window .scroll (0 , 0 );
243239 },
244- handleEdit(reference : Components .Schemas .WorkExperienceReference ) {
240+ handleEdit(reference : Components .Schemas .EmploymentReference ) {
245241 // Set the form fields to component data
246242 this .id = reference .id ;
247243 this .lastName = reference .lastName ;
@@ -250,9 +246,10 @@ export default defineComponent({
250246 this .phoneNumber = reference .phoneNumber ;
251247
252248 this .mode = " add" ;
253- this .icraWorkExperienceEligibilityFormMode = " edit" ;
249+ this .employmentExperienceFormMode = " edit" ;
250+ window .scroll (0 , 0 );
254251 },
255- async handleDelete(_reference : Components .Schemas .WorkExperienceReference , index : number ) {
252+ async handleDelete(_reference : Components .Schemas .EmploymentReference , index : number ) {
256253 this .$emit (" update:model-value" , removeElementByIndex (this .modelValue , index ));
257254
258255 // await this.icraStore.saveDraft();
@@ -263,7 +260,7 @@ export default defineComponent({
263260 const { valid } = await (this .$refs .icraWorkExperienceEligibilityForm as VForm ).validate ();
264261
265262 if (valid ) {
266- const newIcraWorkExperienceEligibilityReference : Components .Schemas .WorkExperienceReference = {
263+ const newEmploymentExperienceReference : Components .Schemas .EmploymentReference = {
267264 id: this .id , // empty if we are adding
268265 lastName: this .lastName ,
269266 firstName: this .firstName ,
@@ -272,21 +269,19 @@ export default defineComponent({
272269 };
273270 let updatedModelValue = this .modelValue ?.slice () || []; // create a copy of the array
274271
275- if (this .icraWorkExperienceEligibilityFormMode === " edit" ) {
276- const indexOfEditedReference = updatedModelValue .findIndex ((reference ) => reference .id === newIcraWorkExperienceEligibilityReference .id );
277- updatedModelValue = replaceElementByIndex (updatedModelValue , indexOfEditedReference , newIcraWorkExperienceEligibilityReference );
278- } else if (this .icraWorkExperienceEligibilityFormMode === " add" ) {
279- updatedModelValue .push (newIcraWorkExperienceEligibilityReference );
272+ if (this .employmentExperienceFormMode === " edit" ) {
273+ const indexOfEditedReference = updatedModelValue .findIndex ((reference ) => reference .id === newEmploymentExperienceReference .id );
274+ updatedModelValue = replaceElementByIndex (updatedModelValue , indexOfEditedReference , newEmploymentExperienceReference );
275+ } else if (this .employmentExperienceFormMode === " add" ) {
276+ updatedModelValue .push (newEmploymentExperienceReference );
280277 }
281278
282279 this .$emit (" update:model-value" , updatedModelValue );
283280
284- // await this.icraStore.saveDraft(); //TODO add in when save draft is ready
281+ await this .icraStore .saveDraft ();
285282
286283 this .alertStore .setSuccessAlert (
287- this .icraWorkExperienceEligibilityFormMode === " edit"
288- ? " You have successfully edited your reference."
289- : " You have successfully added your reference." ,
284+ this .employmentExperienceFormMode === " edit" ? " You have successfully edited your reference." : " You have successfully added your reference." ,
290285 );
291286
292287 this .resetFormData ();
@@ -299,13 +294,13 @@ export default defineComponent({
299294 }
300295 },
301296 resetFormData() {
302- this .id = " " ;
303- this .lastName = " so " ; // TODO remove test data
304- this .firstName = " derek " ;
305- this .emailAddress = " [email protected] " ; 297+ this .id = null ;
298+ this .lastName = " " ;
299+ this .firstName = " " ;
300+ this .emailAddress = " " ;
306301 this .phoneNumber = " " ;
307302
308- this .icraWorkExperienceEligibilityFormMode = undefined ;
303+ this .employmentExperienceFormMode = undefined ;
309304 },
310305 },
311306});
0 commit comments