Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): integrate sending emails with backend #424

Draft
wants to merge 1 commit into
base: cringe_email
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions frontend/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 17 additions & 3 deletions frontend/src/pages/admin/review/finalise_candidates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const FinaliseCandidates = () => {
}
);

useFetch<Campaign>(`/campaign/${campaignId}`, {
const { data: campaign } = useFetch<Campaign>(`/campaign/${campaignId}`, {
deps: [],
errorSummary: "Error getting campaign",
onSuccess: ({ name, organisation_id: orgId }) => {
Expand Down Expand Up @@ -88,6 +88,7 @@ const FinaliseCandidates = () => {
() =>
data?.applications.map((a) => ({
id: a.id,
applicantId: a.user_id,
name: a.user_display_name,
contents: (
<div tw="flex gap-2">
Expand Down Expand Up @@ -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}`,
Expand Down