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

feat: v0.2.1 #28

Merged
merged 26 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
84b83df
Add LogSnag integration for tracking user signups
kcoderhtml Apr 29, 2024
157bb97
Add LogSnag integration for tracking successful team creation
kcoderhtml Apr 29, 2024
bdec21c
Add LogSnag integration for tracking event status changes
kcoderhtml Apr 29, 2024
1c33bb3
Add LogSnag integration for tracking message sent events
kcoderhtml Apr 29, 2024
bb452b4
Update LogSnag integration to track user signups with different roles
kcoderhtml Apr 29, 2024
ff8a65e
Refactor LogSnag integration to use consistent event names
kcoderhtml Apr 29, 2024
07ebe73
Add LogSnag integration for tracking reminder events
kcoderhtml Apr 29, 2024
2a95c89
Add LogSnag integration for tracking event create and delete actions
kcoderhtml Apr 29, 2024
2fee640
Add LogSnag integration for tracking role changes in users.astro
kcoderhtml Apr 29, 2024
c153d6d
Merge pull request #24 from kcoderhtml/logsnag
kcoderhtml Apr 29, 2024
68044cb
Update LogSnag integration to track team name updates and deletions
kcoderhtml Apr 29, 2024
2cd629f
Merge pull request #25 from kcoderhtml/logsnag
kcoderhtml Apr 29, 2024
e681c3c
Update LogSnag integration to use environment variable for token
kcoderhtml Apr 29, 2024
de034d4
feat: add allergies as a entry in the user db
kcoderhtml Apr 29, 2024
c666ef6
chore: remove allergies from session
kcoderhtml Apr 29, 2024
cf4bd5b
Refactor settings page to update user information and track changes w…
kcoderhtml Apr 29, 2024
1a57afa
Refactor settings page to remove console.log statement
kcoderhtml Apr 29, 2024
acc9d0f
Merge branch 'main' into allergies
kcoderhtml Apr 29, 2024
5cc2177
Merge pull request #26 from kcoderhtml/allergies
kcoderhtml Apr 29, 2024
4592140
Add event creation on join page
kcoderhtml Apr 29, 2024
61f2d6e
feat: add newuser flag
kcoderhtml Apr 29, 2024
977ae83
Add newuser flag to ExtendedSession type in dashboard.astro
kcoderhtml Apr 29, 2024
eb19329
Add canvas-confetti library for celebratory confetti animation on suc…
kcoderhtml Apr 29, 2024
7aba42d
chore: un comment team creation
kcoderhtml Apr 29, 2024
b41378b
Merge branch 'dev' into new-signup
kcoderhtml Apr 29, 2024
5b041a0
Merge pull request #27 from kcoderhtml/new-signup
kcoderhtml Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 110 additions & 4 deletions auth.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import Slack from "@auth/core/providers/slack";
import { defineConfig } from "auth-astro";
import { db, like, and, User, Organization } from "astro:db";

import { LogSnag } from "logsnag";

const logsnag = new LogSnag({
token: process.env.LOGSNAG_TOKEN || "",
project: "magicsnap",
});

export default defineConfig({
providers: [
Slack({
clientId: import.meta.env.SLACK_CLIENT_ID,
clientSecret: import.meta.env.SLACK_CLIENT_SECRET,
checks: ["pkce", "nonce"],
async profile(profile) {
let newUser = false;
profile["https://slack.com/team_id"] =
"slack-" + profile["https://slack.com/team_id"];

Expand Down Expand Up @@ -49,7 +57,43 @@ export default defineConfig({
role: "admin",
});

role[0] = { role: "admin" };
await logsnag.track({
channel: "signups",
event: "signup",
user_id: profile["https://slack.com/user_id"],
description: "User signed up as an admin",
icon: "🚀",
tags: {
team: profile["https://slack.com/team_id"],
role: "admin",
},
});

await logsnag.track({
channel: "actions",
event: "joined_team",
user_id: profile["https://slack.com/user_id"],
description: "User joined a team",
icon: "🤝",
tags: {
team: profile["https://slack.com/team_id"],
role: "admin",
},
});

await logsnag.identify({
user_id: profile["https://slack.com/user_id"],
properties: {
email: profile.email,
name: profile.name,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "admin",
},
});

role[0].role = "admin";
newUser = true;
} else {
await db.insert(User).values({
userId: profile["https://slack.com/user_id"],
Expand All @@ -60,10 +104,69 @@ export default defineConfig({
role: "user",
});

role[0] = { role: "user" };
await logsnag.track({
channel: "signups",
event: "signup",
user_id: profile["https://slack.com/user_id"],
description: "User signed up as a user",
icon: "🚀",
tags: {
team: profile["https://slack.com/team_id"],
role: "user",
},
});

await logsnag.track({
channel: "actions",
event: "joined_team",
user_id: profile["https://slack.com/user_id"],
description: "User joined a team",
icon: "🤝",
tags: {
team: profile["https://slack.com/team_id"],
role: "user",
},
});

await logsnag.identify({
user_id: profile["https://slack.com/user_id"],
properties: {
email: profile.email,
name: profile.name,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "user",
},
});

role[0].role = "user";
newUser = true;
}
} else {
role[0] = { role: "guest" };
role[0].role = "guest";

await logsnag.track({
channel: "signups",
event: "signup",
user_id: profile["https://slack.com/user_id"],
description: "User signed up as a guest",
icon: "🚀",
tags: {
team: profile["https://slack.com/team_id"],
role: "guest",
},
});

await logsnag.identify({
user_id: profile["https://slack.com/user_id"],
properties: {
email: profile.email,
name: profile.name,
image: profile.picture,
team: profile["https://slack.com/team_id"],
role: "guest",
},
});
}
}

Expand All @@ -75,7 +178,8 @@ export default defineConfig({
team: profile["https://slack.com/team_id"],
teamName: profile["https://slack.com/team_name"],
teamImage: profile["https://slack.com/team_image_230"],
role: role[0].role || "user",
role: role[0].role || "guest",
newUser: newUser,
};
},
}),
Expand All @@ -89,6 +193,7 @@ export default defineConfig({
token.teamImage = user.teamImage;
token.role = user.role;
token.id = user.id;
token.newUser = user.newUser;
}
return token;
},
Expand All @@ -100,6 +205,7 @@ export default defineConfig({
session.teamImage = token.teamImage;
session.user.role = token.role;
session.user.id = token.id;
session.newUser = token.newUser;
}
return session;
},
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions db/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const User = defineTable({
email: column.text(),
image: column.text(),
role: column.text(),
allergies: column.text({ optional: true }),
},
indexes: {
userIdx: { on: ["userId"], unique: true },
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
"@astrojs/node": "^8.2.5",
"@astrojs/tailwind": "^5.1.0",
"@auth/core": "^0.18.6",
"@types/canvas-confetti": "^1.6.4",
"astro": "^4.5.10",
"auth-astro": "^4.1.1",
"canvas-confetti": "^1.9.2",
"jwt-decode": "^4.0.0",
"logsnag": "^1.0.0",
"magick.css": "^1.0.5",
"normalize.css": "^8.0.1",
"prettier": "^3.2.5",
Expand Down
13 changes: 13 additions & 0 deletions src/pages/api/remind.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { APIRoute } from "astro"
import { db, User, Organization, Event } from "astro:db";
import { LogSnag } from "logsnag";

const logsnag = new LogSnag({
token: process.env.LOGSNAG_TOKEN || "",
project: "magicsnap",
});

export const POST: APIRoute = async ({ request }) => {
// get authorization header
Expand All @@ -20,6 +26,13 @@ export const POST: APIRoute = async ({ request }) => {
return diffHours < 24 && diffHours > 0
})

await logsnag.track({
channel: "api",
event: "reminder-sent",
description: `Sent reminder to ${users.length} users in ${organizations.length} different organizations about ${eventsHappeningToday.length} events happening today`,
icon: "📬",
});

return new Response(JSON.stringify({
ok: true, eventsHappeningToday: eventsHappeningToday, users: users, organizations: organizations
}), { status: 200 })
Expand Down
36 changes: 36 additions & 0 deletions src/pages/dashboard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ExtendedSession = {
user: {
role: string;
};
newUser: boolean;
};

const session = (await getSession(Astro.request)) as Session & ExtendedSession;
Expand Down Expand Up @@ -44,6 +45,13 @@ if (!session) {
});
}

import { LogSnag } from "logsnag";

const logsnag = new LogSnag({
token: process.env.LOGSNAG_TOKEN || "",
project: "magicsnap",
});

import { db, Event, User } from "astro:db";
import { like } from "astro:db";

Expand Down Expand Up @@ -102,6 +110,13 @@ if (Astro.request.method === "POST") {
statusNotGoing: statusNotGoing.join(","),
})
.where(like(Event.id, eventID));

await logsnag.track({
channel: "actions",
event: "event_status_change",
icon: "📅",
user_id: session.user.id,
});
}
} else if (data.get("delete") != null) {
if (session.user.role != "admin") {
Expand All @@ -110,6 +125,13 @@ if (Astro.request.method === "POST") {
const eventID = data.get("eventID") as string;

await db.delete(Event).where(like(Event.id, eventID));

await logsnag.track({
channel: "actions",
event: "event_delete",
icon: "📅",
user_id: session.user.id,
});
}
else if (data.get("newEvent") != null) {
if (!data.has("name") || !data.has("date") || !data.has("time") || !data.has("location") || !data.has("comments")) {
Expand All @@ -135,6 +157,13 @@ if (Astro.request.method === "POST") {
.join(","),
};
await db.insert(Event).values(event);

await logsnag.track({
channel: "actions",
event: "event_create",
icon: "📅",
user_id: session.user.id,
});
}
} catch (error) {
if (error instanceof Error) {
Expand Down Expand Up @@ -165,6 +194,13 @@ const users = await db.select().from(User).where(like(User.team, session.team));
} events
</p>
</section>
{
session.newUser && (
<section>
<p>Since you are a new user we recommend that you first fillout your allergies <a href="/settings">here</a> then come back and set your availability!</p>
</section>
)
}
{
session.user.role === "admin" && (
<section>
Expand Down
Loading
Loading