Skip to content

Commit

Permalink
wip-feature: Allow resend of acceptance/rejection emails (#592)
Browse files Browse the repository at this point in the history
* Allow resend of acceptance/rejection emails

* Change logic for frontend submission collection

* Fix bug in pre-commit frontend lint

Update .pre-commit-config.yaml

* Add toast warning to resend checkbox

---------

Co-authored-by: Julian Weng <[email protected]>
  • Loading branch information
aviupadhyayula and julianweng authored Oct 2, 2023
1 parent 7e347ff commit caf576f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 7 additions & 1 deletion backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4665,13 +4665,17 @@ def send_emails(self, *args, **kwargs):
Send out acceptance/rejection emails for a particular application
Dry run will validate that all emails have nonempty variables
Allow resend will renotify submissions that have already been emailed
---
requestBody:
content:
application/json:
schema:
type: object
properties:
allow_resend:
type: boolean
dry_run:
type: boolean
email_type:
Expand Down Expand Up @@ -4728,13 +4732,15 @@ def send_emails(self, *args, **kwargs):
subject = f"Application Update for {app.name}"
n, skip = 0, 0

allow_resend = self.request.data.get("allow_resend")

acceptance_template = Template(app.acceptance_email)
rejection_template = Template(app.rejection_email)

mass_emails = []
for submission in submissions:
if (
submission.notified
(not allow_resend and submission.notified)
or submission.status == ApplicationSubmission.PENDING
or not (submission.reason and submission.user.email)
):
Expand Down
22 changes: 20 additions & 2 deletions frontend/components/ClubEditPage/ApplicationsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Field, Form, Formik } from 'formik'
import moment from 'moment-timezone'
import React, { ReactElement, useEffect, useMemo, useState } from 'react'
import Select from 'react-select'
import { toast } from 'react-toastify'
import styled from 'styled-components'

import { ALLBIRDS_GRAY, CLUBS_BLUE, MD, mediaMaxWidth, SNOW } from '~/constants'
Expand Down Expand Up @@ -222,15 +223,15 @@ const NotificationModal = (props: {
if (data.email_type.id === 'acceptance' && !data.dry_run) {
const relevant = submissions.filter(
(sub) =>
sub.notified === false &&
(data.allow_resend || !sub.notified) &&
sub.status === 'Accepted' &&
sub.reason,
)
updateSubmissions(relevant)
} else if (data.email_type.id === 'rejection' && !data.dry_run) {
const relevant = submissions.filter(
(sub) =>
sub.notified === false &&
(data.allow_resend || !sub.notified) &&
sub.status.startsWith('Rejected') &&
sub.reason,
)
Expand Down Expand Up @@ -274,6 +275,23 @@ const NotificationModal = (props: {
label="Dry Run"
helpText="If selected, will return the number of emails the script would have sent out"
/>
<Field
name="allow_resend"
as={CheckboxField}
label="Resend Emails"
onClick={(e) => {
if (e.target.checked) {
toast.warning(
'Resending emails will send emails to all applicants, even if they have already been notified.',
)
}
}}
helpText={
<strong>
If selected, will resend notifications to all applicants
</strong>
}
/>
<button type="submit" className="button">
Submit
</button>
Expand Down

0 comments on commit caf576f

Please sign in to comment.