Skip to content

Commit

Permalink
feat: Track core quest status and redesign core quest header (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
evadecker authored Jan 23, 2025
1 parent 24464bb commit 56a570c
Show file tree
Hide file tree
Showing 33 changed files with 639 additions and 206 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-lobsters-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"namesake": minor
---

Display statuses for all core quests
2 changes: 2 additions & 0 deletions convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type * as http from "../http.js";
import type * as passwordReset from "../passwordReset.js";
import type * as quests from "../quests.js";
import type * as seed from "../seed.js";
import type * as userCoreQuests from "../userCoreQuests.js";
import type * as userFormData from "../userFormData.js";
import type * as userQuests from "../userQuests.js";
import type * as userSettings from "../userSettings.js";
Expand All @@ -50,6 +51,7 @@ declare const fullApi: ApiFromModules<{
passwordReset: typeof passwordReset;
quests: typeof quests;
seed: typeof seed;
userCoreQuests: typeof userCoreQuests;
userFormData: typeof userFormData;
userQuests: typeof userQuests;
userSettings: typeof userSettings;
Expand Down
12 changes: 12 additions & 0 deletions convex/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Password } from "@convex-dev/auth/providers/Password";
import { convexAuth } from "@convex-dev/auth/server";
import type { MutationCtx } from "./_generated/server";
import { CORE_QUESTS } from "./constants";
import { ResendOTPPasswordReset } from "./passwordReset";
import { getByEmail } from "./users";

Expand All @@ -26,10 +27,21 @@ export const createOrUpdateUser = async (ctx: MutationCtx, args: any) => {
role: process.env.NODE_ENV === "development" ? "admin" : "user",
})
.then((userId) => {
// Initialize default user settings
ctx.db.insert("userSettings", {
userId,
theme: "system",
});

// Initialize default core quests
for (const quest of Object.keys(CORE_QUESTS)) {
ctx.db.insert("userCoreQuests", {
userId,
type: quest,
status: "notStarted",
});
}

return userId;
});
};
Expand Down
4 changes: 2 additions & 2 deletions convex/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Baby,
Calendar,
CalendarClock,
CalendarDays,
Expand All @@ -10,6 +9,7 @@ import {
Clapperboard,
Clock,
Computer,
FileBadge,
Gamepad2,
Gavel,
Globe,
Expand Down Expand Up @@ -158,7 +158,7 @@ export const CORE_QUESTS: Record<CoreQuest, GroupDetails> = {
},
"birth-certificate": {
label: "Birth Certificate",
icon: Baby,
icon: FileBadge,
},
};

Expand Down
18 changes: 18 additions & 0 deletions convex/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
import {
category,
coreQuest,
jurisdiction,
role,
status,
Expand Down Expand Up @@ -149,6 +150,22 @@ const userSettings = defineTable({
theme: v.optional(theme),
}).index("userId", ["userId"]);

/**
* A user's unique progress in completing a core quest.
*/
const userCoreQuests = defineTable({
/** The user who is working on the quest. */
userId: v.id("users"),
/** The quest that the user is working on, e.g. "court-order", "passport" */
type: coreQuest,
/** The status of the quest. */
status: status,
/** Time in ms since epoch when the user marked the quest as complete. */
completedAt: v.optional(v.number()),
})
.index("userId", ["userId"])
.index("type", ["type"]);

/**
* A user's unique progress in completing a quest.
*/
Expand All @@ -174,5 +191,6 @@ export default defineSchema({
users,
userFormData,
userSettings,
userCoreQuests,
userQuests,
});
Loading

0 comments on commit 56a570c

Please sign in to comment.