-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add new sessions modal in new game flow * pre seat members with email notification and community setting * update types * add changelog component * remove console log * more cleanup
- Loading branch information
Showing
33 changed files
with
1,002 additions
and
265 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
import { Handler } from "@netlify/functions"; | ||
import { buildCommunityAdminMessage, sendEmail } from "../utils"; | ||
import { buildCommunityAdminMessage, logError, sendEmail } from "../utils"; | ||
|
||
/** | ||
* This function is called any time a record is written to the | ||
* notifications table. This is where you can respond to the | ||
* record type and send an email. | ||
*/ | ||
|
||
export const handler: Handler = async (event) => { | ||
const { authorization } = event.headers; | ||
const { record } = JSON.parse(event.body); | ||
|
||
if (authorization !== process.env.WEB_MAIL_PASSWORD) { | ||
console.warn( | ||
"Unauthorized connection. Dropping notification ID", | ||
record.id | ||
); | ||
logError({ | ||
message: "Unauthorized connection. Dropping record:" + record.id, | ||
}); | ||
return { | ||
statusCode: 403, | ||
body: JSON.stringify({ | ||
|
@@ -28,7 +33,25 @@ export const handler: Handler = async (event) => { | |
}); | ||
console.info("successfully sent rsvp email"); | ||
} catch (error) { | ||
console.error("failed to send rsvp email", error); | ||
logError({ | ||
message: `failed to send rsvp email: ${error}`, | ||
}); | ||
} | ||
} | ||
if (record.type === "pre_seated_rsvp") { | ||
const adminMessage = sendPreSeatEmail({ | ||
name: record.user_name, | ||
email: record.email, | ||
relatedUrl: record.related_url, | ||
gameName: record.custom_fields?.game_name, | ||
}); | ||
try { | ||
await sendEmail(adminMessage); | ||
console.info("successfully sent community admin email"); | ||
} catch (error) { | ||
logError({ | ||
message: `failed to send pre_seat email: ${error}`, | ||
}); | ||
} | ||
} | ||
if (record.type === "cancel") { | ||
|
@@ -40,7 +63,9 @@ export const handler: Handler = async (event) => { | |
}); | ||
console.info("successfully sent cancel email"); | ||
} catch (error) { | ||
console.error("failed to send cancel email", error); | ||
logError({ | ||
message: `failed to send cancel email: ${error}`, | ||
}); | ||
} | ||
} | ||
if (record.type === "notify_creator_of_rsvp") { | ||
|
@@ -53,7 +78,9 @@ export const handler: Handler = async (event) => { | |
}); | ||
console.info("successfully sent new join email"); | ||
} catch (error) { | ||
console.error("failed to send new join email", error); | ||
logError({ | ||
message: `failed to send join email: ${error}`, | ||
}); | ||
} | ||
} | ||
} | ||
|
@@ -67,7 +94,9 @@ export const handler: Handler = async (event) => { | |
}); | ||
console.info("successfully sent membership approval email"); | ||
} catch (error) { | ||
console.error("failed to send membership approval email", error); | ||
logError({ | ||
message: `failed to send membership_request email: ${error}`, | ||
}); | ||
} | ||
} | ||
if ( | ||
|
@@ -85,7 +114,9 @@ export const handler: Handler = async (event) => { | |
await sendEmail(adminMessage); | ||
console.info("successfully sent community admin email"); | ||
} catch (error) { | ||
console.error("failed to send community admin email", error); | ||
logError({ | ||
message: `failed to send community_admin email: ${error}`, | ||
}); | ||
} | ||
} | ||
|
||
|
@@ -116,6 +147,28 @@ function sendMembershipApprovalEmail({ name, email, relatedUrl, message }) { | |
}; | ||
return sendEmail(mailjetMessage); | ||
} | ||
function sendPreSeatEmail({ name, email, relatedUrl, gameName }) { | ||
const mailjetMessage = { | ||
From: { | ||
Email: "[email protected]", | ||
Name: "Playabl Notifications", | ||
}, | ||
To: [ | ||
{ | ||
Email: email, | ||
Name: name, | ||
}, | ||
], | ||
TemplateID: 5423059, | ||
TemplateLanguage: true, | ||
Subject: `Playabl - You've been pre-seated for ${gameName}!`, | ||
Variables: { | ||
game_name: gameName, | ||
related_url: relatedUrl, | ||
}, | ||
}; | ||
return sendEmail(mailjetMessage); | ||
} | ||
function sendRsvpEmail({ name, email, relatedUrl, gameName }) { | ||
const mailjetMessage = { | ||
From: { | ||
|
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,59 @@ | ||
import { Handler } from "@netlify/functions"; | ||
import { addNotificationRecord, authenticateUser, supabase } from "../utils"; | ||
|
||
export const handler: Handler = async (event) => { | ||
const user = await authenticateUser(event); | ||
if (!user) { | ||
return { | ||
statusCode: 403, | ||
body: "not authorized", | ||
}; | ||
} | ||
|
||
const sessions = JSON.parse(event.body); | ||
|
||
const { data: game } = await supabase | ||
.from("games") | ||
.select("*") | ||
.eq("id", sessions[0].game_id) | ||
.single(); | ||
|
||
if (game.creator_id !== user.data.user.id) { | ||
return { | ||
statusCode: 403, | ||
body: "not authorized", | ||
}; | ||
} | ||
|
||
const toNotify = new Set( | ||
sessions.reduce((users, curSession) => { | ||
if (curSession?.rsvps?.length > 0) { | ||
return users.concat(curSession.rsvps); | ||
} | ||
return users; | ||
}, []), | ||
); | ||
|
||
const { data: profiles } = await supabase | ||
.from("profiles") | ||
.select("*") | ||
.in("id", [...toNotify]); | ||
|
||
for (const user of profiles) { | ||
await addNotificationRecord({ | ||
user_id: user.id, | ||
user_name: user.username, | ||
email: user.email, | ||
message: `You have been pre-seated in the game ${game.title}`, | ||
related_url: `https://app.playabl.io/games/${game.id}`, | ||
type: "pre_seated_rsvp", | ||
custom_fields: { | ||
game_name: game.title, | ||
}, | ||
}); | ||
} | ||
|
||
return { | ||
statusCode: 201, | ||
}; | ||
}; |
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,46 @@ | ||
<template> | ||
<button | ||
id="headway-trigger" | ||
class="fixed bottom-12 right-12 bg-white rounded-full px-3 py-2 shadow-lg flex items-center z-20" | ||
> | ||
<BellAlertIcon class="w-5 h-5 text-slate-700" /> | ||
<div class="absolute -top-2 -right-2"> | ||
<span class="headway" /> | ||
</div> | ||
</button> | ||
</template> | ||
<script setup lang="ts"> | ||
import { BellAlertIcon } from "@heroicons/vue/24/outline"; | ||
import { onMounted, ref } from "vue"; | ||
const loaded = ref(false); | ||
const APP_ID = "7vbAk7"; | ||
const loadScript = async () => { | ||
const script = document.createElement("script"); | ||
script.setAttribute("src", "//cdn.headwayapp.co/widget.js"); | ||
script.addEventListener("load", () => { | ||
loaded.value = true; | ||
initHeadway(); | ||
}); | ||
script.async = true; | ||
document.head.appendChild(script); | ||
}; | ||
function initHeadway() { | ||
const config = { | ||
selector: ".headway", | ||
account: APP_ID, | ||
trigger: "#headway-trigger", | ||
translations: { | ||
title: "Latest updates", | ||
}, | ||
}; | ||
// @ts-expect-error doesn't know about Headway | ||
window.Headway?.init(config); | ||
} | ||
onMounted(async () => { | ||
await loadScript(); | ||
}); | ||
</script> |
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
Oops, something went wrong.