Skip to content

Commit

Permalink
Merge pull request #382 from bcgov/stories/ECER-1575
Browse files Browse the repository at this point in the history
ECER-1575: Add previous name page
  • Loading branch information
pcatkins authored Jul 17, 2024
2 parents 64525ed + 77b13c9 commit 3f76b15
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import axios from "axios";

import { getClient } from "@/api/client";
import type { Components } from "@/types/openapi";
import ApiResultHandler, { type ApiResponse } from "@/utils/apiResultHandler";

const apiResultHandler = new ApiResultHandler();

const getProfile = async (): Promise<Components.Schemas.UserProfile | null> => {
try {
Expand All @@ -21,15 +24,9 @@ const getProfile = async (): Promise<Components.Schemas.UserProfile | null> => {
}
};

const putProfile = async (user: Components.Schemas.UserProfile): Promise<boolean> => {
try {
const client = await getClient();
const response = await client.profile_put({}, user);
return response.status === 200;
} catch (error) {
console.log("Error creating profile:", error);
return false;
}
const putProfile = async (user: Components.Schemas.UserProfile): Promise<ApiResponse<any>> => {
const client = await getClient();
return apiResultHandler.execute({ request: client.profile_put({}, user), key: "profile_put" });
};

export { getProfile, putProfile };
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default defineComponent({
if (!valid) {
this.alertStore.setFailureAlert("You must enter all required fields in the valid format.");
} else {
const success = await putProfile({
const { error } = await putProfile({
firstName: this.formStore.formData[profileInformationForm.inputs.legalFirstName.id],
middleName: this.formStore.formData[profileInformationForm.inputs.legalMiddleName.id],
preferredName: this.formStore.formData[profileInformationForm.inputs.preferredName.id],
Expand All @@ -80,7 +80,7 @@ export default defineComponent({
alternateContactPhone: this.formStore.formData[profileInformationForm.inputs.alternateContactNumber.id],
});
if (success) {
if (!error) {
this.alertStore.setSuccessAlert("You have successfully edited your profile information.");
this.userStore.setUserInfo({
firstName: this.formStore.formData[profileInformationForm.inputs.legalFirstName.id],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,153 @@
<template><div>ADD PREVIOUS NAME</div></template>
<template>
<PageContainer>
<Breadcrumb :items="items" />
<v-row>
<v-col>
<Alert v-model="duplicatePreviousName" type="error" prominent>
<p>This previous name is already in your account. You cannot add the same name again.</p>
</Alert>
</v-col>
</v-row>
<v-row>
<v-col class="ml-1" cols="12">
<h1>Add previous name</h1>
</v-col>
</v-row>
<div class="d-flex flex-column ga-3 my-6">
<p>
This is only needed when you’re applying for certification and a transcript or other document has a different name then your current legal name. For
example, if your transcript has a different name than the name in your account.
</p>
<p>There are 3 steps:</p>
<ol class="ml-10">
<li>Enter your previous name below</li>
<li>Provide government-issued ID</li>
<li>We’ll review your ID and add this name to your account</li>
</ol>
<p>Before you continue, make sure you have one of the accepted goverment-issued IDs:</p>
<ul class="ml-10">
<li>Government-issued marriage certificate</li>
<li>Divorce certificate or papers</li>
<li>Government-issued change of name document</li>
</ul>
</div>
<v-row class="mt-10">
<v-col>
<EceForm ref="addPreviousNameForm" :form="previousNameForm" :form-data="formStore.formData" @updated-form-data="formStore.setFormData" />
</v-col>
</v-row>
<v-row class="mt-6">
<v-col class="d-flex flex-row ga-3 flex-wrap">
<v-btn size="large" color="primary" :loading="loadingStore.isLoading('profile_put')" @click="handleSubmitPreviousName">Save and continue</v-btn>
<v-btn size="large" variant="outlined" color="primary" @click="router.back()">Cancel</v-btn>
</v-col>
</v-row>
</PageContainer>
</template>

<script lang="ts">
import { useRouter } from "vue-router";
import { getProfile, putProfile } from "@/api/profile";
import Alert from "@/components/Alert.vue";
import Breadcrumb from "@/components/Breadcrumb.vue";
import EceForm from "@/components/Form.vue";
import PageContainer from "@/components/PageContainer.vue";
import previousNameForm from "@/config/previous-name-form";
import { useAlertStore } from "@/store/alert";
import { useFormStore } from "@/store/form";
import { useLoadingStore } from "@/store/loading";
import { useUserStore } from "@/store/user";
import type { Components } from "@/types/openapi";
export default {
name: "AddPreviousName",
components: { PageContainer, EceForm, Alert, Breadcrumb },
setup() {
const formStore = useFormStore();
const loadingStore = useLoadingStore();
const userStore = useUserStore();
const alertStore = useAlertStore();
const router = useRouter();
formStore.initializeForm({});
return { formStore, loadingStore, alertStore, userStore, previousNameForm, router };
},
data: () => ({
items: [
{
title: "Home",
disabled: false,
href: "/",
},
{
title: "Profile",
disabled: false,
href: "/profile",
},
{
title: "Add previous name",
disabled: true,
href: "/profile/add-previous-name",
},
],
}),
computed: {
newPreviousName(): Components.Schemas.PreviousName {
return {
firstName: this.formStore.formData[previousNameForm.inputs.firstName.id],
middleName: this.formStore.formData[previousNameForm.inputs.middleName.id] ?? null,
lastName: this.formStore.formData[previousNameForm.inputs.lastName.id],
};
},
duplicatePreviousName() {
// Check if any existing previous name matches the new previous name
return this.userStore.userProfile?.previousNames?.some(
(previousName) =>
previousName.firstName === this.newPreviousName.firstName &&
previousName.middleName === this.newPreviousName.middleName &&
previousName.lastName === this.newPreviousName.lastName,
);
},
},
methods: {
async handleSubmitPreviousName() {
// Validate the form
const { valid } = await (this.$refs.addPreviousNameForm as typeof EceForm).$refs[previousNameForm.id].validate();
if (valid) {
//check for duplicate previous name
if (!this.duplicatePreviousName) {
const { error } = await putProfile({
...this.userStore.userProfile,
previousNames: [this.newPreviousName],
});
if (error) {
this.alertStore.setFailureAlert("Sorry, something went wrong and your changes could not be saved. Try again later.");
} else {
// Refetch user profile to get the new previous name Id
const userProfile = await getProfile();
if (userProfile !== null) {
this.userStore.setUserProfile(userProfile);
const latestPreviousName = userProfile.previousNames?.find(
(previousName) =>
previousName.firstName === this.newPreviousName.firstName &&
previousName.middleName === this.newPreviousName.middleName &&
previousName.lastName === this.newPreviousName.lastName,
);
if (latestPreviousName) {
this.router.push({ name: "verify-previous-name", params: { previousNameId: latestPreviousName.id } });
}
}
}
} else {
window.scrollTo(0, 0);
}
} else {
this.alertStore.setFailureAlert("You must enter all required fields in the valid format to continue.");
}
},
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default defineComponent({
}
},
async saveProfile() {
const success = await putProfile({
const { error } = await putProfile({
firstName: this.wizardStore.wizardData[this.wizardStore.wizardConfig.steps.profile.form.inputs.legalFirstName.id],
middleName: this.wizardStore.wizardData[this.wizardStore.wizardConfig.steps.profile.form.inputs.legalMiddleName.id],
preferredName: this.wizardStore.wizardData[this.wizardStore.wizardConfig.steps.profile.form.inputs.preferredName.id],
Expand All @@ -190,7 +190,7 @@ export default defineComponent({
alternateContactPhone: this.wizardStore.wizardData[this.wizardStore.wizardConfig.steps.profile.form.inputs.alternateContactNumber.id],
});
if (success) {
if (!error) {
this.alertStore.setSuccessAlert("Your responses have been saved. You may resume this application from your dashboard.");
this.userStore.setUserInfo({
firstName: this.wizardStore.wizardData[this.wizardStore.wizardConfig.steps.profile.form.inputs.legalFirstName.id],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import EceTextField from "@/components/inputs/EceTextField.vue";
import type { Form } from "@/types/form";
import * as Rules from "@/utils/formRules";

const previousNameForm: Form = {
id: "previousNameForm",
title: "Previous Name",
inputs: {
firstName: {
id: "firstName",
component: EceTextField,
props: {
label: "First name",
rules: [Rules.required("Enter your legal name"), Rules.noSpecialCharactersContactName()],
maxLength: 100,
},
cols: {
md: 8,
lg: 6,
xl: 4,
},
},
middleName: {
id: "middleName",
component: EceTextField,
props: {
label: "Middle names (optional)",
rules: [Rules.noSpecialCharactersContactName()],
maxLength: 100,
},
cols: {
md: 8,
lg: 6,
xl: 4,
},
},
lastName: {
id: "lastName",
component: EceTextField,
props: {
label: "Last name",
rules: [Rules.required("Enter your legal name"), Rules.noSpecialCharactersContactName()],
maxLength: 100,
},
cols: {
md: 8,
lg: 6,
xl: 4,
},
},
},
};

export default previousNameForm;
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export const useCertificationStore = defineStore("certification", {
},
actions: {
async fetchCertifications() {
// Drop any existing certifications
this.$reset();

const { data: certifications } = await getCertifications();
if (certifications?.length && certifications.length > 0) {
this.certifications = certifications;
Expand Down

0 comments on commit 3f76b15

Please sign in to comment.