Skip to content

Commit

Permalink
proponent related submissions dropdown added
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaytkbabu committed Sep 4, 2024
1 parent cc2b596 commit e233708
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
9 changes: 6 additions & 3 deletions app/src/controllers/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,12 @@ const controller = {

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

res.status(200).json(response);
let response = await submissionService.getSubmissions();
if (req.currentAuthorization?.attributes.includes('scope:self')) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response = response.filter((x) => x?.submittedBy === getCurrentUsername(req.currentContext));
}
res.status(200).json(response.map((x) => x.activityId));
} catch (e: unknown) {
next(e);
}
Expand Down
10 changes: 7 additions & 3 deletions app/src/routes/v1/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ router.get(
);

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

/** Search submissions */
router.get(
Expand Down
14 changes: 0 additions & 14 deletions app/src/services/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ 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
32 changes: 26 additions & 6 deletions frontend/src/components/housing/enquiry/EnquiryIntakeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import { useRouter } from 'vue-router';
import { object, string } from 'yup';
import BackButton from '@/components/common/BackButton.vue';
import { Dropdown, InputMask, InputText, RadioList, StepperNavigation, TextArea } from '@/components/form';
import {
EditableDropdown,
Dropdown,
InputMask,
InputText,
RadioList,
StepperNavigation,
TextArea
} from '@/components/form';
import CollectionDisclaimer from '@/components/housing/CollectionDisclaimer.vue';
import EnquiryIntakeConfirmation from '@/components/housing/enquiry/EnquiryIntakeConfirmation.vue';
import { Button, Card, Divider, useConfirm, useToast } from '@/lib/primevue';
Expand All @@ -20,6 +28,7 @@ import { IntakeFormCategory, IntakeStatus } from '@/utils/enums/housing';
import { confirmationTemplate } from '@/utils/templates';
import type { Ref } from 'vue';
import type { IInputEvent } from '@/interfaces';
const { formUpdated, stopAutoSave } = useAutoSave(async () => {
const values = formRef.value?.values;
Expand Down Expand Up @@ -47,7 +56,9 @@ const { getConfig } = storeToRefs(useConfigStore());
// State
const assignedActivityId: Ref<string | undefined> = ref(undefined);
const editable: Ref<boolean> = ref(true);
const filteredProjectActivityIds: Ref<Array<string>> = ref([]);
const formRef: Ref<InstanceType<typeof Form> | null> = ref(null);
const projectActivityIds: Ref<Array<string>> = ref([]);
const validationErrors: Ref<string[]> = ref([]);
// Form validation schema
Expand Down Expand Up @@ -222,8 +233,15 @@ async function loadEnquiry(enquiryId: string) {
});
}
onBeforeMount(() => {
function onRelatedActivityInput(e: IInputEvent) {
filteredProjectActivityIds.value = projectActivityIds.value.filter((id) =>
id.toUpperCase().includes(e.target.value.toUpperCase())
);
}
onBeforeMount(async () => {
if (props.enquiryId) loadEnquiry(props.enquiryId);
projectActivityIds.value = filteredProjectActivityIds.value = (await submissionService.getActivityIds()).data;
});
async function emailConfirmation(activityId: string) {
Expand Down Expand Up @@ -393,12 +411,14 @@ async function checkActivityIdValidity(event: Event) {
</template>
<template #content>
<div class="formgrid grid">
<InputText
class="col-6"
<EditableDropdown
class="col-3"
name="basic.relatedActivityId"
placeholder="Confirmation ID"
label="Confirmation ID"
:disabled="!editable"
@on-change="checkActivityIdValidity"
:options="filteredProjectActivityIds"
:get-option-label="(e: string) => e"
@on-input="onRelatedActivityInput"
/>
</div>
</template>
Expand Down

0 comments on commit e233708

Please sign in to comment.