-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Match form to CHES schema and add validation
Add BCC config for prod. Emails are sending.
- Loading branch information
1 parent
9b29059
commit 336cbc9
Showing
20 changed files
with
268 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ config: | |
enabled: true | ||
configMap: | ||
FRONTEND_APIPATH: api/v1 | ||
FRONTEND_CHES_BCC: [email protected] | ||
FRONTEND_COMS_APIPATH: https://coms.api.gov.bc.ca/api/v1 | ||
FRONTEND_COMS_BUCKETID: 0089d041-5aab-485e-842d-8875475d0ed6 | ||
FRONTEND_OIDC_AUTHORITY: https://loginproxy.gov.bc.ca/auth/realms/standard | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<script setup lang="ts"> | ||
import { Form } from 'vee-validate'; | ||
import { onMounted, ref } from 'vue'; | ||
import { array, object, string } from 'yup'; | ||
import { InputText, TextArea } from '@/components/form'; | ||
import { Button, useConfirm, useToast } from '@/lib/primevue'; | ||
import { roadmapService, userService } from '@/services'; | ||
import { useConfigStore } from '@/store'; | ||
import { PERMIT_STATUS } from '@/utils/enums'; | ||
import { roadmapTemplate } from '@/utils/templates'; | ||
import type { Ref } from 'vue'; | ||
import type { Permit, PermitType, Submission } from '@/types'; | ||
import { storeToRefs } from 'pinia'; | ||
// Props | ||
type Props = { | ||
activityId: string; | ||
permits: Array<Permit>; | ||
permitTypes: Array<PermitType>; | ||
submission: Submission; | ||
}; | ||
const props = withDefaults(defineProps<Props>(), {}); | ||
// Store | ||
const { getConfig } = storeToRefs(useConfigStore()); | ||
// State | ||
const initialFormValues: Ref<any> = ref(); | ||
// Form schema | ||
const emailValidator = array() | ||
.transform(function (value, originalValue) { | ||
if (this.isType(value) && value !== null) { | ||
return value; | ||
} | ||
return originalValue ? originalValue.split(/[\s,]+/) : []; | ||
}) | ||
.of(string().email(({ value }) => `${value} is not a valid email`)); | ||
const formSchema = object({ | ||
to: emailValidator, | ||
cc: emailValidator, | ||
bcc: emailValidator, | ||
subject: string().required(), | ||
body: string().required() | ||
}); | ||
// Actions | ||
const confirm = useConfirm(); | ||
const toast = useToast(); | ||
const confirmSubmit = (data: any) => { | ||
confirm.require({ | ||
message: 'Please confirm that you want to send this roadmap. This cannot be undone.', | ||
header: 'Confirm sending this Roadmap', | ||
acceptLabel: 'Send', | ||
rejectLabel: 'Cancel', | ||
accept: async () => { | ||
try { | ||
await roadmapService.send(props.activityId, data); | ||
toast.success('Roadmap sent'); | ||
} catch (e: any) { | ||
toast.error('Failed to send roadmap', e.message); | ||
} | ||
} | ||
}); | ||
}; | ||
function getPermitTypeNamesByStatus(permits: Array<Permit>, permitTypes: Array<PermitType>, status: string) { | ||
return permits | ||
.map((p) => permitTypes.find((pt) => pt.permitTypeId === p.permitTypeId && p.status === status)?.name) | ||
.filter((pt) => !!pt) | ||
.map((name) => name as string); | ||
} | ||
onMounted(async () => { | ||
const assignee = (await userService.searchUsers({ userId: [props.submission.assignedUserId] })).data[0]; | ||
const configBCC = getConfig.value.ches?.bcc; | ||
const bcc = assignee.email + (configBCC ? `, ${configBCC}` : ''); | ||
// Initial form values | ||
initialFormValues.value = { | ||
from: assignee.email, | ||
to: props.submission.contactEmail, | ||
cc: undefined, | ||
bcc: bcc, | ||
subject: "Here is your housing project's Permit Roadmap", // eslint-disable-line quotes | ||
bodyType: 'text', | ||
body: roadmapTemplate({ | ||
'{{ contactName }}': props.submission.contactName ?? '', | ||
'{{ locationAddress }}': props.submission.streetAddress ?? '', | ||
'{{ permitStateNew }}': getPermitTypeNamesByStatus(props.permits, props.permitTypes, PERMIT_STATUS.NEW), | ||
'{{ permitStateApplied }}': getPermitTypeNamesByStatus(props.permits, props.permitTypes, PERMIT_STATUS.APPLIED), | ||
'{{ permitStateCompleted }}': getPermitTypeNamesByStatus( | ||
props.permits, | ||
props.permitTypes, | ||
PERMIT_STATUS.COMPLETED | ||
), | ||
'{{ navigatorName }}': `${assignee.firstName} ${assignee.lastName}` | ||
}) | ||
}; | ||
}); | ||
</script> | ||
|
||
<template> | ||
<Form | ||
v-if="initialFormValues" | ||
:initial-values="initialFormValues" | ||
:validation-schema="formSchema" | ||
@submit="confirmSubmit" | ||
> | ||
<div class="formgrid grid"> | ||
<InputText | ||
class="col-12 lg:col-6" | ||
name="to" | ||
label="To" | ||
/> | ||
<div class="col" /> | ||
<InputText | ||
class="col-12 lg:col-6" | ||
name="cc" | ||
label="CC" | ||
/> | ||
<div class="col" /> | ||
<InputText | ||
class="col-12 lg:col-6" | ||
name="bcc" | ||
label="BCC" | ||
/> | ||
<div class="col" /> | ||
<InputText | ||
class="col-12 lg:col-6" | ||
name="subject" | ||
label="Subject" | ||
/> | ||
<div class="col" /> | ||
<TextArea | ||
class="col-12" | ||
name="body" | ||
label="Note" | ||
:rows="10" | ||
/> | ||
<div class="col-12"><label class="font-bold">Add attachments</label></div> | ||
<div class="col-12 pt-2"> | ||
<Button> | ||
<font-awesome-icon | ||
icon="fa-solid fa-plus" | ||
class="mr-1" | ||
/> | ||
Choose | ||
</Button> | ||
</div> | ||
<div class="col-12 pt-5"> | ||
<Button | ||
label="Send" | ||
type="submit" | ||
icon="pi pi-envelope" | ||
/> | ||
</div> | ||
</div> | ||
</Form> | ||
</template> |
Oops, something went wrong.