-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from bcgov/stories/ECER-713
ECER-713: Contact Information step of application wizard
- Loading branch information
Showing
6 changed files
with
170 additions
and
37 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<template> | ||
<Wizard | ||
:wizard="applicationWizard" | ||
:wizard-data="wizardStore.wizardData" | ||
@save-and-continue="handleSaveAndContinue" | ||
@save-as-draft="handleSaveAsDraft" | ||
@back="handleBack" | ||
@updated-validation="isFormValid = $event" | ||
/> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from "vue"; | ||
import { getProfile, putProfile } from "@/api/profile"; | ||
import Wizard from "@/components/Wizard.vue"; | ||
import applicationWizard from "@/config/application-wizard"; | ||
import { useAlertStore } from "@/store/alert"; | ||
import { useUserStore } from "@/store/user"; | ||
import { userWizardStore } from "@/store/wizard"; | ||
import { AddressType } from "../inputs/EceAddresses.vue"; | ||
export default defineComponent({ | ||
name: "Application", | ||
components: { Wizard }, | ||
setup: async () => { | ||
const wizardStore = userWizardStore(); | ||
const userStore = useUserStore(); | ||
const alertStore = useAlertStore(); | ||
const userProfile = await getProfile(); | ||
if (userProfile !== null) { | ||
wizardStore.initializeWizard(applicationWizard, { | ||
[applicationWizard.steps.profile.form.inputs.legalFirstName.id]: userProfile.firstName, | ||
[applicationWizard.steps.profile.form.inputs.legalLastName.id]: userProfile.lastName, | ||
[applicationWizard.steps.profile.form.inputs.dateOfBirth.id]: userProfile.dateOfBirth, | ||
[applicationWizard.steps.profile.form.inputs.addresses.id]: { | ||
[AddressType.RESIDENTIAL]: userProfile.residentialAddress || userStore.oidcAddress, | ||
[AddressType.MAILING]: userProfile.mailingAddress || userStore.oidcAddress, | ||
}, | ||
[applicationWizard.steps.profile.form.inputs.email.id]: userProfile.email, | ||
[applicationWizard.steps.profile.form.inputs.legalMiddleName.id]: userProfile.middleName, | ||
[applicationWizard.steps.profile.form.inputs.preferredName.id]: userProfile.preferredName, | ||
[applicationWizard.steps.profile.form.inputs.alternateContactNumber.id]: userProfile.alternateContactPhone, | ||
[applicationWizard.steps.profile.form.inputs.primaryContactNumber.id]: userProfile.phone, | ||
}); | ||
} else { | ||
wizardStore.initializeWizard(applicationWizard, { | ||
[applicationWizard.steps.profile.form.inputs.legalFirstName.id]: userStore.oidcUserInfo.firstName, | ||
[applicationWizard.steps.profile.form.inputs.legalLastName.id]: userStore.oidcUserInfo.lastName, | ||
[applicationWizard.steps.profile.form.inputs.dateOfBirth.id]: userStore.oidcUserInfo.dateOfBirth, | ||
[applicationWizard.steps.profile.form.inputs.addresses.id]: { | ||
[AddressType.RESIDENTIAL]: userStore.oidcAddress, | ||
[AddressType.MAILING]: userStore.oidcAddress, | ||
}, | ||
[applicationWizard.steps.profile.form.inputs.email.id]: userStore.oidcUserInfo.email, | ||
[applicationWizard.steps.profile.form.inputs.primaryContactNumber.id]: userStore.oidcUserInfo.phone, | ||
}); | ||
} | ||
return { applicationWizard, wizardStore, alertStore, userStore }; | ||
}, | ||
data: () => ({ | ||
isFormValid: null as boolean | null, | ||
}), | ||
methods: { | ||
handleSaveAndContinue() { | ||
this.saveProfile(); | ||
}, | ||
handleBack() { | ||
this.wizardStore.decrementStep(); | ||
}, | ||
handleSaveAsDraft() { | ||
this.alertStore.setSuccessAlert("Save as Draft"); | ||
}, | ||
async saveProfile() { | ||
if (!this.isFormValid) { | ||
this.alertStore.setFailureAlert("Please fill out all required fields"); | ||
} else { | ||
const success = await putProfile({ | ||
firstName: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.legalFirstName.id], | ||
middleName: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.legalMiddleName.id], | ||
preferredName: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.preferredName.id], | ||
lastName: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.legalLastName.id], | ||
dateOfBirth: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.dateOfBirth.id], | ||
residentialAddress: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.addresses.id][AddressType.RESIDENTIAL], | ||
mailingAddress: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.addresses.id][AddressType.MAILING], | ||
email: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.email.id], | ||
phone: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.primaryContactNumber.id], | ||
alternateContactPhone: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.alternateContactNumber.id], | ||
}); | ||
if (success) { | ||
this.alertStore.setSuccessAlert("Profile saved successfully"); | ||
this.userStore.setUserInfo({ | ||
firstName: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.legalFirstName.id], | ||
lastName: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.legalLastName.id], | ||
email: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.email.id], | ||
phone: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.primaryContactNumber.id], | ||
dateOfBirth: this.wizardStore.wizardData[applicationWizard.steps.profile.form.inputs.dateOfBirth.id], | ||
}); | ||
this.wizardStore.incrementStep(); | ||
} else { | ||
this.alertStore.setFailureAlert("Profile save failed"); | ||
} | ||
} | ||
}, | ||
}, | ||
}); | ||
</script> |
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
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
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
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 |
---|---|---|
|
@@ -9,5 +9,7 @@ interface Step { | |
|
||
interface Wizard { | ||
id: string; | ||
steps: Step[]; | ||
steps: { | ||
[id: string]: Step; | ||
}; | ||
} |