Skip to content

Commit

Permalink
Remove template from email request
Browse files Browse the repository at this point in the history
  • Loading branch information
ArendPeter committed Nov 30, 2024
1 parent 5d9edbf commit af5dc97
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const SendEmailEventQueue = "sendEmailEvent";
export type email_request_data = {
voter_id?: string,
email: {
template: 'invite' | 'blank' | 'receipt',
subject: string,
body: string,
}
Expand All @@ -37,7 +36,6 @@ export type email_request_event = {
url: string,
electionRoll: ElectionRoll,
email: {
template: 'invite' | 'blank' | 'receipt',
subject: string,
body: string,
},
Expand All @@ -61,10 +59,6 @@ const sendEmailsController = async (req: IElectionRequest, res: Response, next:
throw new BadRequest(msg)
}

if (email_request.email.template === 'receipt') {
throw new InternalServerError('Receipts not yet supported');
}

let message_id = ''

if (email_request.target == 'single') {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/Services/Email/EmailTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export function makeEmails(election: Election, voters: ElectionRoll[], url: stri
...emailSettings,
to: voter.email, // Change to your recipient
from: process.env.FROM_EMAIL_ADDRESS ?? '',
subject: email_subject ?? `Invitation to Vote In ${election.title}`,
text: `${election.state === 'draft' ? `[⚠️Test ${election.settings.term_type}]` : ''} ${email_body ?? '' } You have been invited to vote in ${election.title} ${url}/${election.election_id}`,
subject: email_subject,
text: `${election.state === 'draft' ? `[⚠️Test ${election.settings.term_type}]` : ''} You have received a message from election ${election.title}`,
html: emailTemplate(`
${election.state === 'draft' ? `<h3>⚠️This ${election.settings.term_type} is still in test mode. All ballots during test mode will be removed once the election is finalized, and at that time you will need to vote again.⚠️</h3>` : ''}
${processEmailBody(email_body, voter.voter_id)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import useElection from "~/components/ElectionContextProvider";
import { StyledButton } from "~/components/styles";
import { LabelledTextField, RowButtonWithArrow } from "~/components/util";

const formatTime = (time: string | Date, tz: string) => DateTime.fromJSDate(new Date(time)).setZone(tz).toLocaleString(DateTime.DATETIME_FULL);

export default ({open, onClose, onSubmit, targetedEmail=undefined}) => {
const authSession = useAuthSession()
const [audience, setAudience] = useState(targetedEmail? 'single' : 'all')
Expand Down Expand Up @@ -75,7 +73,7 @@ export default ({open, onClose, onSubmit, targetedEmail=undefined}) => {
{/*minWidth keeps text from wrapping during the transition*/}
<Box display='flex' gap={1} flexDirection={'column'} sx={{width: '100%', minWidth: sizes}}>
<Typography sx={{mb: 1}}>Which template would you like to start with?</Typography>
{['invite', 'receipt', 'blank'].map((v, i) =>
{['invite', /*'receipt', */'blank'].map((v, i) =>
<RowButtonWithArrow
key={i}
title={t(`voters.email_form.${v}`, {voter_id: targetedEmail})}
Expand Down Expand Up @@ -122,7 +120,6 @@ export default ({open, onClose, onSubmit, targetedEmail=undefined}) => {
onClick={() => {
setTemplateChosen(false)
onSubmit(
'invite', // temporary
emailSubject,
emailBody,
audience,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ const ViewElectionRolls = () => {
}, [location.search])

const onSendEmails = (
template: 'invite' | 'receipt' | 'blank',
subject: string,
body: string,
target: 'all' | 'has_voted' | 'has_not_voted' | 'single',
) => {
setDialogOpen(false);
sendEmails.makeRequest({
target: target,
email: { template, subject, body },
email: { subject, body },
})
}

Expand All @@ -67,7 +66,7 @@ const ViewElectionRolls = () => {
}

let headKeys:HeadKey[] = (election.settings.invitation === 'email')?
['voter_id', 'email', 'invite_status', 'has_voted']
['voter_id', 'email', /*'invite_status', */'has_voted']
:
['voter_id', 'email', 'has_voted'];

Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/src/i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,8 @@ voters:

# Email Templates
emails:
voting_begin: Voting will begin on {datetime, datetime}
voting_end: '**Voting ends on {datetime, datetime}**'
voting_begin: Voting will begin on {{datetime, datetime}}
voting_end: '**Voting ends on {{datetime, datetime}}**'
election_description: '{{capital_election}} {{description}}'
invite:
subject: Invitation to vote in {{title}}
Expand All @@ -870,6 +870,9 @@ emails:
__VOTE_BUTTON__
This link is unique to you, be careful not to share this email with others
blank:
subject: An update from {{title}}
body: __ELECTION_HOME_BUTTON__

# Ballots

Expand Down

0 comments on commit af5dc97

Please sign in to comment.