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

Add support for sending ad hoc batch emails #234

Merged
merged 6 commits into from Aug 28, 2018
Merged

Conversation

ehsanmasdar
Copy link
Member

@ehsanmasdar ehsanmasdar commented Aug 27, 2018

We can slice by different groups:

  • All users with an account
  • Users that haven't submitted an application

Per Application Branch:

  • Users that have submitted that application branch

Per Confirmation Branch:

  • Users that have not submitted their confirmation
  • Users that have submitted their confirmation

Closes #190
Closes #193
Based on #195 by @mjkaufer.

We can slice by different groups:
All users with an account
Users that haven't submitted an application
Per Application Branch:
Users that have submitted that application branch
Per Confirmation Branch:
Users that have not submitted their confirmation
Users that have submitted their confirmation

Closes #193, based on #195 by @mjkaufer.
@ehsanmasdar ehsanmasdar changed the title Add support for sending adhoc batch emails Add support for sending ad hoc batch emails Aug 27, 2018
Copy link
Member

@petschekr petschekr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looked over the code. Still need to actually test it out on my local environment

});
}
});

settingsRoutes.route("/email_content/:type/rendered")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is literally the same function code. Could we simplify this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, looks like you don't actually use :type for anything so it works with the method removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meant more that we might want to make this a function that we pass to those two event handlers instead of repeating twice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind you did fix this

server/common.ts Outdated
export function sanitize(input: string): string {
if (typeof input !== "string") {
export async function sendBatchMailAsync(mail: IMailObject[]): Promise<void> {
await sendgrid.send(mail);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just return the promise here instead of awaiting it.
Also why does this function exist if it's just a rename of the sendgrid method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I'm just copying the previously existing method (but adding a batch mode). Maybe this was done to allow other email methods in the future?

@@ -412,6 +413,42 @@ <h4><code>config.json</code> options</h4>
</div>
</form>
</section>
<section id="emails">
<h2>Batch Emails - BE CAREFUL</h2>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tweaked title

function generateFilter(branchFilter: HTMLInputElement, statusFilter: HTMLInputElement) {
let filter: any = {};
if (branchFilter.value !== "*" && branchFilter.value !== "na") {
let [, type, branchName] = branchFilter.value.match(/^(application|confirmation)-(.*)$/)!;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of destructuring 👍

let [, type ] = batchEmailBranchFilterSelect.value.match(/^(application|confirmation)-(.*)$/)!;
// Only confirmation branches have no-submission option since confirmation is manually assigned
if (type === "confirmation") {
let noSubmission = new Option('Have not submitted', 'no-submission');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single quotes aren't consistent

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

let noSubmission = new Option('Have not submitted', 'no-submission');
batchEmailStatusFilterSelect.add(noSubmission);
}
let submitted = new Option('Submitted', 'submitted');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

let emailBranchFilter = document.getElementById("email-branch-filter") as HTMLInputElement;
let emailStatusFilter = document.getElementById("email-status-filter") as HTMLInputElement;
let sendEmailButton = document.getElementById("sendEmail") as HTMLButtonElement;
let batchEmailSubject = document.getElementById('batch-email-subject') as HTMLInputElement;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single quotes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}).then(checkStatus).then(parseJSON).then((result: string) => {
console.log(result);
sendEmailButton.disabled = false;
sweetAlert("Dank!", "Successfully sent out your batch email!", "success");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this say how many emails got sent out so we know if it actually worked? Kinda like the current pre-confirm emails

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@hackgbot
Copy link

Hey y'all! A deployment of this PR can be found here:
https://registration-batch-emails.pr.hack.gt

@ehsanmasdar
Copy link
Member Author

@petschekr I did some testing locally but please test it also 👍

Copy link
Member

@petschekr petschekr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Tested working locally in addition to on the deployed PR instance. Just two minor things:

@@ -36,6 +36,7 @@ <h1 class="center">Admin Panel</h1>
<a href="#users" class="btn">Users</a>
<a href="#applicants" class="btn">Applicants</a>
<a href="#settings" class="btn">Settings</a>
<a href="#emails" class="btn">Emails</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this to after Applicants and before Settings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<li><strong>\{{confirmation.<code>question-name</code>}}</strong>: Prints the user's response to the confirmation question with the specified name from <code>questions.json</code>.</li>
<li><strong>\{{reimbursementAmount}}</strong>: A string representing how much a user should be reimbursed for.</li>
</ul>
<button id="sendEmail">Send Email</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be centered by wrapping in <div class="row center"></div> like the structure in the other tabs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@petschekr petschekr added enhancement Adds or suggests a new feature, rewrite, or other enhancement to the codebase high priority labels Aug 28, 2018
@petschekr petschekr added this to the HackGT 5 milestone Aug 28, 2018
Copy link
Member

@petschekr petschekr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!
Please bump to 2.3.0

@ehsanmasdar ehsanmasdar merged commit 4841e1f into master Aug 28, 2018
@ehsanmasdar ehsanmasdar deleted the batch-emails branch August 28, 2018 05:03
rahulrajus pushed a commit that referenced this pull request Jul 22, 2021
* Add support for sending adhoc batch emails

We can slice by different groups:
All users with an account
Users that haven't submitted an application
Per Application Branch:
Users that have submitted that application branch
Per Confirmation Branch:
Users that have not submitted their confirmation
Users that have submitted their confirmation

Closes #193, based on #195 by @mjkaufer.

* Updates

* Show branch type in dropdown

* HTML tweaks

* Bump version

* Use batch email to speed up acceptance emails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adds or suggests a new feature, rewrite, or other enhancement to the codebase high priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants