Skip to content

Commit

Permalink
Merge pull request #136 from bcgov/feature/change-related-enquiry
Browse files Browse the repository at this point in the history
Change Related Enquiry
  • Loading branch information
kyle1morel authored Aug 23, 2024
2 parents 857b746 + 4554225 commit a85c284
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 11 deletions.
10 changes: 10 additions & 0 deletions app/src/controllers/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,16 @@ const controller = {
return submissionData;
},

getActivityIds: async (req: Request<never, { self?: string }>, res: Response, next: NextFunction) => {
try {
const response = await submissionService.getActivityIds();

res.status(200).json(response);
} catch (e: unknown) {
next(e);
}
},

createDraft: async (req: Request, res: Response, next: NextFunction) => {
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
5 changes: 5 additions & 0 deletions app/src/routes/v1/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ router.get('/', (req: Request, res: Response, next: NextFunction): void => {
submissionController.getSubmissions(req, res, next);
});

/** Get a list of all the activityIds */
router.get('/activityIds', (req: Request, res: Response, next: NextFunction): void => {
submissionController.getActivityIds(req, res, next);
});

/** Search submissions */
router.get(
'/search',
Expand Down
14 changes: 14 additions & 0 deletions app/src/services/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ function chefsAxios(formId: string, options: AxiosRequestConfig = {}): AxiosInst
}

const service = {
/**
* @function getActivityIds
* Gets a list of activity IDs
* @returns {Promise<string[]>} The result of running the findMany operation
*/
getActivityIds: async () => {
try {
const result = await prisma.submission.findMany({ select: { activity_id: true } });
return result.map((x) => x.activity_id);
} catch (e: unknown) {
throw e;
}
},

/**
* @function createSubmission
* Creates a new submission
Expand Down
23 changes: 20 additions & 3 deletions frontend/src/components/housing/enquiry/EnquiryForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
TextArea
} from '@/components/form';
import { Button, Message, useToast } from '@/lib/primevue';
import { enquiryService, userService } from '@/services';
import { enquiryService, submissionService, userService } from '@/services';
import { useEnquiryStore } from '@/store';
import { Regex } from '@/utils/enums/application';
import { BasicResponse, Regex } from '@/utils/enums/application';
import { IntakeStatus } from '@/utils/enums/housing';
import {
APPLICATION_STATUS_LIST,
Expand Down Expand Up @@ -47,10 +47,15 @@ const props = withDefaults(defineProps<Props>(), {
editable: true
});
// Emit
const emit = defineEmits(['enquiryForm:saved']);
// State
const assigneeOptions: Ref<Array<User>> = ref([]);
const editable: Ref<boolean> = ref(props.editable);
const filteredProjectActivityIds: Ref<Array<string>> = ref([]);
const formRef: Ref<InstanceType<typeof Form> | null> = ref(null);
const projectActivityIds: Ref<Array<string>> = ref([]);
const initialFormValues: Ref<any | undefined> = ref(undefined);
const showCancelMessage: Ref<boolean> = ref(false);
Expand Down Expand Up @@ -140,12 +145,19 @@ function onInvalidSubmit(e: any) {
first?.scrollIntoView({ behavior: 'smooth' });
}
function onRelatedActivityInput(e: IInputEvent) {
filteredProjectActivityIds.value = projectActivityIds.value.filter((id) =>
id.toUpperCase().includes(e.target.value.toUpperCase())
);
}
const onSubmit = async (values: any) => {
try {
editable.value = false;
const submitData: Enquiry = omit(setEmptyStringsToNull(values) as EnquiryForm, ['user']);
submitData.assignedUserId = values.user?.userId ?? undefined;
submitData.isRelated = submitData.relatedActivityId ? BasicResponse.YES : BasicResponse.NO;
const result = await enquiryService.updateEnquiry(values.enquiryId, submitData);
enquiryStore.setEnquiry(result.data);
Expand All @@ -156,6 +168,7 @@ const onSubmit = async (values: any) => {
user: values.user
}
});
emit('enquiryForm:saved');
toast.success('Form saved');
} catch (e: any) {
Expand All @@ -174,6 +187,7 @@ onMounted(async () => {
submittedAt: new Date(props.enquiry?.submittedAt),
user: assigneeOptions.value[0] ?? null
};
projectActivityIds.value = filteredProjectActivityIds.value = (await submissionService.getActivityIds()).data;
});
</script>

Expand Down Expand Up @@ -211,11 +225,14 @@ onMounted(async () => {
label="Submission date"
:disabled="!editable"
/>
<InputText
<EditableDropdown
class="col-3"
name="relatedActivityId"
label="Related submission"
:disabled="!editable"
:options="filteredProjectActivityIds"
:get-option-label="(e: string) => e"
@on-input="onRelatedActivityInput"
/>
<div class="col-3" />

Expand Down
8 changes: 8 additions & 0 deletions frontend/src/services/submissionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { delimitEmails } from '@/utils/utils';
import type { Email } from '@/types';

export default {
/**
* @function getActivityIds
* @returns {Promise} An axios response
*/
getActivityIds() {
return appAxios().get('submission/activityIds');
},

/**
* @function createDraft
* @returns {Promise} An axios response
Expand Down
36 changes: 28 additions & 8 deletions frontend/src/views/housing/enquiry/EnquiryView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ onMounted(async () => {
enquiryStore.setEnquiry(enquiry);
enquiryStore.setNotes(notes);
if (enquiry?.relatedActivityId) {
relatedSubmission.value = (
await submissionService.searchSubmissions({
activityId: [enquiry.relatedActivityId]
})
).data[0];
}
updateRelatedEnquiry();
}
loading.value = false;
Expand All @@ -63,6 +57,20 @@ const onUpdateNote = (oldNote: Note, newNote: Note) => {
const onDeleteNote = (note: Note) => {
enquiryStore.removeNote(note);
};
async function updateRelatedEnquiry() {
if (getEnquiry?.value?.relatedActivityId) {
relatedSubmission.value = (
await submissionService.searchSubmissions({
activityId: [getEnquiry?.value?.relatedActivityId]
})
).data[0];
} else relatedSubmission.value = undefined;
}
function onEnquiryFormSaved() {
updateRelatedEnquiry();
}
</script>

<template>
Expand Down Expand Up @@ -98,8 +106,20 @@ const onDeleteNote = (note: Note) => {
{{ getEnquiry?.relatedActivityId }}
</router-link>
</Message>

<Message
v-if="getEnquiry?.relatedActivityId && !relatedSubmission"
severity="error"
class="text-center"
:closable="false"
>
This activity is linked to an invalid Activity
</Message>
<span v-if="!loading && getEnquiry">
<EnquiryForm :enquiry="getEnquiry" />
<EnquiryForm
:enquiry="getEnquiry"
@enquiry-form:saved="onEnquiryFormSaved"
/>
</span>
</TabPanel>
<TabPanel header="Notes">
Expand Down

0 comments on commit a85c284

Please sign in to comment.