-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #278 from shaunwarman/feat/bulk-email-preview
fix: touch up admin inquiries and add gaurdrails for inquiries api
- Loading branch information
Showing
10 changed files
with
183 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright (c) Forward Email LLC | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
const $ = require('jquery'); | ||
const Swal = require('sweetalert2/dist/sweetalert2.js'); | ||
const { spinner: Spinner } = require('@ladjs/assets'); | ||
|
||
const sendRequest = require('./send-request'); | ||
|
||
const spinner = new Spinner($); | ||
|
||
function handleBulkReply() { | ||
const checkboxes = $('#table-inquiries input[type="checkbox"]:checked'); | ||
const inquiries = checkboxes | ||
.map(function () { | ||
return { id: $(this).val(), email: $(this).data('email') }; | ||
}) | ||
.get(); | ||
|
||
const emails = inquiries.map((inquiry) => inquiry.email); | ||
const uniqueEmails = [...new Set(emails)]; | ||
|
||
if (inquiries.length === 0) { | ||
Swal.fire(window._types.error, 'No inquiries selected.', 'error'); | ||
return; | ||
} | ||
|
||
if (inquiries.length === 1) { | ||
const { origin, pathname } = window.location; | ||
const redirectUrl = `${origin}${pathname}/${inquiries[0].id}`; | ||
window.location.href = redirectUrl; | ||
return; | ||
} | ||
|
||
const $emailList = $('#modal-reply-to-email-list'); | ||
$emailList.empty(); | ||
|
||
for (const email of uniqueEmails) { | ||
const listItem = $('<li class="list-group-item">').text(email); | ||
$emailList.append(listItem); | ||
} | ||
|
||
$('#bulk-reply-modal').modal('show'); | ||
} | ||
|
||
async function handleSubmitBulkReply() { | ||
console.log('testing'); | ||
const checkboxes = $('#table-inquiries input[type="checkbox"]:checked'); | ||
const inquiries = checkboxes | ||
.map(function () { | ||
return { id: $(this).val(), email: $(this).data('email') }; | ||
}) | ||
.get(); | ||
|
||
const ids = inquiries.map((inquiry) => inquiry.id); | ||
|
||
const message = $('#textarea-bulk-reply-message').val(); | ||
|
||
try { | ||
spinner.show(); | ||
|
||
const url = `${window.location.pathname}/bulk`; | ||
const response = await sendRequest({ ids, message }, url); | ||
|
||
if (response.err) { | ||
console.log('error in response', { response }); | ||
throw response.err; | ||
} | ||
|
||
spinner.hide(); | ||
|
||
location.reload(true); | ||
} catch (err) { | ||
console.error(err); | ||
spinner.hide(); | ||
Swal.fire(window._types.error, err.message, 'error'); | ||
} | ||
} | ||
|
||
$('#table-inquiries').on('click', '#bulk-reply-button', handleBulkReply); | ||
$('#submit-bulk-reply').on('click', handleSubmitBulkReply); |
Oops, something went wrong.