Skip to content

Commit

Permalink
Autofill contact, fixed errors on creating a new submission as a navi…
Browse files Browse the repository at this point in the history
…gator
  • Loading branch information
sanjaytkbabu committed Jan 15, 2025
1 parent 8e15ec9 commit 8542eb9
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 63 deletions.
18 changes: 10 additions & 8 deletions app/src/services/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@ const service = {
return await prisma.$transaction(async (trx) => {
await Promise.all(
data.map(async (x: Contact) => {
let response;
if (!x.contactId) {
const response = await trx.contact.create({
response = await trx.contact.create({
data: contact.toPrismaModel({
...x,
contactId: uuidv4(),
...generateCreateStamps(currentContext)
})
});
if (activityId)
await trx.activity_contact.create({
data: {
activity_id: activityId,
contact_id: response.contact_id
}
});
} else {
await trx.contact.update({
data: contact.toPrismaModel({ ...x, ...generateCreateStamps(currentContext) }),
Expand All @@ -39,6 +33,14 @@ const service = {
}
});
}

if (activityId)
await trx.activity_contact.create({
data: {
activity_id: activityId,
contact_id: response?.contact_id ?? x.contactId
}
});
})
);
});
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/housing/enquiry/EnquiryForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +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,
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
53 changes: 35 additions & 18 deletions frontend/src/components/housing/enquiry/EnquiryIntakeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import CollectionDisclaimer from '@/components/housing/CollectionDisclaimer.vue';
import { Button, Card, Divider, useConfirm, useToast } from '@/lib/primevue';
import { enquiryService, submissionService } from '@/services';
import { useConfigStore } from '@/store';
import { useConfigStore, useContactStore } from '@/store';
import { YES_NO_LIST } from '@/utils/constants/application';
import { CONTACT_PREFERENCE_LIST, PROJECT_RELATIONSHIP_LIST } from '@/utils/constants/housing';
import { BasicResponse, RouteName } from '@/utils/enums/application';
Expand All @@ -38,13 +38,14 @@ const { enquiryId = undefined } = defineProps<{
}>();
// Store
const contactStore = useContactStore();
const { getConfig } = storeToRefs(useConfigStore());
// State
const editable: Ref<boolean> = ref(true);
const filteredProjectActivityIds: Ref<Array<string>> = ref([]);
const formRef: Ref<InstanceType<typeof Form> | null> = ref(null);
const initialFormValues: Ref<undefined | object> = ref(undefined);
const initialFormValues: Ref<any | undefined> = ref(undefined);
const projectActivityIds: Ref<Array<string>> = ref([]);
const submissions: Ref<Array<Submission>> = ref([]);
const validationErrors: Ref<string[]> = ref([]);
Expand Down Expand Up @@ -104,12 +105,12 @@ async function emailConfirmation(activityId: string, enquiryId: string) {
firstTwoSentences = sentences.length > 2 ? firstTwoSentences.concat('..') : firstTwoSentences;
const body = confirmationTemplateEnquiry({
'{{ contactName }}': formRef.value?.values.contacts[0].firstName,
'{{ contactName }}': formRef.value?.values.contactFirstName,
'{{ activityId }}': activityId,
'{{ enquiryDescription }}': firstTwoSentences.trim(),
'{{ enquiryId }}': enquiryId
});
let applicantEmail = formRef.value?.values.contacts[0].email;
let applicantEmail = formRef.value?.values.contactEmail;
let emailData = {
from: configCC,
to: [applicantEmail],
Expand All @@ -128,17 +129,21 @@ async function loadEnquiry() {
if (enquiryId) {
response = (await enquiryService.getEnquiry(enquiryId as string)).data;
editable.value = response?.intakeStatus !== IntakeStatus.SUBMITTED;
} else {
// Load contact data for new enquiry
response = { contacts: [contactStore.getContact] };
}
initialFormValues.value = {
activityId: response?.activityId,
enquiryId: response?.enquiryId,
contactFirstName: response?.contacts[0].firstName,
contactLastName: response?.contacts[0].lastName,
contactPhoneNumber: response?.contacts[0].phoneNumber,
contactEmail: response?.contacts[0].email,
contactApplicantRelationship: response?.contacts[0].contactApplicantRelationship,
contactPreference: response?.contacts[0].contactPreference,
contactFirstName: response?.contacts[0]?.firstName,
contactLastName: response?.contacts[0]?.lastName,
contactPhoneNumber: response?.contacts[0]?.phoneNumber,
contactEmail: response?.contacts[0]?.email,
contactApplicantRelationship: response?.contacts[0]?.contactApplicantRelationship,
contactPreference: response?.contacts[0]?.contactPreference,
contactId: response?.contacts[0]?.contactId,
basic: {
isRelated: response?.isRelated,
relatedActivityId: response?.relatedActivityId,
Expand Down Expand Up @@ -189,7 +194,8 @@ async function onSubmit(data: any) {
phoneNumber: data.contactPhoneNumber,
email: data.contactEmail,
contactApplicantRelationship: data.contactApplicantRelationship,
contactPreference: data.contactPreference
contactPreference: data.contactPreference,
contactId: data.contactId
}
]
},
Expand All @@ -199,7 +205,8 @@ async function onSubmit(data: any) {
'contactPhoneNumber',
'contactEmail',
'contactApplicantRelationship',
'contactPreference'
'contactPreference',
'contactId'
]
);
Expand All @@ -212,6 +219,9 @@ async function onSubmit(data: any) {
// Send confirmation email
emailConfirmation(enquiryResponse.data.activityId, enquiryResponse.data.enquiryId);
// Save contact data to store
contactStore.setContact(enquiryData.contacts[0]);
router.push({
name: RouteName.HOUSING_ENQUIRY_CONFIRMATION,
query: {
Expand Down Expand Up @@ -285,6 +295,13 @@ onBeforeMount(async () => {
<Card>
<template #title>
<span class="section-header">Who is the primary contact regarding this project?</span>
<span
v-tooltip.right="t('enquiryIntakeForm.contactTooltip')"
v-tooltip.focus.right="t('enquiryIntakeForm.contactTooltip')"
tabindex="0"
>
<font-awesome-icon icon="fa-solid fa-circle-info" />
</span>
<Divider type="solid" />
</template>
<template #content>
Expand All @@ -294,44 +311,44 @@ onBeforeMount(async () => {
name="contactFirstName"
label="First name"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contactFirstName ? true : !editable"
/>
<InputText
class="col-6"
name="contactLastName"
label="Last name"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contactLastName ? true : !editable"
/>
<InputMask
class="col-6"
name="contactPhoneNumber"
mask="(999) 999-9999"
label="Phone number"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contactPhoneNumber ? true : !editable"
/>
<InputText
class="col-6"
name="contactEmail"
label="Email"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contactEmail ? true : !editable"
/>
<Dropdown
class="col-6"
name="contactApplicantRelationship"
label="Relationship to project"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contactApplicantRelationship ? true : !editable"
:options="PROJECT_RELATIONSHIP_LIST"
/>
<Dropdown
class="col-6"
:name="`contactPreference`"
label="Preferred contact method"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contactPreference ? true : !editable"
:options="CONTACT_PREFERENCE_LIST"
/>
</div>
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/housing/submission/SubmissionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ onMounted(async () => {
aaiUpdated: submission.aaiUpdated,
astNotes: submission.astNotes,
intakeStatus: submission.intakeStatus,
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,
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
42 changes: 29 additions & 13 deletions frontend/src/components/housing/submission/SubmissionIntakeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
useToast
} from '@/lib/primevue';
import { documentService, enquiryService, externalApiService, permitService, submissionService } from '@/services';
import { useConfigStore, useSubmissionStore, useTypeStore } from '@/store';
import { useConfigStore, useContactStore, useSubmissionStore, useTypeStore } from '@/store';
import { YES_NO_LIST, YES_NO_UNSURE_LIST } from '@/utils/constants/application';
import {
CONTACT_PREFERENCE_LIST,
Expand Down Expand Up @@ -96,6 +96,7 @@ const VALIDATION_BANNER_TEXT =
'One or more of the required fields are missing or contains invalid data. Please check the highlighted pages and fields in red.';
// Store
const contactStore = useContactStore();
const submissionStore = useSubmissionStore();
const typeStore = useTypeStore();
const { getPermitTypes } = storeToRefs(typeStore);
Expand Down Expand Up @@ -338,6 +339,7 @@ async function onSubmit(data: any) {
...data,
contacts: [
{
contactId: data.contacts.contactId,
firstName: data.contacts.contactFirstName,
lastName: data.contacts.contactLastName,
phoneNumber: data.contacts.contactPhoneNumber,
Expand All @@ -363,6 +365,9 @@ async function onSubmit(data: any) {
// Send confirmation email
emailConfirmation(response.data.activityId, response.data.submissionId);
// Save contact data to store
contactStore.setContact(submissionData.contacts[0]);
router.push({
name: RouteName.HOUSING_SUBMISSION_CONFIRMATION,
query: {
Expand Down Expand Up @@ -467,18 +472,22 @@ onBeforeMount(async () => {
// Set form to read-only on non draft form reopening
editable.value = false;
} else {
// Load contact data for new submission
response = { contacts: [contactStore.getContact] };
}
initialFormValues.value = {
activityId: response?.activityId,
submissionId: response?.submissionId,
contacts: {
contactFirstName: response?.contacts[0].firstName,
contactLastName: response?.contacts[0].lastName,
contactPhoneNumber: response?.contacts[0].phoneNumber,
contactEmail: response?.contacts[0].email,
contactApplicantRelationship: response?.contacts[0].contactApplicantRelationship,
contactPreference: response?.contacts[0].contactPreference
contactFirstName: response?.contacts[0]?.firstName,
contactLastName: response?.contacts[0]?.lastName,
contactPhoneNumber: response?.contacts[0]?.phoneNumber,
contactEmail: response?.contacts[0]?.email,
contactApplicantRelationship: response?.contacts[0]?.contactApplicantRelationship,
contactPreference: response?.contacts[0]?.contactPreference,
contactId: response?.contacts[0]?.contactId
},
basic: {
consentToFeedback: response?.consentToFeedback,
Expand Down Expand Up @@ -623,6 +632,13 @@ onBeforeMount(async () => {
<Card>
<template #title>
<span class="section-header">{{ t('submissionIntakeForm.contactCard') }}</span>
<span
v-tooltip.right="t('submissionIntakeForm.contactTooltip')"
v-tooltip.focus.right="t('submissionIntakeForm.contactTooltip')"
tabindex="0"
>
<font-awesome-icon icon="fa-solid fa-circle-question" />
</span>
<Divider type="solid" />
</template>
<template #content>
Expand All @@ -632,44 +648,44 @@ onBeforeMount(async () => {
:name="`contacts.contactFirstName`"
label="First name"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contacts?.contactFirstName ? true : !editable"
/>
<InputText
class="col-6"
:name="`contacts.contactLastName`"
label="Last name"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contacts?.contactLastName ? true : !editable"
/>
<InputMask
class="col-6"
:name="`contacts.contactPhoneNumber`"
mask="(999) 999-9999"
label="Phone number"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contacts?.contactPhoneNumber ? true : !editable"
/>
<InputText
class="col-6"
:name="`contacts.contactEmail`"
label="Email"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contacts?.contactEmail ? true : !editable"
/>
<Dropdown
class="col-6"
:name="`contacts.contactApplicantRelationship`"
label="Relationship to project"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contacts?.contactApplicantRelationship ? true : !editable"
:options="PROJECT_RELATIONSHIP_LIST"
/>
<Dropdown
class="col-6"
:name="`contacts.contactPreference`"
label="Preferred contact method"
:bold="false"
:disabled="!editable"
:disabled="initialFormValues?.contacts?.contactPreference ? true : !editable"
:options="CONTACT_PREFERENCE_LIST"
/>
</div>
Expand Down
Loading

0 comments on commit 8542eb9

Please sign in to comment.