@@ -23,12 +23,12 @@ import RelatedEnquiriesSection from '@/components/form/section/RelatedEnquiriesS
2323import SubmissionStateSection from ' @/components/form/section/SubmissionStateSection.vue' ;
2424import { Button , Message , useConfirm , useToast } from ' @/lib/primevue' ;
2525import { atsService , housingProjectService , mapService , userService } from ' @/services' ;
26- import { useProjectStore } from ' @/store' ;
26+ import { useAppStore , useFormStore , useProjectStore } from ' @/store' ;
2727import { ATS_ENQUIRY_TYPE_CODE_PROJECT_INTAKE_SUFFIX , ATS_MANAGING_REGION } from ' @/utils/constants/projectCommon' ;
2828import { ATSCreateTypes , BasicResponse , GroupName , Initiative } from ' @/utils/enums/application' ;
29- import { ActivityContactRole , ApplicationStatus } from ' @/utils/enums/projectCommon' ;
29+ import { ActivityContactRole , ApplicationStatus , FormState , FormType } from ' @/utils/enums/projectCommon' ;
3030import { formatDate } from ' @/utils/formatters' ;
31- import { omit , scrollToFirstError , setEmptyStringsToNull , toTitleCase } from ' @/utils/utils' ;
31+ import { scrollToFirstError , setEmptyStringsToNull , toTitleCase } from ' @/utils/utils' ;
3232
3333import type { Ref } from ' vue' ;
3434import type {
@@ -37,7 +37,8 @@ import type {
3737 ATSEnquiryResource ,
3838 Contact ,
3939 DeepPartial ,
40- HousingProject
40+ HousingProject ,
41+ User
4142} from ' @/types' ;
4243import type { FormSchemaType } from ' @/validators/housing/projectFormNavigatorSchema' ;
4344
@@ -56,6 +57,7 @@ const confirm = useConfirm();
5657const toast = useToast ();
5758
5859// Store
60+ const { getInitiative } = storeToRefs (useAppStore ());
5961const projectStore = useProjectStore ();
6062const { getActivityContacts } = storeToRefs (projectStore );
6163
@@ -156,12 +158,11 @@ async function handleAtsCreate(values: GenericObject) {
156158}
157159
158160async function initializeFormValues(project : HousingProject ): Promise <DeepPartial <FormSchemaType >> {
159- let assigneeOptions = [];
161+ let assigneeOptions: User [] = [];
160162 if (project .assignedUserId )
161163 assigneeOptions = (await userService .searchUsers ({ userId: [project .assignedUserId ] })).data ;
162164
163165 return {
164- consentToFeedback: project .consentToFeedback ? BasicResponse .YES : BasicResponse .NO ,
165166 contact: {
166167 contactId: primaryContact .value ?.contactId ,
167168 firstName: primaryContact .value ?.firstName ,
@@ -194,27 +195,27 @@ async function initializeFormValues(project: HousingProject): Promise<DeepPartia
194195 geomarkUrl: project .geomarkUrl ,
195196 naturalDisaster: project .naturalDisaster ? BasicResponse .YES : BasicResponse .NO
196197 },
197- locationPidsAuto: locationPidsAuto .value ,
198- project : {
198+ locationPids: { auto: locationPidsAuto .value } ,
199+ companyProjectName : {
199200 companyIdRegistered: project .companyIdRegistered ,
200201 companyNameRegistered: project .companyNameRegistered ,
201202 projectName: project .projectName
202203 },
203204
204205 // Additional Info
205- projectDescription: project .projectDescription ,
206+ projectDescription: { description: project .projectDescription } ,
206207
207208 // Location
208- projectLocationDescription: project .projectLocationDescription ,
209+ locationDescription: { description: project .projectLocationDescription } ,
209210
210211 // Automated Status Tool Notes
211- astNotes: project .astNotes ,
212+ astNotes: { notes: project .astNotes } ,
212213
213214 // Submission state
214215 submissionState: {
215216 queuePriority: project .queuePriority ,
216217 submissionType: project .submissionType ,
217- assignedUser: assigneeOptions [0 ] ?? null ,
218+ assignedUser: assigneeOptions [0 ]?. fullName ?? null ,
218219 applicationStatus: project .applicationStatus
219220 },
220221
@@ -228,16 +229,25 @@ async function initializeFormValues(project: HousingProject): Promise<DeepPartia
228229 },
229230
230231 // ATS link
231- atsClientId: project .atsClientId ,
232- atsEnquiryId: project .atsEnquiryId ,
232+ atsInfo: {
233+ atsClientId: project .atsClientId ,
234+ atsEnquiryId: project .atsEnquiryId
235+ },
236+
237+ // Related enquiries
238+ relatedEnquiries: { csv: project .relatedEnquiries },
233239
234240 // Updates
235- aaiUpdated: project .aaiUpdated ,
236- addedToAts: project .addedToAts ,
237- ltsaCompleted: project .ltsaCompleted ,
238- bcOnlineCompleted: project .bcOnlineCompleted ,
239- submittedAt: new Date (project .submittedAt ),
240- relatedEnquiries: project .relatedEnquiries
241+ projectAreasUpdated: {
242+ aaiUpdated: project .aaiUpdated ,
243+ addedToAts: project .addedToAts ,
244+ ltsaCompleted: project .ltsaCompleted ,
245+ bcOnlineCompleted: project .bcOnlineCompleted
246+ },
247+
248+ consent: {
249+ consentToFeedback: project .consentToFeedback ? BasicResponse .YES : BasicResponse .NO
250+ }
241251 };
242252}
243253
@@ -280,50 +290,88 @@ function onReOpen() {
280290 });
281291}
282292
283- const onSubmit = async (values : GenericObject ) => {
293+ const onSubmit = async (formValues : GenericObject ) => {
284294 try {
295+ // vee-validate doesn't get transformed data from yup so
296+ // manually run the form values through it here
297+ const values: FormSchemaType = projectFormNavigatorSchema .cast (formValues );
298+
285299 await handleAtsCreate (values );
286300
287- // Generate final submission object
288- const dataOmitted = omit (
289- setEmptyStringsToNull ({
290- ... values .project ,
291- ... values .units ,
292- ... values .location ,
293- ... values .finance ,
294- ... values .submissionState ,
295- activityId: project .activityId ,
296- housingProjectId: project .housingProjectId ,
297- projectDescription: values .projectDescription ,
298- projectLocationDescription: values .projectLocationDescription ,
299- astNotes: values .astNotes ,
300- atsClientId: Number .parseInt (values .atsClientId ) || ' ' ,
301- atsEnquiryId: Number .parseInt (values .atsEnquiryId ) || ' ' ,
302- aaiUpdated: values .aaiUpdated ,
303- addedToAts: values .addedToAts ,
304- ltsaCompleted: values .ltsaCompleted ,
305- bcOnlineCompleted: values .bcOnlineCompleted ,
306- companyIdRegistered: values .project ?.companyIdRegistered ?? null ,
307- submittedAt: values .submittedAt ,
308- consentToFeedback: values .consentToFeedback === BasicResponse .YES ,
309- naturalDisaster: values .location .naturalDisaster === BasicResponse .YES ,
310- assignedUserId: values .submissionState .assignedUser ?.userId ?? undefined
311- }),
312- [' contact' , ' assignedUser' , ' isDevelopedInBc' , ' submissionState' , ' locationAddress' , ' relatedEnquiries' ]
313- );
301+ // Generate final payload
302+ // TODO: Create a type using Pick instead of Partial?
303+ const payload: Partial <HousingProject > = {
304+ // Company and Project Information
305+ projectName: values .companyProjectName .projectName ,
306+ companyNameRegistered: values .companyProjectName .companyNameRegistered ,
307+ companyIdRegistered: values .companyProjectName .companyIdRegistered ,
308+
309+ // Residential units
310+ singleFamilyUnits: values .units .singleFamilyUnits ,
311+ multiFamilyUnits: values .units .multiFamilyUnits ,
312+ hasRentalUnits: values .units .hasRentalUnits ,
313+ rentalUnits: values .units .rentalUnits ,
314+ otherUnits: values .units .otherUnits ,
315+ otherUnitsDescription: values .units .otherUnitsDescription ,
316+
317+ // Financially supported
318+ financiallySupportedBc: values .finance .financiallySupportedBc ,
319+ financiallySupportedIndigenous: values .finance .financiallySupportedIndigenous ,
320+ indigenousDescription: values .finance .indigenousDescription ,
321+ financiallySupportedNonProfit: values .finance .financiallySupportedNonProfit ,
322+ nonProfitDescription: values .finance .nonProfitDescription ,
323+ financiallySupportedHousingCoop: values .finance .financiallySupportedHousingCoop ,
324+ housingCoopDescription: values .finance .housingCoopDescription ,
325+
326+ // Location
327+ locality: values .location .locality ,
328+ province: values .location .province ,
329+ locationPids: values .location .locationPids ,
330+ latitude: values .location .latitude ,
331+ longitude: values .location .longitude ,
332+ streetAddress: values .location .streetAddress ,
333+ geomarkUrl: values .location .geomarkUrl ,
334+ naturalDisaster: values .location .naturalDisaster === BasicResponse .YES ,
335+
336+ // Additional Location Information
337+ projectLocationDescription: values .locationDescription .description ,
338+
339+ // Additional Project Information
340+ projectDescription: values .projectDescription .description ,
341+
342+ // AST Notes
343+ astNotes: values .astNotes .notes ,
344+
345+ // Submission State
346+ assignedUserId: values .submissionState .assignedUser ? (values .submissionState .assignedUser as User ).userId : null ,
347+ applicationStatus: values .submissionState .applicationStatus ,
348+ submissionType: values .submissionState .submissionType ,
349+ queuePriority: values .submissionState .queuePriority ,
350+
351+ // ATS
352+ atsClientId: values .atsInfo .atsClientId ,
353+ atsEnquiryId: values .atsInfo .atsEnquiryId ,
354+
355+ // Updates
356+ addedToAts: values .projectAreasUpdated .addedToAts ,
357+ ltsaCompleted: values .projectAreasUpdated .ltsaCompleted ,
358+ bcOnlineCompleted: values .projectAreasUpdated .bcOnlineCompleted ,
359+ aaiUpdated: values .projectAreasUpdated .aaiUpdated ,
360+
361+ // Consent
362+ consentToFeedback: values .consent .consentToFeedback === BasicResponse .YES
363+ };
314364
315365 // Update project
316- const result = await housingProjectService .updateProject (project .housingProjectId , dataOmitted );
366+ const result = await housingProjectService .updateProject (project .housingProjectId , payload );
317367 projectStore .setProject (result .data );
318368
319369 // Wait a tick for store to propagate
320370 await nextTick ();
321371
322372 // Reinitialize the form
323373 formRef .value ?.resetForm ({
324- values: {
325- ... initializeFormValues (result .data )
326- }
374+ values: await initializeFormValues (result .data )
327375 });
328376
329377 toast .success (t (' i.common.form.savedMessage' ));
@@ -332,7 +380,7 @@ const onSubmit = async (values: GenericObject) => {
332380 }
333381};
334382
335- const projectFormNavigatorSchema = createProjectFormNavigatorSchema ();
383+ const projectFormNavigatorSchema = createProjectFormNavigatorSchema ({ initiative: getInitiative . value , t } );
336384
337385// Set basic info, clear it if no contact is provided
338386function setBasicInfo(contact ? : Contact ) {
@@ -360,6 +408,9 @@ watch(primaryContact, (newContact, oldContact) => {
360408});
361409
362410onBeforeMount (async () => {
411+ useFormStore ().setFormType (FormType .NAVIGATOR );
412+ useFormStore ().setFormState (FormState .UNLOCKED );
413+
363414 locationPidsAuto .value = (await mapService .getPIDs (project .housingProjectId )).data ;
364415
365416 // Default form values
0 commit comments