Skip to content

Commit

Permalink
feat: add functionality to send emails from WorksiteForm (#1317)
Browse files Browse the repository at this point in the history
- Implemented `sendEmail` method in WorksiteForm for sending emails to survivors.
- Added email icon to the email input field, dynamically displayed based on conditions.
- Integrated confirmation dialog when triggering email sending.
- Added `sendSurvivorEmail` API method in Worksite model to handle email requests.
  • Loading branch information
tabiodun authored Dec 26, 2024
1 parent 156eb8d commit 854ae1f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/components/work/WorksiteForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@
selector="js-worksite-email"
size="large"
:placeholder="$t('formLabels.email')"
:fa-icon="
currentIncident.auto_contact && worksite.id ? 'envelope' : null
"
@update:model-value="(v) => updateWorksite(v, 'email')"
@icon-clicked="() => sendEmail(worksite.email)"
/>
</div>
<div class="form-field">
Expand Down Expand Up @@ -941,6 +945,32 @@ export default defineComponent({
}
}
async function sendEmail(email: string) {
try {
const result = await confirm({
title: t(`actions.confirm`),
content: t(`caseForm.confirm_send_email`),
actions: {
no: {
text: t('actions.cancel'),
type: 'outline',
buttonClass: 'border border-black',
},
yes: {
text: t('actions.send_message'),
type: 'solid',
},
},
});
if (result === 'yes') {
await Worksite.api().sendSurvivorEmail(worksite.value.id, email);
$toasted.success(t('caseForm.email_sent'));
}
} catch (error) {
$toasted.error(getErrorMessage(error));
}
}
async function findPotentialGeocode() {
const geocodeKeys = ['address', 'city', 'county', 'state', 'postal_code'];
const nonEmptyKeys = geocodeKeys.filter((key) =>
Expand Down Expand Up @@ -1713,13 +1743,8 @@ export default defineComponent({
getSectionCount,
clearWorksiteStorage,
statusValueChange,
reloadWorksite,
sendSms,
findPotentialGeocode,
checkGeocodeLocation,
potentialIncidents,
getPotentialIncidents,
updateWorksiteFields,
unlockLocationFields,
clearLocationFields,
collapseGreenPhoneSection,
Expand Down Expand Up @@ -1762,6 +1787,7 @@ export default defineComponent({
hasFormHeaderContent,
supportedLanguages,
emitManualDialer,
sendEmail,
};
},
});
Expand Down
9 changes: 9 additions & 0 deletions src/models/Worksite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,15 @@ export default class Worksite extends CCUModel {
{ save: false },
);
},
sendSurvivorEmail(id, email) {
return this.post(
`/worksites/${id}/send_survivor_email`,
{
email,
},
{ save: false },
);
},
searchWorksites(search, incident) {
return this.get(
`/worksites?fields=id,name,address,case_number,postal_code,city,state,incident,work_types&limit=5&search=${search}&incident=${incident}`,
Expand Down

0 comments on commit 854ae1f

Please sign in to comment.