Skip to content

Commit

Permalink
Removed unused imports. Fix nav form save issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle1morel committed Dec 19, 2024
1 parent bba92aa commit 1ea9102
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 20 deletions.
58 changes: 50 additions & 8 deletions frontend/src/components/housing/enquiry/EnquiryForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const intakeSchema = object({
enquiryType: string().oneOf(ENQUIRY_TYPE_LIST).label('Submission type'),
submittedAt: date().required().label('Submission date'),
relatedActivityId: string().nullable().min(0).max(255).label('Related submission'),
contacts: array().of(object(contactValidator)),
...contactValidator,
enquiryDescription: string().required().label('Enquiry detail'),
intakeStatus: string().oneOf(INTAKE_STATUS_LIST).label('Intake state'),
user: mixed()
Expand Down Expand Up @@ -160,7 +160,35 @@ function onReOpen() {
const onSubmit = async (values: any) => {
try {
const submitData: Enquiry = omit(setEmptyStringsToNull(values) as EnquiryForm, ['user']);
// Convert contact fields into contacts array object then remove form keys from data
const valuesWithContact = omit(
{
...values,
contacts: [
{
contactId: values.contactId,
firstName: values.contactFirstName,
lastName: values.contactLastName,
phoneNumber: values.contactPhoneNumber,
email: values.contactEmail,
contactApplicantRelationship: values.contactApplicantRelationship,
contactPreference: values.contactPreference
}
]
},
[
'contactId',
'contactFirstName',
'contactLastName',
'contactPhoneNumber',
'contactEmail',
'contactApplicantRelationship',
'contactPreference'
]
);
// Generate final enquiry object
const submitData: Enquiry = omit(setEmptyStringsToNull(valuesWithContact) as EnquiryForm, ['user']);
submitData.assignedUserId = values.user?.userId ?? undefined;
submitData.isRelated = submitData.relatedActivityId ? BasicResponse.YES : BasicResponse.NO;
Expand All @@ -169,6 +197,13 @@ const onSubmit = async (values: any) => {
formRef.value?.resetForm({
values: {
...submitData,
contactId: submitData?.contacts[0].contactId,
contactFirstName: submitData?.contacts[0].firstName,
contactLastName: submitData?.contacts[0].lastName,
contactPhoneNumber: submitData?.contacts[0].phoneNumber,
contactEmail: submitData?.contacts[0].email,
contactApplicantRelationship: submitData?.contacts[0].contactApplicantRelationship,
contactPreference: submitData?.contacts[0].contactPreference,
submittedAt: new Date(submitData.submittedAt),
user: values.user
}
Expand All @@ -187,6 +222,13 @@ onMounted(async () => {
}
initialFormValues.value = {
...enquiry,
contactId: enquiry?.contacts[0].contactId,
contactFirstName: enquiry?.contacts[0].firstName,
contactLastName: enquiry?.contacts[0].lastName,
contactPhoneNumber: enquiry?.contacts[0].phoneNumber,
contactEmail: enquiry?.contacts[0].email,
contactApplicantRelationship: enquiry?.contacts[0].contactApplicantRelationship,
contactPreference: enquiry?.contacts[0].contactPreference,
submittedAt: new Date(enquiry?.submittedAt),
user: assigneeOptions.value[0] ?? null
};
Expand Down Expand Up @@ -243,40 +285,40 @@ onMounted(async () => {

<InputText
class="col-3"
:name="`contacts[0].firstName`"
name="contactFirstName"
label="First name"
:disabled="!editable"
/>
<InputText
class="col-3"
:name="`contacts[0].lastName`"
name="contactLastName"
label="Last name"
:disabled="!editable"
/>
<Dropdown
class="col-3"
:name="`contacts[0].contactApplicantRelationship`"
name="contactApplicantRelationship"
label="Relationship to activity"
:disabled="!editable"
:options="PROJECT_RELATIONSHIP_LIST"
/>
<Dropdown
class="col-3"
:name="`contacts[0].contactPreference`"
name="contactPreference"
label="Preferred contact method"
:disabled="!editable"
:options="CONTACT_PREFERENCE_LIST"
/>
<InputMask
class="col-3"
:name="`contacts[0].phoneNumber`"
name="contactPhoneNumber"
mask="(999) 999-9999"
label="Phone number"
:disabled="!editable"
/>
<InputText
class="col-3"
:name="`contacts[0].email`"
name="contactEmail"
label="Contact email"
:disabled="!editable"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { storeToRefs } from 'pinia';
import { Form } from 'vee-validate';
import { computed, onBeforeMount, ref } from 'vue';
import { useRouter } from 'vue-router';
import { array, object, string } from 'yup';
import { object, string } from 'yup';
import BackButton from '@/components/common/BackButton.vue';
import {
Expand Down
62 changes: 53 additions & 9 deletions frontend/src/components/housing/submission/SubmissionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const formSchema = object({
submissionType: string().required().oneOf(SUBMISSION_TYPE_LIST).label('Submission type'),
submittedAt: string().required().label('Submission date'),
relatedEnquiries: string().notRequired().label('Related enquiries'),
contacts: array().of(object(contactValidator)),
...contactValidator,
companyNameRegistered: string().notRequired().max(255).label('Company'),
consentToFeedback: string().notRequired().nullable().label('Consent to feedback'),
isDevelopedInBC: string().when('companyNameRegistered', {
Expand Down Expand Up @@ -211,14 +211,52 @@ function onReOpen() {
const onSubmit = async (values: any) => {
try {
const submitData: Submission = omit(setEmptyStringsToNull(values) as SubmissionForm, ['locationAddress', 'user']);
// Convert contact fields into contacts array object then remove form keys from data
const valuesWithContact = omit(
{
...values,
contacts: [
{
contactId: values.contactId,
firstName: values.contactFirstName,
lastName: values.contactLastName,
phoneNumber: values.contactPhoneNumber,
email: values.contactEmail,
contactApplicantRelationship: values.contactApplicantRelationship,
contactPreference: values.contactPreference
}
]
},
[
'contactId',
'contactFirstName',
'contactLastName',
'contactPhoneNumber',
'contactEmail',
'contactApplicantRelationship',
'contactPreference'
]
);
// Generate final submission object
const submitData: Submission = omit(setEmptyStringsToNull(valuesWithContact) as SubmissionForm, [
'locationAddress',
'user'
]);
submitData.assignedUserId = values.user?.userId ?? undefined;
submitData.consentToFeedback = values.consentToFeedback === BasicResponse.YES;
const result = await submissionService.updateSubmission(values.submissionId, submitData);
submissionStore.setSubmission(result.data);
formRef.value?.resetForm({
values: {
...submitData,
contactId: submitData?.contacts[0].contactId,
contactFirstName: submitData?.contacts[0].firstName,
contactLastName: submitData?.contacts[0].lastName,
contactPhoneNumber: submitData?.contacts[0].phoneNumber,
contactEmail: submitData?.contacts[0].email,
contactApplicantRelationship: submitData?.contacts[0].contactApplicantRelationship,
contactPreference: submitData?.contacts[0].contactPreference,
locationAddress: values.locationAddress,
user: values.user,
consentToFeedback: values.consentToFeedback
Expand Down Expand Up @@ -289,7 +327,13 @@ onMounted(async () => {
aaiUpdated: submission.aaiUpdated,
astNotes: submission.astNotes,
intakeStatus: submission.intakeStatus,
contacts: submission.contacts,
contactId: submission?.contacts[0].contactId,
contactFirstName: submission?.contacts[0].firstName,
contactLastName: submission?.contacts[0].lastName,
contactPhoneNumber: submission?.contacts[0].phoneNumber,
contactEmail: submission?.contacts[0].email,
contactApplicantRelationship: submission?.contacts[0].contactApplicantRelationship,
contactPreference: submission?.contacts[0].contactPreference,
user: assigneeOptions.value[0] ?? null,
applicationStatus: submission.applicationStatus,
waitingOn: submission.waitingOn
Expand Down Expand Up @@ -350,13 +394,13 @@ onMounted(async () => {

<InputText
class="col-3"
:name="`contacts[0].firstName`"
name="contactFirstName"
label="First name"
:disabled="!editable"
/>
<InputText
class="col-3"
:name="`contacts[0].lastName`"
name="contactLastName"
label="Last name"
:disabled="!editable"
/>
Expand All @@ -383,28 +427,28 @@ onMounted(async () => {
/>
<Dropdown
class="col-3"
:name="`contacts[0].contactApplicantRelationship`"
name="contactApplicantRelationship"
label="Relationship to project"
:disabled="!editable"
:options="PROJECT_RELATIONSHIP_LIST"
/>
<Dropdown
class="col-3"
:name="`contacts[0].contactPreference`"
name="contactPreference"
label="Preferred contact method"
:disabled="!editable"
:options="CONTACT_PREFERENCE_LIST"
/>
<InputMask
class="col-3"
:name="`contacts[0].phoneNumber`"
name="contactPhoneNumber"
mask="(999) 999-9999"
label="Contact phone"
:disabled="!editable"
/>
<InputText
class="col-3"
:name="`contacts[0].email`"
name="contactEmail"
label="Contact email"
:disabled="!editable"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { BasicResponse, StorageKey } from '@/utils/enums/application';
import { ContactPreference, IntakeFormCategory, ProjectRelationship } from '@/utils/enums/housing';

import type { AxiosResponse } from 'axios';
import type { Contact } from '@/types';

vi.mock('vue-i18n', () => ({
useI18n: () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { submissionIntakeSchema } from '@/components/housing/submission/Submissi
import { permitService } from '@/services';
import { NUM_RESIDENTIAL_UNITS_LIST } from '@/utils/constants/housing';
import { BasicResponse, StorageKey } from '@/utils/enums/application';
import { ContactPreference, ProjectRelationship } from '@/utils/enums/housing';

import type { AxiosResponse } from 'axios';

Expand Down

0 comments on commit 1ea9102

Please sign in to comment.