Skip to content

Commit

Permalink
Send email to user when status is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
rlho committed Mar 27, 2024
1 parent aedd639 commit 60c7136
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion media_commons_booking_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"deploy:staging": "rimraf dist && npm run build:staging && npx clasp push",
"deploy": "rimraf dist && npm run build && npx clasp push",
"serve": "cross-env NODE_ENV=development CALENDAR_ENV=development webpack serve",
"start": "npm run deploy:dev && npm run serve"
"start": "npm run deploy:local && npm run serve"
},
"keywords": [
"react",
Expand Down
38 changes: 36 additions & 2 deletions media_commons_booking_app/src/server/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from './db';
import { inviteUserToCalendarEvent, updateEventPrefix } from './calendars';

import { sendHTMLEmail } from './emails';
import { sendHTMLEmail, sendTextEmail } from './emails';

export const bookingContents = (id: string) => {
const values = fetchById(TableNames.BOOKING, id);
Expand Down Expand Up @@ -112,6 +112,11 @@ export const approveEvent = (id: string) => {
id,
ActiveSheetBookingStatusColumns.EMAIL
);
sendTextEmail(
guestEmail,
'Media Commons Reservation Approved',
'Your reservation request for Media Commons is approved.'
);

updateEventPrefix(id, 'APPROVED');
inviteUserToCalendarEvent(id, guestEmail);
Expand All @@ -125,7 +130,16 @@ export const reject = (id: string) => {
new Date()
);

//TODO: send email to user
const guestEmail = getActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
ActiveSheetBookingStatusColumns.EMAIL
);
sendTextEmail(
guestEmail,
'Media Commons Reservation Has Been Rejected',
'Your reservation request for Media Commons has been rejected. For detailed reasons regarding this decision, please contact us at [email protected].'
);
updateEventPrefix(id, 'REJECTED');
};

Expand All @@ -136,6 +150,16 @@ export const cancel = (id: string) => {
ActiveSheetBookingStatusColumns.CANCELLED_DATE,
new Date()
);
const guestEmail = getActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
ActiveSheetBookingStatusColumns.EMAIL
);
sendTextEmail(
guestEmail,
'Media Commons Reservation Has Been Cancelled',
'Your reservation request for Media Commons has been cancelled. For detailed reasons regarding this decision, please contact us at [email protected].'
);
updateEventPrefix(id, 'CANCELLED');
};

Expand All @@ -146,6 +170,16 @@ export const checkin = (id: string) => {
ActiveSheetBookingStatusColumns.CHECKED_IN_DATE,
new Date()
);
const guestEmail = getActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
ActiveSheetBookingStatusColumns.EMAIL
);
sendTextEmail(
guestEmail,
'Media Commons Reservation Has Been Checked In',
'Your reservation request for Media Commons has been checked in. Thank you for choosing Media Commons.'
);
updateEventPrefix(id, 'CHECKED IN');
};

Expand Down

0 comments on commit 60c7136

Please sign in to comment.