diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index 44cac326..a9266069 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -156,6 +156,24 @@ export const getRoleQuestions = (roleId: number) => path: `/role/${roleId}/questions`, }); +export const postEmail = ({ + applicantId, + roleId, + subject, + body, +}: { + applicantId: number; + roleId: number; + subject: string; + body: string; +}) => + authenticatedRequest({ + method: "POST", + path: `/role/${roleId}/email`, + body: { dest_id: applicantId, subject, body }, + jsonResp: false, + }); + export const setApplicationRating = (applicationId: number, rating: number) => authenticatedRequest({ method: "PUT", diff --git a/frontend/src/pages/admin/review/finalise_candidates/index.tsx b/frontend/src/pages/admin/review/finalise_candidates/index.tsx index 96f2e870..95c5eaa2 100644 --- a/frontend/src/pages/admin/review/finalise_candidates/index.tsx +++ b/frontend/src/pages/admin/review/finalise_candidates/index.tsx @@ -56,7 +56,7 @@ const FinaliseCandidates = () => { } ); - useFetch(`/campaign/${campaignId}`, { + const { data: campaign } = useFetch(`/campaign/${campaignId}`, { deps: [], errorSummary: "Error getting campaign", onSuccess: ({ name, organisation_id: orgId }) => { @@ -88,6 +88,7 @@ const FinaliseCandidates = () => { () => data?.applications.map((a) => ({ id: a.id, + applicantId: a.user_id, name: a.user_display_name, contents: (
@@ -158,10 +159,23 @@ const FinaliseCandidates = () => { ); })(); + const { post: sendPostEmail } = useFetch(`/role/${roleId}/email`); + const sendEmail = useCallback( - // TODO: actually send the email, this just updates the public status async (tab: number) => { - const { id, status, name } = tabs[tab]; + if (campaign === null) { + return false; + } + + const { id, applicantId, status, name } = tabs[tab]; + await sendPostEmail("", { + body: { + dest_id: applicantId, + roleId, + subject: `${campaign.name} application outcome`, + body: renderEmail(id, name), + }, + }); const { error, aborted } = await putStatus(id, { body: status, errorSummary: `Failed to release result for ${name}`,