From 5961fad55fa4cf91eab72c00ed04eed1e53c9235 Mon Sep 17 00:00:00 2001 From: Oluwatobiloba Promise Temitope Date: Wed, 14 Oct 2026 15:04:00 +0300 Subject: [PATCH 01/17] feat: add bulk move and archive with undo to task service --- src/actions/task/index.ts | 27 ++- src/actions/task/schema.ts | 28 +++ src/core/ports/task.ts | 9 + src/core/services/task.ts | 18 +- src/infra/db/task/repo.ts | 137 ++++++++++++++- tests/integration/taskManagement.test.ts | 213 +++++++++++++++++++++++ 6 files changed, 428 insertions(+), 4 deletions(-) create mode 100644 tests/integration/taskManagement.test.ts diff --git a/src/actions/task/index.ts b/src/actions/task/index.ts index 06f176b..47b986c 100644 --- a/src/actions/task/index.ts +++ b/src/actions/task/index.ts @@ -2,7 +2,14 @@ import { taskService } from "~/infra"; import { action } from "~/lib/action"; -import { archiveTaskSchema, createTaskSchema, updateTaskSchema } from "./schema"; +import { + archiveTaskSchema, + createTaskSchema, + moveTasksSchema, + setTasksArchivedSchema, + undoMoveTasksSchema, + updateTaskSchema, +} from "./schema"; const revalidate = ["/admin/tasks", "/tasks"]; @@ -29,3 +36,21 @@ export const archiveTaskAction = action( }, { revalidate }, ); + +export const moveTasksAction = action( + moveTasksSchema, + async (user, { taskIds, categoryId }) => taskService.moveTasks(user, taskIds, categoryId), + { revalidate }, +); + +export const undoMoveTasksAction = action( + undoMoveTasksSchema, + async (user, { moves }) => taskService.undoMoveTasks(user, moves), + { revalidate }, +); + +export const setTasksArchivedAction = action( + setTasksArchivedSchema, + async (user, { taskIds, archived }) => taskService.setTasksArchived(user, taskIds, archived), + { revalidate }, +); diff --git a/src/actions/task/schema.ts b/src/actions/task/schema.ts index d82e236..f90191a 100644 --- a/src/actions/task/schema.ts +++ b/src/actions/task/schema.ts @@ -25,4 +25,32 @@ export const archiveTaskSchema = z.object({ archived: z.boolean(), }); +const taskIdsSchema = z + .array(z.uuid()) + .min(1, "Select one or more tasks.") + .refine((ids) => new Set(ids).size === ids.length, "Select each task only once."); + +export const moveTasksSchema = z.object({ + taskIds: taskIdsSchema, + categoryId: z.uuid(), +}); + +export const setTasksArchivedSchema = z.object({ + taskIds: taskIdsSchema, + archived: z.boolean(), +}); + +export const undoMoveTasksSchema = z.object({ + moves: z + .array( + z.object({ + taskId: z.uuid(), + fromCategoryId: z.uuid(), + toCategoryId: z.uuid(), + }), + ) + .min(1) + .refine((moves) => new Set(moves.map(({ taskId }) => taskId)).size === moves.length), +}); + export type TaskValues = z.infer; diff --git a/src/core/ports/task.ts b/src/core/ports/task.ts index 35871e3..3907033 100644 --- a/src/core/ports/task.ts +++ b/src/core/ports/task.ts @@ -11,6 +11,12 @@ export interface TaskListItem { readonly takenByAnother: boolean; } +export interface TaskMove { + readonly taskId: string; + readonly fromCategoryId: string; + readonly toCategoryId: string; +} + export interface TaskRepository { listActive(userId: string | null): Promise>; listAll(): Promise< @@ -24,6 +30,9 @@ export interface TaskRepository { create(input: NewTaskInput): Promise; update(id: string, input: NewTaskInput): Promise; setArchived(id: string, archived: boolean): Promise; + moveMany(ids: ReadonlyArray, categoryId: string): Promise>; + undoMoveMany(moves: ReadonlyArray): Promise; + setArchivedMany(ids: ReadonlyArray, archived: boolean): Promise>; } export interface NewTaskInput { diff --git a/src/core/services/task.ts b/src/core/services/task.ts index bbd55b0..ea3d949 100644 --- a/src/core/services/task.ts +++ b/src/core/services/task.ts @@ -2,7 +2,7 @@ import { completionPolicy } from "~/domain/completionPolicy"; import type { TaskPolicy } from "~/domain/task"; import { userCanBrowseTasks, userCanManageTasks } from "~/domain/rules"; import { guard } from "../guard"; -import type { NewTaskInput, TaskRepository } from "../ports/task"; +import type { NewTaskInput, TaskMove, TaskRepository } from "../ports/task"; export interface TaskInput { readonly title: string; @@ -38,6 +38,22 @@ export function createTaskService({ tasks }: Deps) { archiveTask: guard(userCanManageTasks, (_user, taskId: string, archived: boolean) => tasks.setArchived(taskId, archived), ), + + moveTasks: guard( + userCanManageTasks, + (_user, taskIds: ReadonlyArray, categoryId: string) => + tasks.moveMany(taskIds, categoryId), + ), + + undoMoveTasks: guard(userCanManageTasks, (_user, moves: ReadonlyArray) => + tasks.undoMoveMany(moves), + ), + + setTasksArchived: guard( + userCanManageTasks, + (_user, taskIds: ReadonlyArray, archived: boolean) => + tasks.setArchivedMany(taskIds, archived), + ), }; } diff --git a/src/infra/db/task/repo.ts b/src/infra/db/task/repo.ts index 6e8b66c..8096570 100644 --- a/src/infra/db/task/repo.ts +++ b/src/infra/db/task/repo.ts @@ -1,9 +1,10 @@ -import { eq } from "drizzle-orm"; +import { and, eq, inArray, isNotNull, isNull } from "drizzle-orm"; import type { TaskRepository } from "~/core/ports/task"; import { conflict, notFound } from "~/domain/errors"; import { proofs } from "../proof/model"; +import { categories } from "../category/model"; import type { Database } from "../client"; -import { isUniqueViolation } from "../errors"; +import { isForeignKeyViolation, isUniqueViolation } from "../errors"; import { tasks } from "./model"; import { toTask } from "./map"; import { createTaskRead } from "./read"; @@ -69,5 +70,137 @@ export function createTaskRepository(db: Database): TaskRepository { return toTask(row); }, + + async moveMany(ids, categoryId) { + return db.transaction(async (tx) => { + const [category] = await tx + .select({ id: categories.id }) + .from(categories) + .where(eq(categories.id, categoryId)) + .limit(1); + if (category === undefined) { + throw notFound("That category does not exist."); + } + + const existing = await tx + .select({ + id: tasks.id, + categoryId: tasks.categoryId, + }) + .from(tasks) + .where(inArray(tasks.id, ids)) + .orderBy(tasks.id) + .for("update"); + if (existing.length !== ids.length) { + throw notFound("One or more selected tasks do not exist."); + } + + const existingById = new Map(existing.map((task) => [task.id, task])); + const moves = ids.flatMap((id) => { + const task = existingById.get(id); + if (task === undefined || task.categoryId === categoryId) return []; + + return [ + { + taskId: task.id, + fromCategoryId: task.categoryId, + toCategoryId: categoryId, + }, + ]; + }); + if (moves.length > 0) { + await tx + .update(tasks) + .set({ + categoryId, + updatedAt: new Date(), + }) + .where( + inArray( + tasks.id, + moves.map(({ taskId }) => taskId), + ), + ); + } + + return moves; + }); + }, + + async undoMoveMany(moves) { + await db.transaction(async (tx) => { + const ids = moves.map(({ taskId }) => taskId); + const existing = await tx + .select({ + id: tasks.id, + categoryId: tasks.categoryId, + }) + .from(tasks) + .where(inArray(tasks.id, ids)) + .orderBy(tasks.id) + .for("update"); + if (existing.length !== moves.length) { + throw notFound("One or more moved tasks no longer exist; no changes were made."); + } + + const currentCategories = new Map(existing.map(({ id, categoryId }) => [id, categoryId])); + if ( + moves.some(({ taskId, toCategoryId }) => currentCategories.get(taskId) !== toCategoryId) + ) { + throw conflict( + "Some tasks have changed categories since the move; no changes were made.", + ); + } + + const fromCategoryIds = new Set(moves.map(({ fromCategoryId }) => fromCategoryId)); + for (const fromCategoryId of fromCategoryIds) { + const groupIds = moves + .filter((move) => move.fromCategoryId === fromCategoryId) + .map(({ taskId }) => taskId); + try { + await tx + .update(tasks) + .set({ + categoryId: fromCategoryId, + updatedAt: new Date(), + }) + .where(inArray(tasks.id, groupIds)); + } catch (error) { + if (isForeignKeyViolation(error)) { + throw conflict("The original category no longer exists; no changes were made."); + } + throw error; + } + } + }); + }, + + async setArchivedMany(ids, archived) { + return db.transaction(async (tx) => { + const existing = await tx + .select({ id: tasks.id }) + .from(tasks) + .where(inArray(tasks.id, ids)); + if (existing.length !== ids.length) { + throw notFound("One or more selected tasks do not exist."); + } + + const rows = await tx + .update(tasks) + .set({ + archivedAt: archived ? new Date() : null, + updatedAt: new Date(), + }) + .where( + and( + inArray(tasks.id, ids), + archived ? isNull(tasks.archivedAt) : isNotNull(tasks.archivedAt), + ), + ) + .returning({ id: tasks.id }); + + return rows.map(({ id }) => id); + }); + }, }; } diff --git a/tests/integration/taskManagement.test.ts b/tests/integration/taskManagement.test.ts new file mode 100644 index 0000000..49fb383 --- /dev/null +++ b/tests/integration/taskManagement.test.ts @@ -0,0 +1,213 @@ +import { afterAll, beforeEach, describe, expect, it } from "vitest"; +import { moveTasksSchema, setTasksArchivedSchema } from "~/actions/task/schema"; +import { createTaskService } from "~/core/services/task"; +import { createCategoryRepository } from "~/infra/db/category/repo"; +import { createTaskRepository } from "~/infra/db/task/repo"; +import { createUserRepository } from "~/infra/db/user/repo"; +import { connect, seedUsers, truncateAll } from "./helpers"; + +const { client, db } = connect(); +const categories = createCategoryRepository(db); +const tasks = createTaskRepository(db); +const users = createUserRepository(db); +const taskService = createTaskService({ tasks }); + +const taskInput = (categoryId: string, title: string) => ({ + title, + description: "", + categoryId, + points: 5, + policy: "one_per_user" as const, + cooldownSeconds: 0, + photoRequired: false, + photoInstructions: "", +}); + +async function setup() { + const people = await seedUsers(users); + const source = await categories.create({ + name: "Source", + slug: "source", + }); + const destination = await categories.create({ + name: "Destination", + slug: "destination", + }); + const first = await tasks.create({ + ...taskInput(source.id, "First"), + cooldownSeconds: null, + photoInstructions: null, + }); + const second = await tasks.create({ + ...taskInput(source.id, "Second"), + cooldownSeconds: null, + photoInstructions: null, + }); + + return { + ...people, + source, + destination, + first, + second, + }; +} + +afterAll(async () => { + await client.end(); +}); + +beforeEach(async () => { + await truncateAll(db); +}); + +describe("bulk task management", () => { + it("moves every task and treats moving to the same category as a no-op", async () => { + const { admin, source, destination, first, second } = await setup(); + + const moved = await taskService.moveTasks(admin, [first.id, second.id], destination.id); + const beforeNoOp = await tasks.findById(first.id); + const noOpMoves = await taskService.moveTasks(admin, [first.id], destination.id); + + expect(moved).toEqual([ + { + taskId: first.id, + fromCategoryId: source.id, + toCategoryId: destination.id, + }, + { + taskId: second.id, + fromCategoryId: source.id, + toCategoryId: destination.id, + }, + ]); + expect(noOpMoves).toEqual([]); + expect(await tasks.findById(first.id)).toMatchObject({ + categoryId: destination.id, + updatedAt: beforeNoOp?.updatedAt, + }); + expect(await tasks.findById(second.id)).toMatchObject({ categoryId: destination.id }); + }); + + it("undoes a bulk move to each task's original category", async () => { + const { admin, source, destination, first, second } = await setup(); + const otherSource = await categories.create({ + name: "Other source", + slug: "other-source", + }); + await tasks.moveMany([second.id], otherSource.id); + const moves = await taskService.moveTasks(admin, [first.id, second.id], destination.id); + + await taskService.undoMoveTasks(admin, moves); + + expect(await tasks.findById(first.id)).toMatchObject({ categoryId: source.id }); + expect(await tasks.findById(second.id)).toMatchObject({ categoryId: otherSource.id }); + }); + + it("rejects a stale bulk-move undo atomically", async () => { + const { admin, source, destination, first, second } = await setup(); + const moves = await taskService.moveTasks(admin, [first.id, second.id], destination.id); + await tasks.moveMany([second.id], source.id); + + await expect(taskService.undoMoveTasks(admin, moves)).rejects.toMatchObject({ + code: "CONFLICT", + }); + expect(await tasks.findById(first.id)).toMatchObject({ categoryId: destination.id }); + expect(await tasks.findById(second.id)).toMatchObject({ categoryId: source.id }); + }); + + it("archives only newly archived IDs and can reactivate the returned IDs", async () => { + const { admin, first, second } = await setup(); + await tasks.setArchived(second.id, true); + + const archivedIds = await taskService.setTasksArchived(admin, [first.id, second.id], true); + await taskService.setTasksArchived(admin, archivedIds, false); + + expect(archivedIds).toEqual([first.id]); + expect(await tasks.findById(first.id)).toMatchObject({ archivedAt: null }); + const reactivatedTask = await tasks.findById(second.id); + expect(reactivatedTask?.archivedAt).toBeInstanceOf(Date); + }); + + it("rejects duplicate or empty selections at the action boundary", async () => { + const { source, first } = await setup(); + + expect( + moveTasksSchema.safeParse({ + taskIds: [], + categoryId: source.id, + }).success, + ).toBe(false); + expect( + moveTasksSchema.safeParse({ + taskIds: [first.id, first.id], + categoryId: source.id, + }).success, + ).toBe(false); + expect( + setTasksArchivedSchema.safeParse({ + taskIds: ["not-a-uuid"], + archived: true, + }).success, + ).toBe(false); + }); + + it("rejects undo with a conflict when the original category was deleted", async () => { + const { admin, source, destination, first, second } = await setup(); + const moves = await taskService.moveTasks(admin, [first.id, second.id], destination.id); + await categories.delete(source.id); + + await expect(taskService.undoMoveTasks(admin, moves)).rejects.toMatchObject({ + code: "CONFLICT", + }); + expect(await tasks.findById(first.id)).toMatchObject({ categoryId: destination.id }); + }); + + it("rejects missing IDs or categories without partially changing tasks", async () => { + const { admin, source, destination, first, second } = await setup(); + const missingId = "00000000-0000-0000-0000-000000000000"; + + await expect( + taskService.moveTasks(admin, [first.id, missingId], destination.id), + ).rejects.toMatchObject({ code: "NOT_FOUND" }); + await expect( + taskService.moveTasks(admin, [first.id, second.id], missingId), + ).rejects.toMatchObject({ code: "NOT_FOUND" }); + await expect( + taskService.setTasksArchived(admin, [first.id, missingId], true), + ).rejects.toMatchObject({ + code: "NOT_FOUND", + }); + + expect(await tasks.findById(first.id)).toMatchObject({ + categoryId: source.id, + archivedAt: null, + }); + expect(await tasks.findById(second.id)).toMatchObject({ + categoryId: source.id, + archivedAt: null, + }); + }); + + it("rejects bulk task actions from non-managers", async () => { + const { admin, alice, source, destination, first } = await setup(); + + const moves = await taskService.moveTasks(admin, [first.id], destination.id); + await expect(taskService.moveTasks(alice, [first.id], source.id)).rejects.toMatchObject({ + code: "FORBIDDEN", + }); + await expect(taskService.undoMoveTasks(alice, moves)).rejects.toMatchObject({ + code: "FORBIDDEN", + }); + await expect(taskService.setTasksArchived(alice, [first.id], true)).rejects.toMatchObject({ + code: "FORBIDDEN", + }); + await expect(taskService.setTasksArchived(null, [first.id], false)).rejects.toMatchObject({ + code: "UNAUTHENTICATED", + }); + expect(await tasks.findById(first.id)).toMatchObject({ + categoryId: destination.id, + archivedAt: null, + }); + }); +}); From 16c1c4bfd59998932a5c07ddb27cb706ab76ef47 Mon Sep 17 00:00:00 2001 From: Oluwatobiloba Promise Temitope Date: Wed, 14 Oct 2026 15:32:00 +0300 Subject: [PATCH 02/17] feat: open task create and edit in a modal --- src/components/admin/task/createForm.tsx | 42 --------- src/components/admin/task/editForm.tsx | 55 ------------ src/components/admin/task/fields.tsx | 25 +++++- src/components/admin/task/manager.tsx | 34 +++---- .../admin/task/taskEditorDialog.tsx | 88 +++++++++++++++++++ src/components/admin/task/taskForm.tsx | 79 +++++++++++++++++ 6 files changed, 207 insertions(+), 116 deletions(-) delete mode 100644 src/components/admin/task/createForm.tsx delete mode 100644 src/components/admin/task/editForm.tsx create mode 100644 src/components/admin/task/taskEditorDialog.tsx create mode 100644 src/components/admin/task/taskForm.tsx diff --git a/src/components/admin/task/createForm.tsx b/src/components/admin/task/createForm.tsx deleted file mode 100644 index 270c699..0000000 --- a/src/components/admin/task/createForm.tsx +++ /dev/null @@ -1,42 +0,0 @@ -"use client"; - -import type { FC } from "react"; -import { createTaskAction } from "~/actions/task"; -import { createTaskSchema } from "~/actions/task/schema"; -import { useActionForm } from "~/lib/form"; -import { Button } from "../../ui/button"; -import { Card, CardContent } from "../../ui/card"; -import { Form, FormActions, FormError } from "../../ui/form"; -import type { CategoryView } from "./model"; -import { TaskFields, taskValues } from "./fields"; - -interface Props { - categories: Array; - onDone: () => void; -} - -export const CreateTaskForm: FC = ({ categories, onDone }) => { - const { form, submit, pending } = useActionForm(createTaskSchema, createTaskAction, { - defaultValues: { task: taskValues(categories) }, - onSuccess: onDone, - }); - - return ( - - -
- - - - - - - -
-
- ); -}; diff --git a/src/components/admin/task/editForm.tsx b/src/components/admin/task/editForm.tsx deleted file mode 100644 index 1d0be8e..0000000 --- a/src/components/admin/task/editForm.tsx +++ /dev/null @@ -1,55 +0,0 @@ -"use client"; - -import type { FC } from "react"; -import { updateTaskAction } from "~/actions/task"; -import { updateTaskSchema } from "~/actions/task/schema"; -import { useActionForm } from "~/lib/form"; -import { Button } from "../../ui/button"; -import { Card, CardContent } from "../../ui/card"; -import { Form, FormActions, FormError } from "../../ui/form"; -import type { CategoryView, TaskView } from "./model"; -import { TaskFields } from "./fields"; - -interface Props { - task: TaskView; - categories: Array; - onDone: () => void; -} - -export const EditTaskForm: FC = ({ task, categories, onDone }) => { - const { form, submit, pending } = useActionForm(updateTaskSchema, updateTaskAction, { - defaultValues: { - taskId: task.id, - task: { - title: task.title, - description: task.description, - categoryId: task.categoryId, - points: task.points, - policy: task.policy, - cooldownSeconds: task.cooldownSeconds ?? 86_400, - photoRequired: task.photoRequired, - photoInstructions: task.photoInstructions ?? "", - }, - }, - onSuccess: onDone, - }); - - return ( - - -
- - - - - - - -
-
- ); -}; diff --git a/src/components/admin/task/fields.tsx b/src/components/admin/task/fields.tsx index 088dbac..8bbf073 100644 --- a/src/components/admin/task/fields.tsx +++ b/src/components/admin/task/fields.tsx @@ -8,10 +8,10 @@ import { taskPolicies } from "~/domain/task"; import { describeTaskPolicy } from "~/lib/taskLabels"; import { Field } from "../../ui/form"; import { Checkbox, Input, Select, Textarea } from "../../ui/formControls"; -import type { CategoryView } from "./model"; +import type { CategoryView, TaskView } from "./model"; interface Props { - categories: Array; + readonly categories: Array; } export const TaskFields: FC = ({ categories }) => { @@ -80,11 +80,28 @@ export const TaskFields: FC = ({ categories }) => { ); }; -export function taskValues(categories: Array): TaskValues { +export function taskValues( + categories: Array, + task?: TaskView, + categoryId?: string, +): TaskValues { + if (task) { + return { + title: task.title, + description: task.description, + categoryId: task.categoryId, + points: task.points, + policy: task.policy, + cooldownSeconds: task.cooldownSeconds ?? 86_400, + photoRequired: task.photoRequired, + photoInstructions: task.photoInstructions ?? "", + }; + } + return { title: "", description: "", - categoryId: categories[0]?.id ?? "", + categoryId: categoryId ?? categories[0]?.id ?? "", points: 5, policy: "one_per_user", cooldownSeconds: 86_400, diff --git a/src/components/admin/task/manager.tsx b/src/components/admin/task/manager.tsx index 1e7afd8..4fd8621 100644 --- a/src/components/admin/task/manager.tsx +++ b/src/components/admin/task/manager.tsx @@ -6,23 +6,17 @@ import { Button } from "../../ui/button"; import { EmptyState, Notice } from "../../ui/feedback"; import { Page } from "../../ui/page"; import type { CategoryView, TaskView } from "./model"; -import { CreateTaskForm } from "./createForm"; -import { EditTaskForm } from "./editForm"; import { TaskRow } from "./row"; +import { type TaskDialog, TaskEditorDialog } from "./taskEditorDialog"; interface Props { tasks: Array; categories: Array; } -type Editing = TaskView | "new" | null; - export const TaskManager: FC = ({ tasks, categories }) => { - const [editing, setEditing] = useState(null); + const [dialog, setDialog] = useState(null); const hasCategories = categories.length > 0; - const close = () => { - setEditing(null); - }; return ( = ({ tasks, categories }) => { + +
+ {dialog?.kind === "edit" && !task ? ( + + ) : ( + dialog && ( + + ) + )} +
+ + + ); +}; diff --git a/src/components/admin/task/taskForm.tsx b/src/components/admin/task/taskForm.tsx new file mode 100644 index 0000000..62885a7 --- /dev/null +++ b/src/components/admin/task/taskForm.tsx @@ -0,0 +1,79 @@ +"use client"; + +import { type FC, useEffect } from "react"; +import { createTaskAction, updateTaskAction } from "~/actions/task"; +import { createTaskSchema } from "~/actions/task/schema"; +import { useActionForm } from "~/lib/form"; +import { Button } from "../../ui/button"; +import { Form, FormActions, FormError } from "../../ui/form"; +import type { CategoryView, TaskView } from "./model"; +import { TaskFields, taskValues } from "./fields"; + +interface Props { + readonly categories: Array; + readonly task: TaskView | undefined; + readonly categoryId: string | undefined; + readonly onDone: () => void; + readonly onCancel: () => void; + readonly onDirtyChange: (dirty: boolean) => void; + readonly onPendingChange: (pending: boolean) => void; +} + +export const TaskForm: FC = ({ + categories, + task, + categoryId, + onDone, + onCancel, + onDirtyChange, + onPendingChange, +}) => { + const { form, submit, pending } = useActionForm( + createTaskSchema, + (values) => + task + ? updateTaskAction({ + taskId: task.id, + ...values, + }) + : createTaskAction(values), + { + defaultValues: { task: taskValues(categories, task, categoryId) }, + onSuccess: onDone, + }, + ); + + useEffect(() => { + onDirtyChange(form.formState.isDirty); + }, [form.formState.isDirty, onDirtyChange]); + useEffect(() => { + onPendingChange(pending); + }, [onPendingChange, pending]); + + let submitLabel = task ? "Save changes" : "Create task"; + if (pending) submitLabel = task ? "Saving…" : "Creating…"; + + return ( +
+
+ + +
+ + + + +
+ ); +}; From 0187238705c46860c850e5acde50c5d6706aafa9 Mon Sep 17 00:00:00 2001 From: Oluwatobiloba Promise Temitope Date: Wed, 14 Oct 2026 16:25:00 +0300 Subject: [PATCH 03/17] feat: add accordion, checkbox and selectable accordion ui primitives --- package.json | 2 + pnpm-lock.yaml | 248 ++++++++++++++++++++++ src/components/ui/accordion.tsx | 54 +++++ src/components/ui/checkbox.tsx | 23 ++ src/components/ui/selectableAccordion.tsx | 125 +++++++++++ 5 files changed, 452 insertions(+) create mode 100644 src/components/ui/accordion.tsx create mode 100644 src/components/ui/checkbox.tsx create mode 100644 src/components/ui/selectableAccordion.tsx diff --git a/package.json b/package.json index f664928..d8ce21b 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,9 @@ "@aws-sdk/s3-request-presigner": "^3.1134.0", "@date-fns/tz": "^1.5.0", "@hookform/resolvers": "^5.9.1", + "@radix-ui/react-accordion": "^1.3.1", "@radix-ui/react-avatar": "^1.2.6", + "@radix-ui/react-checkbox": "^1.4.1", "@radix-ui/react-dialog": "^1.1.23", "@radix-ui/react-label": "^2.1.15", "@radix-ui/react-popover": "^1.1.23", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6cd2c6d..88c97ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,9 +20,15 @@ importers: '@hookform/resolvers': specifier: ^5.9.1 version: 5.9.1(@standard-schema/spec@1.1.0)(ajv-formats@2.1.1(ajv@8.20.0))(ajv@8.20.0)(arktype@2.2.3)(react-hook-form@7.88.0(react@19.3.0))(zod@4.6.5) + '@radix-ui/react-accordion': + specifier: ^1.3.1 + version: 1.3.1(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) '@radix-ui/react-avatar': specifier: ^1.2.6 version: 1.2.6(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) + '@radix-ui/react-checkbox': + specifier: ^1.4.1 + version: 1.4.1(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) '@radix-ui/react-dialog': specifier: ^1.1.23 version: 1.1.23(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) @@ -1326,6 +1332,22 @@ packages: '@radix-ui/primitive@1.1.7': resolution: {integrity: sha512-rqWnm76nYT8HoNNqEjpgJ7Pw/DrBj5iBTrmEPo6HTX5+VJyBNOqTdv4g89G63HuR5g0AaENoAcH7Is5fF2kZ8Q==} + '@radix-ui/primitive@1.2.0': + resolution: {integrity: sha512-KABY+VMIRPJL+Vyzv/335FEhXXD/xDv8BMb1kl48/aXJZMH0LtHCTx5ga5RnxaEP3nZHtmTLf1P9vanmFX46bw==} + + '@radix-ui/react-accordion@1.3.1': + resolution: {integrity: sha512-lCZ6sbGS/7WO0j84yx4srIgOf0MRJ/sZ13RonADXxvKBym8xrxNCq5f6DibGcr38sIlwPk8/52uYdXeOPsbEDw==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + '@radix-ui/react-arrow@1.1.15': resolution: {integrity: sha512-v4zggRcjadnI+ClKDuijlQEW4tw3NoaeHc/PwpKnLoLLKNUG4InLegkstooLcRIUWCs+8L22dGURCVuFfOKfnA==} peerDependencies: @@ -1352,6 +1374,32 @@ packages: '@types/react-dom': optional: true + '@radix-ui/react-checkbox@1.4.1': + resolution: {integrity: sha512-KWtwhh+98ML3seZ9vO9yRY2OwaQG90dCiDAxjpSNY2AaZ3Hik3B0dsk6m0ILywo/no3A9/SozadyPMNweVT8yw==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + + '@radix-ui/react-collapsible@1.2.1': + resolution: {integrity: sha512-fSzLb/qy1wuZSxQBcxpW0hNXYHDMWiIXDGyJGdA4+FSLknOWZsNRrTCUavxb4PI8b8lvHo/CysO6NVi5zLpo5g==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + '@radix-ui/react-collection@1.1.15': resolution: {integrity: sha512-9W+B9NPF0NaaPh/1NJd3+KqsnlLqU9H7T2rvww+fp+T/evVXdNAyYcnfRQZFOjkR1ajQp3yORlqnI8soawLvNA==} peerDependencies: @@ -1365,6 +1413,19 @@ packages: '@types/react-dom': optional: true + '@radix-ui/react-collection@1.2.0': + resolution: {integrity: sha512-+yiQzqcc7Sy7/5s0jrMCjpPRFB3538VNrXPWdTLZhE/SCfgEws4aI6lHWN/vvcnyhHndROWBzqmqB4QBrITZ9Q==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + '@radix-ui/react-compose-refs@1.1.5': resolution: {integrity: sha512-+48PbAAbq3didjJxa+OaWY2ZwgAKsNiRGyeHKszblZMQ+kcpd9pAaT11cMkGEie0vsOi3QdeTE6d5Fe3Gn61kA==} peerDependencies: @@ -1383,6 +1444,15 @@ packages: '@types/react': optional: true + '@radix-ui/react-context@1.3.0': + resolution: {integrity: sha512-v5AYEocMISkbJ+1fTXzZpiFv7NRr3D2WiYbLIKf+FkmJ8VkP6d503eV2n34MFussHXY1pcoq3yfJiQH77dc4Mg==} + peerDependencies: + '@types/react': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@radix-ui/react-dialog@1.1.23': resolution: {integrity: sha512-Ksw4WeROkO4rC9k/onilX/Ao2Cr1ku1unMNH+XSCcP4jSXYu7HDsg9n4ojMjVb22XpYjAQ9qfrFlVbru1vXDUA==} peerDependencies: @@ -1405,6 +1475,15 @@ packages: '@types/react': optional: true + '@radix-ui/react-direction@1.2.0': + resolution: {integrity: sha512-FtRA52a/r+LKStFT+neLUm+8vSe7wbzkbQGGeU8ixFiwC8NU14Evoq9ATECqL3eGbcUzJR4fyfA4KkK/q6dfqg==} + peerDependencies: + '@types/react': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@radix-ui/react-dismissable-layer@1.1.19': resolution: {integrity: sha512-8g4pfOL9HoKKLWGiypT+dphVqjFfmcXO5GBnhsG6zI+lxAx/8feQpr+1LSN8Re3hiZ+XkLNS4O9ztK11/LzQ6w==} peerDependencies: @@ -1514,6 +1593,19 @@ packages: '@types/react-dom': optional: true + '@radix-ui/react-presence@1.1.11': + resolution: {integrity: sha512-Z7/atlkab36Z8hm+V8zYc79r0W+tiOB1o0tun1By94JyadkekLQmtEAnBSP9XKXBNQsStoStS4+gX10JpS5akA==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + '@radix-ui/react-primitive@2.1.10': resolution: {integrity: sha512-MucOnzh6hR5mid6VpkbglRAMYMjKLqRnGBbjXkzjK52fuQDd1qbkx78a5P40mkcnVXJdEVxm26E9OPAiUq7nBg==} peerDependencies: @@ -1527,6 +1619,19 @@ packages: '@types/react-dom': optional: true + '@radix-ui/react-primitive@2.2.0': + resolution: {integrity: sha512-HCTSPMNqv55Qk0IX4geJbpyXazmqulcimwuyjxTkKi29v+QZbG2Zho9BnbBq4YS2PF+KlNb2CXoLz66uUmblkg==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + '@radix-ui/react-roving-focus@1.1.19': resolution: {integrity: sha512-V9jI6hDjT7l3jsCQD9bLNvDLM3tH/gdbOTp7Tefp3hbbgCGQoK7tUvrWiRlcoBHIZ809ElXwNQwVo0B98LuTXQ==} peerDependencies: @@ -1562,6 +1667,15 @@ packages: '@types/react': optional: true + '@radix-ui/react-slot@1.5.0': + resolution: {integrity: sha512-tyYd9ddPXAysAbdbD9eYxgwpCSv6f3PncqVSNKQFSR5lcJVLz3cb/pANDoYrLiHBpXv7skortyUgGUWsYuPPFQ==} + peerDependencies: + '@types/react': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@radix-ui/react-switch@1.3.7': resolution: {integrity: sha512-48tB/4dn2UVLBCYhTu9AuR63IHl73l/qLbLgxd86noTUor4/K4LFDAcYjK+isP5313qxaFpjPVogE7+Y0/V3Kw==} peerDependencies: @@ -1606,6 +1720,15 @@ packages: '@types/react': optional: true + '@radix-ui/react-use-controllable-state@1.3.0': + resolution: {integrity: sha512-TAcBI7bw2ljYCbv4+zuTSd6zICu8pRt6SDN2vJ/Z06K2MXh6I9WYFe/A9ovlFDtR5HVHGm5iDxDoABm/++dbKg==} + peerDependencies: + '@types/react': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@radix-ui/react-use-effect-event@0.0.5': resolution: {integrity: sha512-7cshFL8HGS/7HEiHH+9kL9HBwp2sa9yX18Knwek6KYWmXwM7pegMgta2AXMQKI+rq3JnfSj9x8wYqFMTdG1Jgg==} peerDependencies: @@ -1660,6 +1783,15 @@ packages: '@types/react': optional: true + '@radix-ui/react-use-size@1.1.5': + resolution: {integrity: sha512-V1McDQkMGzgivwqdu7u96APs7oi0Jvj9LTzgq3WWrDZqxWdAqU9yZnZQqk5OizGFR8badUQwZsrlao7MOlWYOA==} + peerDependencies: + '@types/react': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@radix-ui/react-visually-hidden@1.2.11': resolution: {integrity: sha512-NFS86RYYZb4/exihaESBGOpMJFz8MGLAfu3mOBSGByVnVPC9JPASfYubxd/8KbkQK0sYAv8lVQDEQukDX/qXvQ==} peerDependencies: @@ -6061,6 +6193,25 @@ snapshots: '@radix-ui/primitive@1.1.7': {} + '@radix-ui/primitive@1.2.0': {} + + '@radix-ui/react-accordion@1.3.1(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': + dependencies: + '@radix-ui/primitive': 1.2.0 + '@radix-ui/react-collapsible': 1.2.1(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) + '@radix-ui/react-collection': 1.2.0(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) + '@radix-ui/react-compose-refs': 1.1.5(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-context': 1.3.0(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-direction': 1.2.0(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-id': 1.1.4(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-primitive': 2.2.0(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) + '@radix-ui/react-use-controllable-state': 1.3.0(@types/react@19.3.0)(react@19.3.0) + react: 19.3.0 + react-dom: 19.3.0(react@19.3.0) + optionalDependencies: + '@types/react': 19.3.0 + '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@radix-ui/react-arrow@1.1.15(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': dependencies: '@radix-ui/react-primitive': 2.1.10(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) @@ -6084,6 +6235,37 @@ snapshots: '@types/react': 19.3.0 '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@radix-ui/react-checkbox@1.4.1(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': + dependencies: + '@radix-ui/primitive': 1.2.0 + '@radix-ui/react-compose-refs': 1.1.5(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-context': 1.3.0(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-presence': 1.1.11(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) + '@radix-ui/react-primitive': 2.2.0(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) + '@radix-ui/react-use-controllable-state': 1.3.0(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-use-size': 1.1.5(@types/react@19.3.0)(react@19.3.0) + react: 19.3.0 + react-dom: 19.3.0(react@19.3.0) + optionalDependencies: + '@types/react': 19.3.0 + '@types/react-dom': 19.3.0(@types/react@19.3.0) + + '@radix-ui/react-collapsible@1.2.1(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': + dependencies: + '@radix-ui/primitive': 1.2.0 + '@radix-ui/react-compose-refs': 1.1.5(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-context': 1.3.0(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-id': 1.1.4(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-presence': 1.1.11(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) + '@radix-ui/react-primitive': 2.2.0(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) + '@radix-ui/react-use-controllable-state': 1.3.0(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-use-layout-effect': 1.1.4(@types/react@19.3.0)(react@19.3.0) + react: 19.3.0 + react-dom: 19.3.0(react@19.3.0) + optionalDependencies: + '@types/react': 19.3.0 + '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@radix-ui/react-collection@1.1.15(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': dependencies: '@radix-ui/react-compose-refs': 1.1.5(@types/react@19.3.0)(react@19.3.0) @@ -6096,6 +6278,19 @@ snapshots: '@types/react': 19.3.0 '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@radix-ui/react-collection@1.2.0(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': + dependencies: + '@radix-ui/react-compose-refs': 1.1.5(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-context': 1.3.0(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-primitive': 2.2.0(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) + '@radix-ui/react-slot': 1.5.0(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-use-layout-effect': 1.1.4(@types/react@19.3.0)(react@19.3.0) + react: 19.3.0 + react-dom: 19.3.0(react@19.3.0) + optionalDependencies: + '@types/react': 19.3.0 + '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@radix-ui/react-compose-refs@1.1.5(@types/react@19.3.0)(react@19.3.0)': dependencies: react: 19.3.0 @@ -6108,6 +6303,12 @@ snapshots: optionalDependencies: '@types/react': 19.3.0 + '@radix-ui/react-context@1.3.0(@types/react@19.3.0)(react@19.3.0)': + dependencies: + react: 19.3.0 + optionalDependencies: + '@types/react': 19.3.0 + '@radix-ui/react-dialog@1.1.23(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': dependencies: '@radix-ui/primitive': 1.1.7 @@ -6137,6 +6338,12 @@ snapshots: optionalDependencies: '@types/react': 19.3.0 + '@radix-ui/react-direction@1.2.0(@types/react@19.3.0)(react@19.3.0)': + dependencies: + react: 19.3.0 + optionalDependencies: + '@types/react': 19.3.0 + '@radix-ui/react-dismissable-layer@1.1.19(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': dependencies: '@radix-ui/primitive': 1.1.7 @@ -6243,6 +6450,15 @@ snapshots: '@types/react': 19.3.0 '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@radix-ui/react-presence@1.1.11(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': + dependencies: + '@radix-ui/react-use-layout-effect': 1.1.4(@types/react@19.3.0)(react@19.3.0) + react: 19.3.0 + react-dom: 19.3.0(react@19.3.0) + optionalDependencies: + '@types/react': 19.3.0 + '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@radix-ui/react-primitive@2.1.10(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': dependencies: '@radix-ui/react-slot': 1.3.3(@types/react@19.3.0)(react@19.3.0) @@ -6252,6 +6468,15 @@ snapshots: '@types/react': 19.3.0 '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@radix-ui/react-primitive@2.2.0(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': + dependencies: + '@radix-ui/react-slot': 1.5.0(@types/react@19.3.0)(react@19.3.0) + react: 19.3.0 + react-dom: 19.3.0(react@19.3.0) + optionalDependencies: + '@types/react': 19.3.0 + '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@radix-ui/react-roving-focus@1.1.19(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': dependencies: '@radix-ui/primitive': 1.1.7 @@ -6308,6 +6533,13 @@ snapshots: optionalDependencies: '@types/react': 19.3.0 + '@radix-ui/react-slot@1.5.0(@types/react@19.3.0)(react@19.3.0)': + dependencies: + '@radix-ui/react-compose-refs': 1.1.5(@types/react@19.3.0)(react@19.3.0) + react: 19.3.0 + optionalDependencies: + '@types/react': 19.3.0 + '@radix-ui/react-switch@1.3.7(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': dependencies: '@radix-ui/primitive': 1.1.7 @@ -6353,6 +6585,15 @@ snapshots: optionalDependencies: '@types/react': 19.3.0 + '@radix-ui/react-use-controllable-state@1.3.0(@types/react@19.3.0)(react@19.3.0)': + dependencies: + '@radix-ui/primitive': 1.2.0 + '@radix-ui/react-use-effect-event': 0.0.5(@types/react@19.3.0)(react@19.3.0) + '@radix-ui/react-use-layout-effect': 1.1.4(@types/react@19.3.0)(react@19.3.0) + react: 19.3.0 + optionalDependencies: + '@types/react': 19.3.0 + '@radix-ui/react-use-effect-event@0.0.5(@types/react@19.3.0)(react@19.3.0)': dependencies: '@radix-ui/react-use-layout-effect': 1.1.4(@types/react@19.3.0)(react@19.3.0) @@ -6392,6 +6633,13 @@ snapshots: optionalDependencies: '@types/react': 19.3.0 + '@radix-ui/react-use-size@1.1.5(@types/react@19.3.0)(react@19.3.0)': + dependencies: + '@radix-ui/react-use-layout-effect': 1.1.4(@types/react@19.3.0)(react@19.3.0) + react: 19.3.0 + optionalDependencies: + '@types/react': 19.3.0 + '@radix-ui/react-visually-hidden@1.2.11(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)': dependencies: '@radix-ui/react-primitive': 2.1.10(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) diff --git a/src/components/ui/accordion.tsx b/src/components/ui/accordion.tsx new file mode 100644 index 0000000..708a9e4 --- /dev/null +++ b/src/components/ui/accordion.tsx @@ -0,0 +1,54 @@ +"use client"; + +import * as AccordionPrimitive from "@radix-ui/react-accordion"; +import { ChevronDown } from "lucide-react"; +import type { ComponentProps } from "react"; +import { cn } from "~/lib/utils"; + +export const Accordion = AccordionPrimitive.Root; + +export function AccordionItem({ + className, + ...props +}: ComponentProps) { + return ; +} + +export function AccordionTrigger({ + className, + children, + heading: Heading = "h3", + ...props +}: ComponentProps & { readonly heading?: "h2" | "h3" }) { + return ( + + + svg]:rotate-180", + className, + )} + {...props} + > + {children} + + + + + ); +} + +export function AccordionContent({ + className, + children, + ...props +}: ComponentProps) { + return ( + +
{children}
+
+ ); +} diff --git a/src/components/ui/checkbox.tsx b/src/components/ui/checkbox.tsx new file mode 100644 index 0000000..2a1e0d5 --- /dev/null +++ b/src/components/ui/checkbox.tsx @@ -0,0 +1,23 @@ +"use client"; + +import * as CheckboxPrimitive from "@radix-ui/react-checkbox"; +import { Check, Minus } from "lucide-react"; +import type { ComponentProps } from "react"; +import { cn } from "~/lib/utils"; + +export function Checkbox({ className, ...props }: ComponentProps) { + return ( + + + + + + + ); +} diff --git a/src/components/ui/selectableAccordion.tsx b/src/components/ui/selectableAccordion.tsx new file mode 100644 index 0000000..2b0c7cf --- /dev/null +++ b/src/components/ui/selectableAccordion.tsx @@ -0,0 +1,125 @@ +"use client"; + +import { X } from "lucide-react"; +import { type ReactNode, useState } from "react"; +import { AccordionContent, AccordionItem, AccordionTrigger } from "./accordion"; +import { Button } from "./button"; +import { Checkbox } from "./checkbox"; +import { cn } from "~/lib/utils"; + +interface Props { + readonly value: string; + readonly id?: string; + readonly title: ReactNode; + readonly label: string; + readonly items: ReadonlyArray; + readonly itemLabel: (item: Item) => string; + readonly renderItem: (item: Item) => ReactNode; + readonly actions: (selected: Array, clear: () => void) => ReactNode; + readonly headerAction?: ReactNode; + readonly empty?: ReactNode; + readonly className?: string; +} + +export function SelectableAccordion({ + value, + id, + title, + label, + items, + itemLabel, + renderItem, + actions, + headerAction, + empty, + className, +}: Props) { + const [selectedIds, setSelectedIds] = useState>(() => new Set()); + // Ids of items that left the list (moved, archived, filtered out) are ignored, not kept. + const selected = items.filter((item) => selectedIds.has(item.id)); + const clear = () => { + setSelectedIds(new Set()); + }; + const toggle = (itemId: string, checked: boolean) => { + const next = new Set(selected.map((item) => item.id)); + if (checked) next.add(itemId); + else next.delete(itemId); + setSelectedIds(next); + }; + + let allState: boolean | "indeterminate" = false; + if (selected.length > 0) allState = selected.length === items.length ? true : "indeterminate"; + + return ( + +
+ { + setSelectedIds(checked === true ? new Set(items.map((item) => item.id)) : new Set()); + }} + /> + + {title} + + {headerAction} +
+ + {selected.length > 0 && ( +
+ {selected.length} selected + {actions(selected, clear)} + +
+ )} + {items.length === 0 ? ( +
{empty}
+ ) : ( +
    + {items.map((item) => ( +
  • + { + toggle(item.id, checked === true); + }} + /> + {renderItem(item)} +
  • + ))} +
+ )} +
+
+ ); +} From 459b3b1f5cc3c88e7246170df203a5fbe9360ce8 Mon Sep 17 00:00:00 2001 From: Oluwatobiloba Promise Temitope Date: Wed, 14 Oct 2026 23:20:00 +0300 Subject: [PATCH 04/17] feat: group admin tasks into selectable category accordions --- src/components/admin/task/bulkActions.tsx | 177 ++++++++++++++++ src/components/admin/task/manager.tsx | 118 +++++------ src/components/admin/task/model.ts | 1 + src/components/admin/task/row.tsx | 112 ++++++---- src/components/admin/task/workspaceState.ts | 33 +++ src/components/admin/task/workspaceView.tsx | 220 ++++++++++++++++++++ tests/components/taskWorkspace.test.ts | 77 +++++++ 7 files changed, 634 insertions(+), 104 deletions(-) create mode 100644 src/components/admin/task/bulkActions.tsx create mode 100644 src/components/admin/task/workspaceState.ts create mode 100644 src/components/admin/task/workspaceView.tsx create mode 100644 tests/components/taskWorkspace.test.ts diff --git a/src/components/admin/task/bulkActions.tsx b/src/components/admin/task/bulkActions.tsx new file mode 100644 index 0000000..95af26f --- /dev/null +++ b/src/components/admin/task/bulkActions.tsx @@ -0,0 +1,177 @@ +"use client"; + +import { Archive, ArchiveRestore, FolderInput, LoaderCircle, type LucideIcon } from "lucide-react"; +import { useState } from "react"; +import { toast } from "sonner"; +import { moveTasksAction, setTasksArchivedAction, undoMoveTasksAction } from "~/actions/task"; +import type { ActionResult } from "~/lib/action"; +import { useAction } from "~/lib/form"; +import { Button } from "../../ui/button"; +import { ErrorState } from "../../ui/feedback"; +import { Select } from "../../ui/formControls"; +import type { CategoryView, TaskView } from "./model"; + +interface Props { + readonly tasks: Array; + readonly categories: Array; + readonly categoryId: string; + readonly onDone: () => void; +} + +const count = (n: number) => `${n} ${n === 1 ? "task" : "tasks"}`; + +export function undoToast( + message: string, + undo: () => Promise>, + undone: string, +) { + toast(message, { + duration: 10_000, + action: { + label: "Undo", + onClick: () => { + undo().then( + (result) => { + if (result.ok) toast.success(undone); + else toast.error(result.error); + }, + () => { + toast.error("Could not undo. Please refresh and try again."); + }, + ); + }, + }, + }); +} + +function BusyIcon({ icon: Icon, busy }: { readonly icon: LucideIcon; readonly busy: boolean }) { + return busy ? ( + + ) : ( + + ); +} + +export function TaskBulkActions({ tasks, categories, categoryId, onDone }: Props) { + const [destinationId, setDestinationId] = useState(""); + const activeIds = tasks.filter(({ archived }) => !archived).map(({ id }) => id); + const archivedIds = tasks.filter(({ archived }) => archived).map(({ id }) => id); + + const move = useAction(moveTasksAction, { + onSuccess: (moves) => { + onDone(); + if (moves.length === 0) return; + undoToast( + `Moved ${count(moves.length)}.`, + () => undoMoveTasksAction({ moves }), + `Moved ${count(moves.length)} back.`, + ); + }, + }); + const archive = useAction(setTasksArchivedAction, { + onSuccess: (changedIds) => { + onDone(); + if (changedIds.length === 0) return; + undoToast( + `Archived ${count(changedIds.length)}.`, + () => + setTasksArchivedAction({ + taskIds: changedIds, + archived: false, + }), + `Reactivated ${count(changedIds.length)}.`, + ); + }, + }); + const reactivate = useAction(setTasksArchivedAction, { + onSuccess: (changedIds) => { + onDone(); + if (changedIds.length > 0) toast.success(`Reactivated ${count(changedIds.length)}.`); + }, + }); + const pending = move.pending || archive.pending || reactivate.pending; + const error = move.error ?? archive.error ?? reactivate.error; + + return ( + <> + + + + {activeIds.length > 0 && ( + + )} + {archivedIds.length > 0 && ( + + )} + {error && ( +
+ +
+ )} + + ); +} diff --git a/src/components/admin/task/manager.tsx b/src/components/admin/task/manager.tsx index 4fd8621..72726ce 100644 --- a/src/components/admin/task/manager.tsx +++ b/src/components/admin/task/manager.tsx @@ -1,83 +1,79 @@ "use client"; -import Link from "next/link"; -import { type FC, useState } from "react"; -import { Button } from "../../ui/button"; -import { EmptyState, Notice } from "../../ui/feedback"; -import { Page } from "../../ui/page"; +import { useSearchParams } from "next/navigation"; +import { type FC, useEffect, useMemo, useState } from "react"; import type { CategoryView, TaskView } from "./model"; -import { TaskRow } from "./row"; import { type TaskDialog, TaskEditorDialog } from "./taskEditorDialog"; +import { TaskWorkspaceView } from "./workspaceView"; +import { groupWorkspaceTasks } from "./workspaceState"; interface Props { - tasks: Array; - categories: Array; + readonly tasks: Array; + readonly categories: Array; } export const TaskManager: FC = ({ tasks, categories }) => { + const searchParams = useSearchParams(); + const [search, setSearch] = useState(() => searchParams.get("search") ?? ""); + const [showArchived, setShowArchived] = useState(() => searchParams.get("archived") === "1"); const [dialog, setDialog] = useState(null); - const hasCategories = categories.length > 0; - - return ( - - - - - } - > - {!hasCategories && ( - - Every task needs a category.{" "} - - Create one first. - - - )} + const groups = useMemo( + () => groupWorkspaceTasks(tasks, categories, search, showArchived), + [categories, tasks, search, showArchived], + ); + const archivedCount = tasks.filter((task) => task.archived).length; + const editedTask = + dialog?.kind === "edit" ? tasks.find(({ id }) => id === dialog.taskId) : undefined; - {tasks.length === 0 && ( - - )} + // Native replaceState keeps the URL shareable without a server round trip (Next syncs it with useSearchParams). + useEffect(() => { + const timer = setTimeout(() => { + const url = new URL(window.location.href); + if (search) url.searchParams.set("search", search); + else url.searchParams.delete("search"); + if (showArchived) url.searchParams.set("archived", "1"); + else url.searchParams.delete("archived"); + window.history.replaceState(null, "", url); + }, 300); -
    - {tasks.map((task) => ( -
  • - { - setDialog({ - kind: "edit", - taskId: task.id, - }); - }} - /> -
  • - ))} -
+ return () => { + clearTimeout(timer); + }; + }, [search, showArchived]); + return ( + <> + { + setShowArchived((current) => !current); + }} + onCreate={(categoryId) => { + setDialog({ + kind: "create", + categoryId, + }); + }} + onEdit={(task) => { + setDialog({ + kind: "edit", + taskId: task.id, + }); + }} + /> id === dialog.taskId) : undefined} + task={editedTask} categories={categories} onClose={() => { setDialog(null); }} /> -
+ ); }; diff --git a/src/components/admin/task/model.ts b/src/components/admin/task/model.ts index dcd8175..b6eadef 100644 --- a/src/components/admin/task/model.ts +++ b/src/components/admin/task/model.ts @@ -17,4 +17,5 @@ export interface TaskView { export interface CategoryView { id: string; name: string; + slug: string; } diff --git a/src/components/admin/task/row.tsx b/src/components/admin/task/row.tsx index 6caf6a7..aef3b21 100644 --- a/src/components/admin/task/row.tsx +++ b/src/components/admin/task/row.tsx @@ -1,5 +1,6 @@ "use client"; +import { Archive, ArchiveRestore, Camera, LoaderCircle } from "lucide-react"; import type { FC } from "react"; import { archiveTaskAction } from "~/actions/task"; import { useAction } from "~/lib/form"; @@ -7,58 +8,83 @@ import { describeTaskPolicy } from "~/lib/taskLabels"; import { cn } from "~/lib/utils"; import { Badge } from "../../ui/badge"; import { Button } from "../../ui/button"; -import { Card, CardContent } from "../../ui/card"; import { ErrorState } from "../../ui/feedback"; +import { undoToast } from "./bulkActions"; import type { TaskView } from "./model"; interface Props { - task: TaskView; - onEdit: () => void; + readonly task: TaskView; + readonly onEdit: () => void; } export const TaskRow: FC = ({ task, onEdit }) => { - const archive = useAction(archiveTaskAction); + const archive = useAction(archiveTaskAction, { + onSuccess: (_data, { archived }) => { + if (!archived) return; + undoToast( + `Archived "${task.title}".`, + () => + archiveTaskAction({ + taskId: task.id, + archived: false, + }), + `Reactivated "${task.title}".`, + ); + }, + }); + const archiveLabel = `${task.archived ? "Reactivate" : "Archive"} ${task.title}`; + let ArchiveIcon = task.archived ? ArchiveRestore : Archive; + if (archive.pending) ArchiveIcon = LoaderCircle; return ( - - -
-
-

{task.title}

-

- {task.categoryName} · {describeTaskPolicy(task.policy)} -

-
- {task.photoRequired && Photo required} - {task.archived && Archived} -
-
- - {task.points} pts - -
- - {archive.error && } - -
- - -
-
-
+ {task.title} + + + {task.photoRequired && ( + + + Photo required + + )} + {task.archived && Archived} + {describeTaskPolicy(task.policy)} + + {task.points} pts + + + + + + {archive.error && } + ); }; diff --git a/src/components/admin/task/workspaceState.ts b/src/components/admin/task/workspaceState.ts new file mode 100644 index 0000000..7f2ce8a --- /dev/null +++ b/src/components/admin/task/workspaceState.ts @@ -0,0 +1,33 @@ +import type { CategoryView, TaskView } from "./model"; + +export interface TaskGroup { + category: CategoryView; + tasks: Array; +} + +export function groupWorkspaceTasks( + tasks: Array, + categories: Array, + search: string, + showArchived: boolean, +): Array { + const query = search.trim().toLocaleLowerCase(); + const groups = categories.map((category) => ({ + category, + tasks: tasks.filter((task) => { + if (task.categoryId !== category.id || (!showArchived && task.archived)) { + return false; + } + + return ( + query.length === 0 || + task.title.toLocaleLowerCase().includes(query) || + task.description.toLocaleLowerCase().includes(query) + ); + }), + })); + + return query.length === 0 + ? groups + : groups.filter(({ tasks: visibleTasks }) => visibleTasks.length > 0); +} diff --git a/src/components/admin/task/workspaceView.tsx b/src/components/admin/task/workspaceView.tsx new file mode 100644 index 0000000..da99a7e --- /dev/null +++ b/src/components/admin/task/workspaceView.tsx @@ -0,0 +1,220 @@ +"use client"; + +import { Eye, EyeOff, Plus, Search, Tags } from "lucide-react"; +import Link from "next/link"; +import { type FC, useState } from "react"; +import { Accordion } from "../../ui/accordion"; +import { Button } from "../../ui/button"; +import { EmptyState, Notice } from "../../ui/feedback"; +import { Input } from "../../ui/formControls"; +import { Page } from "../../ui/page"; +import { SelectableAccordion } from "../../ui/selectableAccordion"; +import { TaskBulkActions } from "./bulkActions"; +import type { CategoryView, TaskView } from "./model"; +import { TaskRow } from "./row"; +import type { TaskGroup } from "./workspaceState"; + +interface Props { + readonly categories: Array; + readonly groups: Array; + readonly search: string; + readonly showArchived: boolean; + readonly archivedCount: number; + readonly onSearchChange: (search: string) => void; + readonly onToggleArchived: () => void; + readonly onCreate: (categoryId?: string) => void; + readonly onEdit: (task: TaskView) => void; +} + +export const TaskWorkspaceView: FC = ({ + categories, + groups, + search, + showArchived, + archivedCount, + onSearchChange, + onToggleArchived, + onCreate, + onEdit, +}) => { + const [collapsed, setCollapsed] = useState>(() => new Set()); + + return ( + + {categories.length === 0 && ( + + Every task needs a category.{" "} + + Create one first. + + + )} + + {/* top-17.5 / md:top-19 sit right under the sticky navbar (h-16 + stripe, md:h-[76px]). */} +
+
+ +
+ + { + onSearchChange(event.target.value); + }} + placeholder="Search tasks" + className="pl-9 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring" + /> +
+ {archivedCount > 0 && ( + + )} + + +
+ + {groups.length > 0 && ( + + )} +
+ + {search.trim() !== "" && groups.length === 0 && ( + + + + )} + + category.id).filter((id) => !collapsed.has(id))} + onValueChange={(open) => { + setCollapsed( + new Set(groups.map(({ category }) => category.id).filter((id) => !open.includes(id))), + ); + }} + > + {groups.map(({ category, tasks }) => ( + + {category.name}{" "} + + · {tasks.length} + + + } + items={tasks} + itemLabel={(task) => task.title} + renderItem={(task) => ( + { + onEdit(task); + }} + /> + )} + actions={(selected, clear) => ( + + )} + headerAction={ + + } + empty={ +

+ {showArchived + ? "No tasks in this category yet." + : "No active tasks in this category."} +

+ } + /> + ))} +
+
+ ); +}; diff --git a/tests/components/taskWorkspace.test.ts b/tests/components/taskWorkspace.test.ts new file mode 100644 index 0000000..cdbe559 --- /dev/null +++ b/tests/components/taskWorkspace.test.ts @@ -0,0 +1,77 @@ +import { describe, expect, it } from "vitest"; +import type { CategoryView, TaskView } from "~/components/admin/task/model"; +import { groupWorkspaceTasks } from "~/components/admin/task/workspaceState"; + +const categories: Array = [ + { + id: "food", + name: "Food", + slug: "food", + }, + { + id: "home", + name: "Home", + slug: "home", + }, + { + id: "empty", + name: "Empty", + slug: "empty", + }, +]; + +const tasks: Array = [ + { + id: "task-1", + title: "Bake bread", + description: "Use the rye flour", + categoryId: "food", + categoryName: "Food", + points: 5, + policy: "one_per_user", + cooldownSeconds: null, + photoRequired: false, + photoInstructions: null, + archived: false, + }, + { + id: "task-2", + title: "Clean room", + description: "Put away toys", + categoryId: "home", + categoryName: "Home", + points: 3, + policy: "single_winner", + cooldownSeconds: null, + photoRequired: false, + photoInstructions: null, + archived: true, + }, +]; + +describe("task workspace grouping", () => { + it("shows active tasks and empty categories by default", () => { + const groups = groupWorkspaceTasks(tasks, categories, "", false); + + expect( + groups.map(({ category, tasks: groupTasks }) => [category.name, groupTasks.length]), + ).toEqual([ + ["Food", 1], + ["Home", 0], + ["Empty", 0], + ]); + }); + + it("searches task titles and descriptions and omits non-matching categories", () => { + const groups = groupWorkspaceTasks(tasks, categories, "RYE", false); + + expect(groups.map(({ category }) => category.name)).toEqual(["Food"]); + expect(groups[0]?.tasks.map(({ id }) => id)).toEqual(["task-1"]); + }); + + it("shows archived tasks only when archive visibility is enabled", () => { + const groups = groupWorkspaceTasks(tasks, categories, "", true); + + expect(groups[1]?.tasks.map(({ id }) => id)).toEqual(["task-2"]); + }); +}); From 9239c1030bfc25e4b0373d2f138bcf3544b41ba3 Mon Sep 17 00:00:00 2001 From: Oluwatobiloba Promise Temitope Date: Thu, 15 Oct 2026 00:15:00 +0300 Subject: [PATCH 05/17] feat: replace categories page with a dialog in the task workspace --- src/actions/category/index.ts | 2 +- src/app/admin/categories/page.tsx | 21 +- src/components/admin/category/editForm.tsx | 6 +- .../admin/category/managementDialog.tsx | 192 ++++++++++++++++++ src/components/admin/category/manager.tsx | 141 ------------- src/components/admin/category/model.ts | 5 - src/components/admin/task/manager.tsx | 15 ++ src/components/admin/task/workspaceView.tsx | 21 +- src/components/navLinks.tsx | 2 - src/lib/navigation.ts | 9 +- tests/domain/navigation.test.ts | 4 +- 11 files changed, 231 insertions(+), 187 deletions(-) create mode 100644 src/components/admin/category/managementDialog.tsx delete mode 100644 src/components/admin/category/manager.tsx delete mode 100644 src/components/admin/category/model.ts diff --git a/src/actions/category/index.ts b/src/actions/category/index.ts index 632de03..50f7932 100644 --- a/src/actions/category/index.ts +++ b/src/actions/category/index.ts @@ -4,7 +4,7 @@ import { categoryService } from "~/infra"; import { action } from "~/lib/action"; import { createCategorySchema, deleteCategorySchema, updateCategorySchema } from "./schema"; -const revalidate = ["/admin/categories", "/admin/tasks", "/"]; +const revalidate = ["/admin/tasks", "/"]; export const createCategoryAction = action( createCategorySchema, diff --git a/src/app/admin/categories/page.tsx b/src/app/admin/categories/page.tsx index 614762d..4c85c05 100644 --- a/src/app/admin/categories/page.tsx +++ b/src/app/admin/categories/page.tsx @@ -1,18 +1,5 @@ -import type { Metadata } from "next"; -import type { FC } from "react"; -import { CategoryManager } from "~/components/admin/category/manager"; -import { categoryService } from "~/infra"; -import { userCanManageCategories } from "~/domain/rules"; -import { requireUser } from "~/lib/user"; +import { redirect } from "next/navigation"; -export const metadata: Metadata = { title: "Categories" }; - -const AdminCategoriesPage: FC = async () => { - const categories = await categoryService.listCategories( - await requireUser(userCanManageCategories), - ); - - return ; -}; - -export default AdminCategoriesPage; +export default function AdminCategoriesPage() { + redirect("/admin/tasks?categories=1"); +} diff --git a/src/components/admin/category/editForm.tsx b/src/components/admin/category/editForm.tsx index a2d3200..b2f998e 100644 --- a/src/components/admin/category/editForm.tsx +++ b/src/components/admin/category/editForm.tsx @@ -7,11 +7,11 @@ import { useActionForm } from "~/lib/form"; import { Button } from "../../ui/button"; import { Field, Form, FormError } from "../../ui/form"; import { Input } from "../../ui/formControls"; -import type { CategoryRowView } from "./model"; +import type { CategoryView } from "../task/model"; interface Props { - category: CategoryRowView; - onDone: () => void; + readonly category: CategoryView; + readonly onDone: () => void; } export const EditCategoryForm: FC = ({ category, onDone }) => { diff --git a/src/components/admin/category/managementDialog.tsx b/src/components/admin/category/managementDialog.tsx new file mode 100644 index 0000000..e624fe0 --- /dev/null +++ b/src/components/admin/category/managementDialog.tsx @@ -0,0 +1,192 @@ +"use client"; + +import { type FC, useState } from "react"; +import { deleteCategoryAction } from "~/actions/category"; +import { useAction } from "~/lib/form"; +import { Button } from "../../ui/button"; +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogTitle, +} from "../../ui/dialog"; +import { EmptyState, ErrorState } from "../../ui/feedback"; +import { CreateCategoryForm } from "./createForm"; +import { EditCategoryForm } from "./editForm"; +import type { CategoryView, TaskView } from "../task/model"; + +interface Props { + readonly open: boolean; + readonly categories: Array; + readonly tasks: Array; + readonly onOpenChange: (open: boolean) => void; +} + +export const CategoryManagementDialog: FC = ({ open, categories, tasks, onOpenChange }) => { + const [renaming, setRenaming] = useState(null); + + return ( + { + if (!next) setRenaming(null); + onOpenChange(next); + }} + > + +
+
+ + Manage categories + + + Create, rename, or remove the groups used to organize tasks. + +
+ + + +
+ +
+
+

+ Add category +

+ +
+ +
+

+ Categories{" "} + + · {categories.length} + +

+ {categories.length === 0 ? ( + + ) : ( +
    + {categories.map((category) => ( + task.categoryId === category.id).length} + renaming={renaming === category.id} + onRename={() => { + setRenaming(category.id); + }} + onRenameDone={() => { + setRenaming(null); + }} + /> + ))} +
+ )} +
+
+
+
+ ); +}; + +interface CategoryRowProps { + readonly category: CategoryView; + readonly taskCount: number; + readonly renaming: boolean; + readonly onRename: () => void; + readonly onRenameDone: () => void; +} + +const CategoryRow: FC = ({ + category, + taskCount, + renaming, + onRename, + onRenameDone, +}) => { + const [confirming, setConfirming] = useState(false); + const remove = useAction(deleteCategoryAction, { + onError: () => { + setConfirming(false); + }, + }); + + return ( +
  • + {renaming ? ( + + ) : ( +
    +

    {category.name}

    +

    + {category.slug} · {taskCount} total {taskCount === 1 ? "task" : "tasks"} (archived + included) +

    + {taskCount > 0 && ( +

    + Move all tasks, including archived ones, before deleting this category. +

    + )} +
    + )} + + {!renaming && ( +
    + {confirming ? ( + <> + + + + ) : ( + <> + + + + )} +
    + )} + + {remove.error && ( +
    + +
    + )} +
  • + ); +}; diff --git a/src/components/admin/category/manager.tsx b/src/components/admin/category/manager.tsx deleted file mode 100644 index 0c6d396..0000000 --- a/src/components/admin/category/manager.tsx +++ /dev/null @@ -1,141 +0,0 @@ -"use client"; - -import Link from "next/link"; -import { type FC, useState } from "react"; -import { deleteCategoryAction } from "~/actions/category"; -import { useAction } from "~/lib/form"; -import { Button } from "../../ui/button"; -import { Card, CardContent } from "../../ui/card"; -import { EmptyState, ErrorState } from "../../ui/feedback"; -import { Page } from "../../ui/page"; -import { CreateCategoryForm } from "./createForm"; -import { EditCategoryForm } from "./editForm"; -import type { CategoryRowView } from "./model"; - -interface Props { - categories: Array; -} - -export const CategoryManager: FC = ({ categories }) => { - const [renaming, setRenaming] = useState(null); - const stopRenaming = () => { - setRenaming(null); - }; - - return ( - - Every task belongs to one category.{" "} - - Manage tasks - - - } - > - - - - - - - {categories.length === 0 && ( - - )} - -
      - {categories.map((category) => ( -
    • - - - {renaming === category.id ? ( - - ) : ( - { - setRenaming(category.id); - }} - /> - )} - - -
    • - ))} -
    -
    - ); -}; - -interface CategoryRowProps { - category: CategoryRowView; - onRename: () => void; -} - -const CategoryRow: FC = ({ category, onRename }) => { - const [confirming, setConfirming] = useState(false); - const remove = useAction(deleteCategoryAction, { - onError: () => { - setConfirming(false); - }, - }); - - return ( - <> -
    - {category.name} - {category.slug} -
    -
    - {confirming ? ( - <> - - - - ) : ( - <> - - - - )} -
    - {remove.error && ( -
    - -
    - )} - - ); -}; diff --git a/src/components/admin/category/model.ts b/src/components/admin/category/model.ts deleted file mode 100644 index 5d94463..0000000 --- a/src/components/admin/category/model.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface CategoryRowView { - id: string; - name: string; - slug: string; -} diff --git a/src/components/admin/task/manager.tsx b/src/components/admin/task/manager.tsx index 72726ce..3e9feb2 100644 --- a/src/components/admin/task/manager.tsx +++ b/src/components/admin/task/manager.tsx @@ -3,6 +3,7 @@ import { useSearchParams } from "next/navigation"; import { type FC, useEffect, useMemo, useState } from "react"; import type { CategoryView, TaskView } from "./model"; +import { CategoryManagementDialog } from "../category/managementDialog"; import { type TaskDialog, TaskEditorDialog } from "./taskEditorDialog"; import { TaskWorkspaceView } from "./workspaceView"; import { groupWorkspaceTasks } from "./workspaceState"; @@ -17,6 +18,9 @@ export const TaskManager: FC = ({ tasks, categories }) => { const [search, setSearch] = useState(() => searchParams.get("search") ?? ""); const [showArchived, setShowArchived] = useState(() => searchParams.get("archived") === "1"); const [dialog, setDialog] = useState(null); + const [categoryDialogOpen, setCategoryDialogOpen] = useState( + () => searchParams.get("categories") === "1", + ); const groups = useMemo( () => groupWorkspaceTasks(tasks, categories, search, showArchived), [categories, tasks, search, showArchived], @@ -33,6 +37,8 @@ export const TaskManager: FC = ({ tasks, categories }) => { else url.searchParams.delete("search"); if (showArchived) url.searchParams.set("archived", "1"); else url.searchParams.delete("archived"); + // The nav link opens the dialog once; a reload should not reopen it. + url.searchParams.delete("categories"); window.history.replaceState(null, "", url); }, 300); @@ -49,6 +55,9 @@ export const TaskManager: FC = ({ tasks, categories }) => { search={search} showArchived={showArchived} archivedCount={archivedCount} + onManageCategories={() => { + setCategoryDialogOpen(true); + }} onSearchChange={setSearch} onToggleArchived={() => { setShowArchived((current) => !current); @@ -66,6 +75,12 @@ export const TaskManager: FC = ({ tasks, categories }) => { }); }} /> + void; readonly onSearchChange: (search: string) => void; readonly onToggleArchived: () => void; readonly onCreate: (categoryId?: string) => void; @@ -32,6 +32,7 @@ export const TaskWorkspaceView: FC = ({ search, showArchived, archivedCount, + onManageCategories, onSearchChange, onToggleArchived, onCreate, @@ -47,9 +48,9 @@ export const TaskWorkspaceView: FC = ({ {categories.length === 0 && ( Every task needs a category.{" "} - + )} @@ -94,11 +95,15 @@ export const TaskWorkspaceView: FC = ({ Archived ({archivedCount}) )} - + ); +}; diff --git a/src/components/admin/task/bulkActions.tsx b/src/components/admin/task/bulkActions.tsx index 95af26f..cc32fca 100644 --- a/src/components/admin/task/bulkActions.tsx +++ b/src/components/admin/task/bulkActions.tsx @@ -117,7 +117,7 @@ export function TaskBulkActions({ tasks, categories, categoryId, onDone }: Props - - - {archive.error && } - - ); -}; diff --git a/src/components/admin/task/workspaceState.ts b/src/components/admin/task/workspaceState.ts index 7f2ce8a..68fb8eb 100644 --- a/src/components/admin/task/workspaceState.ts +++ b/src/components/admin/task/workspaceState.ts @@ -1,3 +1,4 @@ +import { matchesTaskSearch } from "../../task/search"; import type { CategoryView, TaskView } from "./model"; export interface TaskGroup { @@ -11,7 +12,6 @@ export function groupWorkspaceTasks( search: string, showArchived: boolean, ): Array { - const query = search.trim().toLocaleLowerCase(); const groups = categories.map((category) => ({ category, tasks: tasks.filter((task) => { @@ -19,15 +19,11 @@ export function groupWorkspaceTasks( return false; } - return ( - query.length === 0 || - task.title.toLocaleLowerCase().includes(query) || - task.description.toLocaleLowerCase().includes(query) - ); + return matchesTaskSearch(task, search); }), })); - return query.length === 0 + return search.trim() === "" ? groups : groups.filter(({ tasks: visibleTasks }) => visibleTasks.length > 0); } diff --git a/src/components/admin/task/workspaceView.tsx b/src/components/admin/task/workspaceView.tsx index 072df38..5c0f587 100644 --- a/src/components/admin/task/workspaceView.tsx +++ b/src/components/admin/task/workspaceView.tsx @@ -1,16 +1,20 @@ "use client"; -import { Eye, EyeOff, Plus, Search, Tags } from "lucide-react"; -import { type FC, useState } from "react"; -import { Accordion } from "../../ui/accordion"; +import { Eye, EyeOff, Plus, Tags } from "lucide-react"; +import type { FC } from "react"; import { Button } from "../../ui/button"; -import { EmptyState, Notice } from "../../ui/feedback"; -import { Input } from "../../ui/formControls"; +import { Notice } from "../../ui/feedback"; import { Page } from "../../ui/page"; import { SelectableAccordion } from "../../ui/selectableAccordion"; +import { CategoryTitle } from "../../task/categoryTitle"; +import { TaskGroups } from "../../task/groups"; +import { TaskToolbar } from "../../task/toolbar"; import { TaskBulkActions } from "./bulkActions"; import type { CategoryView, TaskView } from "./model"; -import { TaskRow } from "./row"; +import { TaskRow } from "../../task/row"; +import { ArchiveTaskButton } from "./archiveButton"; +import { Badge } from "../../ui/badge"; +import { describeTaskPolicy } from "~/lib/taskLabels"; import type { TaskGroup } from "./workspaceState"; interface Props { @@ -38,8 +42,6 @@ export const TaskWorkspaceView: FC = ({ onCreate, onEdit, }) => { - const [collapsed, setCollapsed] = useState>(() => new Set()); - return ( = ({ )} - {/* top-17.5 / md:top-19 sit right under the sticky navbar (h-16 + stripe, md:h-[76px]). */} -
    -
    - -
    - - { - onSearchChange(event.target.value); - }} - placeholder="Search tasks" - className="pl-9 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring" - /> -
    - {archivedCount > 0 && ( - - )} + {archivedCount > 0 && ( - -
    - - {groups.length > 0 && ( - )} -
    - - {search.trim() !== "" && groups.length === 0 && ( - - - - )} + + Categories + + + - category.id).filter((id) => !collapsed.has(id))} - onValueChange={(open) => { - setCollapsed( - new Set(groups.map(({ category }) => category.id).filter((id) => !open.includes(id))), - ); + category.id)} + search={search} + onClearSearch={() => { + onSearchChange(""); }} > {groups.map(({ category, tasks }) => ( - {category.name}{" "} - - · {tasks.length} - - - } + title={} items={tasks} itemLabel={(task) => task.title} renderItem={(task) => ( { + title={task.title} + policy={describeTaskPolicy(task.policy)} + points={task.points} + photoRequired={task.photoRequired} + muted={task.archived} + status={task.archived && Archived} + aria-label={`Edit ${task.title}`} + onClick={() => { onEdit(task); }} + action={} /> )} actions={(selected, clear) => ( @@ -200,6 +142,7 @@ export const TaskWorkspaceView: FC = ({ headerAction={

    } /> ))} -
    +
    ); }; diff --git a/src/components/task/categoryTitle.tsx b/src/components/task/categoryTitle.tsx new file mode 100644 index 0000000..a1c3c24 --- /dev/null +++ b/src/components/task/categoryTitle.tsx @@ -0,0 +1,10 @@ +import type { FC } from "react"; + +export const CategoryTitle: FC<{ readonly name: string; readonly count: number }> = ({ + name, + count, +}) => ( + + {name} · {count} + +); diff --git a/src/components/task/groups.tsx b/src/components/task/groups.tsx new file mode 100644 index 0000000..5f77bae --- /dev/null +++ b/src/components/task/groups.tsx @@ -0,0 +1,43 @@ +"use client"; + +import { type FC, type ReactNode, useState } from "react"; +import { Accordion } from "../ui/accordion"; +import { Button } from "../ui/button"; +import { EmptyState } from "../ui/feedback"; + +interface Props { + readonly groupIds: ReadonlyArray; + readonly search: string; + readonly onClearSearch: () => void; + readonly children: ReactNode; +} + +export const TaskGroups: FC = ({ groupIds, search, onClearSearch, children }) => { + const [collapsed, setCollapsed] = useState>(() => new Set()); + + if (search.trim() !== "" && groupIds.length === 0) { + return ( + + + + ); + } + + return ( + !collapsed.has(id))} + onValueChange={(open) => { + setCollapsed(new Set(groupIds.filter((id) => !open.includes(id)))); + }} + > + {children} + + ); +}; diff --git a/src/components/task/row.tsx b/src/components/task/row.tsx new file mode 100644 index 0000000..decc3a4 --- /dev/null +++ b/src/components/task/row.tsx @@ -0,0 +1,78 @@ +"use client"; + +import { Camera, ChevronRight } from "lucide-react"; +import Link from "next/link"; +import type { FC, ReactNode } from "react"; +import { cn } from "~/lib/utils"; +import { Badge } from "../ui/badge"; + +const rowClassName = + "flex min-h-12 min-w-0 flex-1 flex-wrap items-center gap-x-3 gap-y-1 rounded-lg px-2 py-1.5 text-left hover:bg-muted focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"; + +interface Props { + readonly title: string; + readonly policy: string; + readonly points: number; + readonly photoRequired: boolean; + readonly muted?: boolean; + readonly status?: ReactNode; + readonly href?: string; + readonly onClick?: () => void; + readonly "aria-label"?: string; + readonly action?: ReactNode; +} + +export const TaskRow: FC = ({ + title, + policy, + points, + photoRequired, + muted = false, + status, + href, + onClick, + "aria-label": ariaLabel, + action, +}) => { + const content = ( + <> + + {title} + + + {photoRequired && ( + + + Photo required + + )} + {status} + {policy} + + {points} pts + + + + + ); + + return ( +
    + {href === undefined ? ( + + ) : ( + + {content} + + )} + {action} +
    + ); +}; diff --git a/src/components/task/search.ts b/src/components/task/search.ts new file mode 100644 index 0000000..822fbc4 --- /dev/null +++ b/src/components/task/search.ts @@ -0,0 +1,12 @@ +export function matchesTaskSearch( + task: { readonly title: string; readonly description: string }, + search: string, +): boolean { + const query = search.trim().toLocaleLowerCase(); + + return ( + query.length === 0 || + task.title.toLocaleLowerCase().includes(query) || + task.description.toLocaleLowerCase().includes(query) + ); +} diff --git a/src/components/task/toolbar.tsx b/src/components/task/toolbar.tsx new file mode 100644 index 0000000..4faad3e --- /dev/null +++ b/src/components/task/toolbar.tsx @@ -0,0 +1,49 @@ +"use client"; + +import { Search } from "lucide-react"; +import type { FC, ReactNode } from "react"; +import { Input } from "../ui/formControls"; + +interface TaskToolbarProps { + readonly label: string; + readonly search: string; + readonly onSearchChange: (search: string) => void; + readonly searchDisabled?: boolean; + readonly children?: ReactNode; +} + +export const TaskToolbar: FC = ({ + label, + search, + onSearchChange, + searchDisabled = false, + children, +}) => ( + // top-17.5 / md:top-19 sit right under the sticky navbar (h-16 + stripe, md:h-[76px]). +
    + +
    + + { + onSearchChange(event.target.value); + }} + placeholder="Search tasks" + className="pl-9 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring" + /> +
    + {children} +
    +); diff --git a/src/components/ui/accordion.tsx b/src/components/ui/accordion.tsx index 708a9e4..f330229 100644 --- a/src/components/ui/accordion.tsx +++ b/src/components/ui/accordion.tsx @@ -2,7 +2,7 @@ import * as AccordionPrimitive from "@radix-ui/react-accordion"; import { ChevronDown } from "lucide-react"; -import type { ComponentProps } from "react"; +import type { ComponentProps, ReactNode } from "react"; import { cn } from "~/lib/utils"; export const Accordion = AccordionPrimitive.Root; @@ -31,7 +31,7 @@ export function AccordionTrigger({ {...props} > {children} - + @@ -52,3 +52,33 @@ export function AccordionContent({ ); } + +export interface GroupAccordionItemProps { + readonly value: string; + readonly title: ReactNode; + readonly leading?: ReactNode; + readonly headerAction?: ReactNode; + readonly children: ReactNode; +} + +export function GroupAccordionItem({ + value, + title, + leading, + headerAction, + children, +}: GroupAccordionItemProps) { + return ( + +
    + {leading} + {title} + {headerAction} +
    + {children} +
    + ); +} diff --git a/src/components/ui/checkbox.tsx b/src/components/ui/checkbox.tsx index 2a1e0d5..2431792 100644 --- a/src/components/ui/checkbox.tsx +++ b/src/components/ui/checkbox.tsx @@ -9,7 +9,7 @@ export function Checkbox({ className, ...props }: ComponentProps { - readonly value: string; - readonly id?: string; - readonly title: ReactNode; +interface Props extends Omit< + GroupAccordionItemProps, + "leading" | "children" +> { readonly label: string; readonly items: ReadonlyArray; readonly itemLabel: (item: Item) => string; readonly renderItem: (item: Item) => ReactNode; readonly actions: (selected: Array, clear: () => void) => ReactNode; - readonly headerAction?: ReactNode; readonly empty?: ReactNode; - readonly className?: string; } export function SelectableAccordion({ - value, - id, - title, label, items, itemLabel, renderItem, actions, - headerAction, empty, - className, + ...group }: Props) { const [selectedIds, setSelectedIds] = useState>(() => new Set()); - // Ids of items that left the list (moved, archived, filtered out) are ignored, not kept. const selected = items.filter((item) => selectedIds.has(item.id)); const clear = () => { setSelectedIds(new Set()); @@ -51,20 +44,11 @@ export function SelectableAccordion({ if (selected.length > 0) allState = selected.length === items.length ? true : "indeterminate"; return ( - -
    + ({ setSelectedIds(checked === true ? new Set(items.map((item) => item.id)) : new Set()); }} /> - - {title} - - {headerAction} -
    - - {selected.length > 0 && ( -
    + {selected.length > 0 && ( +
    + {selected.length} selected + {actions(selected, clear)} + +
    + )} + {items.length === 0 ? ( +
    {empty}
    + ) : ( +
      + {items.map((item) => ( +
    • - - -
    - )} - {items.length === 0 ? ( -
    {empty}
    - ) : ( -
      - {items.map((item) => ( -
    • - { - toggle(item.id, checked === true); - }} - /> - {renderItem(item)} -
    • - ))} -
    - )} -
    -
    + { + toggle(item.id, checked === true); + }} + /> + {renderItem(item)} + + ))} + + )} + ); } From f6ea7a43c2658973e4d50421051eee37ee87f1d8 Mon Sep 17 00:00:00 2001 From: Oluwatobiloba Promise Temitope Date: Thu, 15 Oct 2026 09:55:00 +0300 Subject: [PATCH 08/17] feat: group member tasks by category with search and availability --- src/app/(member)/tasks/page.tsx | 59 ++++++--------- src/components/task/list.tsx | 129 ++++++++++++++++++++++++++++++++ src/lib/taskLabels.ts | 21 ++++++ tests/lib/taskLabels.test.ts | 72 ++++++++++++++++++ 4 files changed, 244 insertions(+), 37 deletions(-) create mode 100644 src/components/task/list.tsx create mode 100644 tests/lib/taskLabels.test.ts diff --git a/src/app/(member)/tasks/page.tsx b/src/app/(member)/tasks/page.tsx index fd8e3bd..440e875 100644 --- a/src/app/(member)/tasks/page.tsx +++ b/src/app/(member)/tasks/page.tsx @@ -1,13 +1,10 @@ import type { Metadata } from "next"; -import Link from "next/link"; import type { FC } from "react"; -import { ProofStatusBadge } from "~/components/proof/statusBadge"; -import { Badge } from "~/components/ui/badge"; -import { Card, CardContent } from "~/components/ui/card"; -import { EmptyState } from "~/components/ui/feedback"; +import { TaskList } from "~/components/task/list"; import { Page } from "~/components/ui/page"; import { taskService } from "~/infra"; -import { describeTaskPolicy } from "~/lib/taskLabels"; +import { describeTaskPolicy, taskAvailability } from "~/lib/taskLabels"; +import { formatDate } from "~/lib/utils"; import { userCanBrowseTasks } from "~/domain/rules"; import { requireUser } from "~/lib/user"; @@ -15,39 +12,27 @@ export const metadata: Metadata = { title: "Tasks" }; const TasksPage: FC = async () => { const items = await taskService.listOpenTasks(await requireUser(userCanBrowseTasks)); + const now = new Date(); + const tasks = items.map((item) => ({ + id: item.task.id, + title: item.task.title, + description: item.task.description, + categoryId: item.task.categoryId, + categoryName: item.categoryName, + points: item.task.points, + policy: describeTaskPolicy(item.task.policy), + photoRequired: item.task.photoRequired, + availability: taskAvailability(item, now), + cooldownUntil: item.userCooldownUntil && formatDate(item.userCooldownUntil), + })); + const open = tasks.filter((task) => task.availability === "open").length; return ( - - {items.length === 0 && ( - - )} -
      - {items.map(({ task, categoryName, userProofStatus, takenByAnother }) => ( -
    • - - -
      - - {task.title} - -

      - {categoryName} · {describeTaskPolicy(task.policy)} - {task.photoRequired && " · photo required"} -

      - {userProofStatus && } - {!userProofStatus && takenByAnother && Taken by someone else} -
      - - {task.points} pts - -
      -
      -
    • - ))} -
    + + ); }; diff --git a/src/components/task/list.tsx b/src/components/task/list.tsx new file mode 100644 index 0000000..081a2ab --- /dev/null +++ b/src/components/task/list.tsx @@ -0,0 +1,129 @@ +"use client"; + +import { Check, Clock, Lock } from "lucide-react"; +import Link from "next/link"; +import { type FC, useState } from "react"; +import type { TaskAvailability } from "~/lib/taskLabels"; +import { GroupAccordionItem } from "../ui/accordion"; +import { Badge } from "../ui/badge"; +import { Button } from "../ui/button"; +import { EmptyState } from "../ui/feedback"; +import { CategoryTitle } from "./categoryTitle"; +import { TaskGroups } from "./groups"; +import { TaskRow } from "./row"; +import { matchesTaskSearch } from "./search"; +import { TaskToolbar } from "./toolbar"; + +export interface BrowsableTask { + readonly id: string; + readonly title: string; + readonly description: string; + readonly categoryId: string; + readonly categoryName: string; + readonly points: number; + readonly policy: string; + readonly photoRequired: boolean; + readonly availability: TaskAvailability; + readonly cooldownUntil: string | null; +} + +const rank: Record = { + open: 0, + pending: 1, + cooldown: 2, + taken: 2, + done: 3, +}; + +export const TaskList: FC<{ readonly tasks: ReadonlyArray }> = ({ tasks }) => { + const [search, setSearch] = useState(""); + const groups = Map.groupBy( + tasks.filter((task) => matchesTaskSearch(task, search)), + (task) => task.categoryId, + ); + + if (tasks.length === 0) { + return ( + + + + ); + } + + return ( + <> + + + { + setSearch(""); + }} + > + {[...groups].map(([categoryId, group]) => ( + } + > +
      + {group + .toSorted((a, b) => rank[a.availability] - rank[b.availability]) + .map((task) => ( +
    • + } + /> +
    • + ))} +
    +
    + ))} +
    + + ); +}; + +const AvailabilityBadge: FC<{ readonly task: BrowsableTask }> = ({ task }) => { + switch (task.availability) { + case "pending": + return ( + + + Awaiting review + + ); + case "done": + return ( + + + Done + + ); + case "taken": + return ( + + + Taken + + ); + case "cooldown": + return ( + + + Again on {task.cooldownUntil} + + ); + case "open": + return null; + } +}; diff --git a/src/lib/taskLabels.ts b/src/lib/taskLabels.ts index 1a67818..bafa745 100644 --- a/src/lib/taskLabels.ts +++ b/src/lib/taskLabels.ts @@ -1,4 +1,5 @@ import { completionPolicy } from "~/domain/completionPolicy"; +import type { ProofStatus } from "~/domain/proof"; import type { TaskPolicy } from "~/domain/task"; export const describeTaskPolicy = (policy: TaskPolicy): string => completionPolicy(policy).label; @@ -39,3 +40,23 @@ export function describeUnavailability( return null; } + +export type TaskAvailability = "open" | "pending" | "done" | "taken" | "cooldown"; + +interface Standing { + readonly userProofStatus: ProofStatus | null; + readonly takenByAnother: boolean; + readonly userCooldownUntil: Date | null; +} + +export function taskAvailability( + { userProofStatus, takenByAnother, userCooldownUntil }: Standing, + now: Date, +): TaskAvailability { + if (userProofStatus === "pending") return "pending"; + if (userProofStatus === "approved") return "done"; + if (takenByAnother) return "taken"; + if (userCooldownUntil !== null && userCooldownUntil > now) return "cooldown"; + + return "open"; +} diff --git a/tests/lib/taskLabels.test.ts b/tests/lib/taskLabels.test.ts new file mode 100644 index 0000000..e0a8e4e --- /dev/null +++ b/tests/lib/taskLabels.test.ts @@ -0,0 +1,72 @@ +import { describe, expect, it } from "vitest"; +import { taskAvailability } from "~/lib/taskLabels"; + +const now = new Date("2026-10-15T12:00:00Z"); +const standing = { + userProofStatus: null, + takenByAnother: false, + userCooldownUntil: null, +}; + +describe("taskAvailability", () => { + it("is open when nothing blocks the user", () => { + expect(taskAvailability(standing, now)).toBe("open"); + }); + + it("puts the user's own proof before anyone else's claim", () => { + expect( + taskAvailability( + { + ...standing, + userProofStatus: "pending", + takenByAnother: true, + }, + now, + ), + ).toBe("pending"); + expect( + taskAvailability( + { + ...standing, + userProofStatus: "approved", + }, + now, + ), + ).toBe("done"); + }); + + it("is taken when another member holds an exclusive task", () => { + expect( + taskAvailability( + { + ...standing, + takenByAnother: true, + }, + now, + ), + ).toBe("taken"); + }); + + it("only counts a cooldown that has not ended", () => { + const later = new Date(now.getTime() + 60_000); + const earlier = new Date(now.getTime() - 60_000); + expect( + taskAvailability( + { + ...standing, + userCooldownUntil: later, + }, + now, + ), + ).toBe("cooldown"); + expect( + taskAvailability( + { + ...standing, + userCooldownUntil: earlier, + }, + now, + ), + ).toBe("open"); + }); +}); From 0d510f986ed679b6129f7dd43870eeba5d5f1701 Mon Sep 17 00:00:00 2001 From: Oluwatobiloba Promise Temitope Date: Thu, 15 Oct 2026 10:25:00 +0300 Subject: [PATCH 09/17] feat: restyle the task page, proof form and my proofs list --- src/app/(member)/proofs/page.tsx | 68 +++++++++++-- src/app/(member)/tasks/[taskId]/page.tsx | 60 +++++++++--- src/components/proof/form.tsx | 92 ++++++++++-------- .../proof/{myCard.tsx => myRow.tsx} | 55 +++++------ src/components/proof/panel.tsx | 75 ++++++++++++-- src/components/proof/photoGallery.tsx | 3 +- src/components/proof/photoPicker.tsx | 97 +++++++++++-------- 7 files changed, 313 insertions(+), 137 deletions(-) rename src/components/proof/{myCard.tsx => myRow.tsx} (51%) diff --git a/src/app/(member)/proofs/page.tsx b/src/app/(member)/proofs/page.tsx index eb130a3..3aa61cd 100644 --- a/src/app/(member)/proofs/page.tsx +++ b/src/app/(member)/proofs/page.tsx @@ -1,16 +1,41 @@ import type { Metadata } from "next"; +import Link from "next/link"; import type { FC } from "react"; -import { MyProofCard } from "~/components/proof/myCard"; +import { MyProofRow } from "~/components/proof/myRow"; +import { Accordion, GroupAccordionItem } from "~/components/ui/accordion"; +import { Button } from "~/components/ui/button"; import { EmptyState } from "~/components/ui/feedback"; import { Page } from "~/components/ui/page"; +import type { ProofStatus } from "~/domain/proof"; import { proofService } from "~/infra"; import { userCanSubmitProof } from "~/domain/rules"; import { requireUser } from "~/lib/user"; export const metadata: Metadata = { title: "My proofs" }; +const sections: ReadonlyArray<{ status: ProofStatus; title: string }> = [ + { + status: "rejected", + title: "Rejected", + }, + { + status: "pending", + title: "Awaiting review", + }, + { + status: "approved", + title: "Approved", + }, +]; + const ProofsPage: FC = async () => { const entries = await proofService.listMyProofs(await requireUser(userCanSubmitProof)); + const groups = sections + .map((section) => ({ + ...section, + entries: entries.filter((entry) => entry.proof.status === section.status), + })) + .filter((group) => group.entries.length > 0); return ( @@ -18,15 +43,42 @@ const ProofsPage: FC = async () => { + > + + )} -
      - {entries.map((entry) => ( -
    • - -
    • + group.status !== "approved" || groups.length === 1) + .map((group) => group.status)} + > + {groups.map((group) => ( + + {group.title}{" "} + + · {group.entries.length} + + + } + > +
        + {group.entries.map((entry) => ( +
      • + +
      • + ))} +
      +
      ))} -
    +
    ); }; diff --git a/src/app/(member)/tasks/[taskId]/page.tsx b/src/app/(member)/tasks/[taskId]/page.tsx index 4a7b252..e80c97e 100644 --- a/src/app/(member)/tasks/[taskId]/page.tsx +++ b/src/app/(member)/tasks/[taskId]/page.tsx @@ -1,40 +1,71 @@ +import { Camera, ChevronLeft } from "lucide-react"; +import type { Metadata } from "next"; +import Link from "next/link"; import { notFound } from "next/navigation"; -import type { FC } from "react"; +import { type FC, cache } from "react"; import { ProofPanel } from "~/components/proof/panel"; import { Badge } from "~/components/ui/badge"; import { Card, CardContent } from "~/components/ui/card"; -import { Page } from "~/components/ui/page"; import { proofService, taskService } from "~/infra"; import { describeCooldown, describeTaskPolicy, describeUnavailability } from "~/lib/taskLabels"; import { formatDateTime } from "~/lib/utils"; import { userCanBrowseTasks } from "~/domain/rules"; import { requireUser } from "~/lib/user"; +const loadTask = cache(async (taskId: string) => + taskService.getTask(await requireUser(userCanBrowseTasks), taskId), +); + +export async function generateMetadata({ + params, +}: PageProps<"/tasks/[taskId]">): Promise { + const item = await loadTask((await params).taskId); + + return { title: item?.task.title ?? "Task" }; +} + const TaskPage: FC> = async ({ params }) => { const { taskId } = await params; const user = await requireUser(userCanBrowseTasks); - const [item, reviewers] = await Promise.all([ - taskService.getTask(user, taskId), - proofService.listReviewers(user), - ]); + const [item, reviewers] = await Promise.all([loadTask(taskId), proofService.listReviewers(user)]); if (!item) { notFound(); } const { task, categoryName } = item; const cooldown = describeCooldown(task.cooldownSeconds); - const details = [categoryName, describeTaskPolicy(task.policy), cooldown && `every ${cooldown}`]; return ( - +
    + + + Tasks + {task.points} pts - } - > +
    + +
    +

    {categoryName}

    +

    + {task.title} +

    +
    + {describeTaskPolicy(task.policy)} + {cooldown && every {cooldown}} + {task.photoRequired && ( + + + photo required + + )} +
    +
    {task.description && ( @@ -46,6 +77,7 @@ const TaskPage: FC> = async ({ params }) => { )} > = async ({ params }) => { formatDateTime, )} /> -
    + ); }; diff --git a/src/components/proof/form.tsx b/src/components/proof/form.tsx index 100afcd..23dc195 100644 --- a/src/components/proof/form.tsx +++ b/src/components/proof/form.tsx @@ -1,5 +1,6 @@ "use client"; +import { ChevronDown } from "lucide-react"; import { type FC, useState } from "react"; import { useFormContext, useWatch } from "react-hook-form"; import { submitProofAction } from "~/actions/proof"; @@ -8,13 +9,13 @@ import type { PublicUserView } from "~/domain/user"; import { useActionForm } from "~/lib/form"; import { UserAvatar } from "../ui/avatar"; import { Button } from "../ui/button"; -import { Card, CardContent } from "../ui/card"; import { Checkbox } from "../ui/formControls"; import { Form, FormActions, FormError } from "../ui/form"; import { PhotoPicker } from "./photoPicker"; interface Props { taskId: string; + points: number; photoRequired: boolean; photoInstructions: string | null; reviewers: ReadonlyArray; @@ -23,6 +24,7 @@ interface Props { export const ProofForm: FC = ({ taskId, + points, photoRequired, photoInstructions, reviewers, @@ -44,32 +46,32 @@ export const ProofForm: FC = ({ const missingPhotos = photoRequired && objectKeys.length === 0; return ( -
    + +

    Submit proof

    {photoRequired && ( - - -

    Photos

    - -
    -
    - )} - {reviewers.length > 0 && ( - - - - - +
    +

    + Photos{" "} + · at least one required +

    + +
    )} + {reviewers.length > 0 && } - - - {missingPhotos && ( -

    - Attach at least one photo first. -

    - )}
    ); @@ -79,22 +81,32 @@ const ReviewerPicker: FC<{ reviewers: ReadonlyArray }> = ({ revi const { register } = useFormContext<{ reviewerIds: Array }>(); return ( -
    - Reviewers -

    - Optional. The people you pick are notified; either way it waits in the review queue. -

    -
      - {reviewers.map((reviewer) => ( -
    • - -
    • - ))} -
    -
    +
    + + Notify a reviewer + · optional + + +
    + Reviewers +

    + The people you pick are notified; either way it waits in the review queue. +

    +
      + {reviewers.map((reviewer) => ( +
    • + +
    • + ))} +
    +
    +
    ); }; diff --git a/src/components/proof/myCard.tsx b/src/components/proof/myRow.tsx similarity index 51% rename from src/components/proof/myCard.tsx rename to src/components/proof/myRow.tsx index 2938fb5..f2dd78a 100644 --- a/src/components/proof/myCard.tsx +++ b/src/components/proof/myRow.tsx @@ -1,37 +1,44 @@ +import Link from "next/link"; import type { FC } from "react"; import type { ProofWithContext } from "~/core/ports/proof"; import { formatDateTime } from "~/lib/utils"; -import { ProofStatusBadge } from "./statusBadge"; import { PhotoGallery } from "./photoGallery"; -import { ReviewerList } from "../review/reviewers"; import { Badge } from "../ui/badge"; -import { Card, CardContent } from "../ui/card"; interface Props { entry: ProofWithContext; } -export const MyProofCard: FC = ({ +export const MyProofRow: FC = ({ entry: { proof, taskTitle, taskPoints, categoryName, photos, requestedReviewers, reviewedByName }, -}) => ( - - -
    -
    -

    {taskTitle}

    +}) => { + let review = "any admin can review it"; + if (reviewedByName !== null) review = `reviewed by ${reviewedByName}`; + else if (requestedReviewers.length > 0) { + review = `waiting on ${requestedReviewers.map((reviewer) => reviewer.displayName).join(", ")}`; + } + + return ( +
    +
    +
    + + {taskTitle} +

    {categoryName} · submitted{" "} + {" "} + · {review}

    -
    - - - {taskPoints} pts - -
    + + {taskPoints} pts +
    {proof.status === "rejected" && proof.rejectionReason && ( @@ -43,14 +50,8 @@ export const MyProofCard: FC = ({ `/api/photos/${proof.id}/${item.id}`)} alt={`Photos you submitted for ${taskTitle}`} - size="sm" - /> - - - - -); +
    + ); +}; diff --git a/src/components/proof/panel.tsx b/src/components/proof/panel.tsx index 9192de0..61da1ff 100644 --- a/src/components/proof/panel.tsx +++ b/src/components/proof/panel.tsx @@ -1,13 +1,17 @@ "use client"; -import { type FC, useState } from "react"; +import { Check, Clock, Lock } from "lucide-react"; +import Link from "next/link"; +import { type FC, type ReactNode, useState } from "react"; import type { ProofStatus } from "~/domain/proof"; import type { PublicUserView } from "~/domain/user"; -import { Notice } from "../ui/feedback"; +import { cn } from "~/lib/utils"; +import { Button } from "../ui/button"; import { ProofForm } from "./form"; interface Props { taskId: string; + points: number; photoRequired: boolean; photoInstructions: string | null; reviewers: ReadonlyArray; @@ -20,16 +24,47 @@ export const ProofPanel: FC = ({ status, unavailable, ...form }) => { if (submitted || status === "pending") { return ( - - Awaiting review. You will be notified either way; see My proofs for who is reviewing it. - + } + title="Awaiting review" + className="bg-brand-soft" + action={{ + href: "/proofs", + label: "See my proofs", + }} + > + You will be notified either way. My proofs shows who is reviewing it. + ); } if (status === "approved") { - return Completed — your points have been awarded.; + return ( + } + title={`Done, +${form.points} pts`} + className="bg-success-soft" + action={{ + href: "/tasks", + label: "Browse open tasks", + }} + > + Your points have been awarded. + + ); } if (unavailable) { - return {unavailable}; + return ( + } + title="Not available right now" + action={{ + href: "/tasks", + label: "Browse open tasks", + }} + > + {unavailable} + + ); } return ( @@ -41,3 +76,29 @@ export const ProofPanel: FC = ({ status, unavailable, ...form }) => { /> ); }; + +interface StatePanelProps { + icon: ReactNode; + title: string; + action: { href: string; label: string }; + className?: string; + children: ReactNode; +} + +const StatePanel: FC = ({ icon, title, action, className, children }) => ( +
    svg]:size-6 [&>svg]:shrink-0", + className, + )} + > + {icon} +
    +

    {title}

    +

    {children}

    +
    + +
    +); diff --git a/src/components/proof/photoGallery.tsx b/src/components/proof/photoGallery.tsx index 85bf02d..cf6db7a 100644 --- a/src/components/proof/photoGallery.tsx +++ b/src/components/proof/photoGallery.tsx @@ -5,11 +5,12 @@ import { cn } from "~/lib/utils"; interface Props { urls: ReadonlyArray; alt: string; - size?: "sm" | "md"; + size?: "xs" | "sm" | "md"; layout?: "row" | "grid"; } const sizes = { + xs: "size-12", sm: "size-20", md: "size-28", }; diff --git a/src/components/proof/photoPicker.tsx b/src/components/proof/photoPicker.tsx index e3272ff..e32a25e 100644 --- a/src/components/proof/photoPicker.tsx +++ b/src/components/proof/photoPicker.tsx @@ -1,12 +1,12 @@ "use client"; +import { Camera, LoaderCircle, X } from "lucide-react"; import { type FC, useState } from "react"; import { useFormContext, useWatch } from "react-hook-form"; import type { ProofValues } from "~/actions/proof/schema"; import { allowedContentTypes, isAllowedContentType, photoLimits } from "~/config/photo"; import { Button } from "../ui/button"; import { ErrorState } from "../ui/feedback"; -import { Label } from "../ui/formControls"; interface Props { proofRef: string; @@ -69,53 +69,70 @@ export const PhotoPicker: FC = ({ proofRef, instructions }) => { Photos (required) {instructions &&

    {instructions}

    } - - void add(event.target.files)} - className="text-sm text-foreground/80 file:mr-3 file:rounded-xl file:border file:border-border file:bg-background file:px-3 file:py-1.5 file:text-sm" - /> +
      + {previews.map((preview) => ( +
    • + {/* eslint-disable-next-line @next/next/no-img-element */} + {preview.name} + +
    • + ))} + {remaining > 0 && ( +
    • + +
    • + )} +

    JPEG, PNG, or WebP. Up to {maxMegabytes} MB each, {maxPhotosPerProof} photos at most.

    - {uploading && ( -

    +

    Uploading…

    )} {error && } - - {previews.length > 0 && ( -
      - {previews.map((preview) => ( -
    • - {/* eslint-disable-next-line @next/next/no-img-element */} - {preview.name} - -
    • - ))} -
    - )} ); }; From d3bade5d1b952bb197ccc60d1adb3627f743eb6a Mon Sep 17 00:00:00 2001 From: Oluwatobiloba Promise Temitope Date: Thu, 15 Oct 2026 10:59:00 +0300 Subject: [PATCH 10/17] feat: let tasks require a written answer --- migrations/0002_bouncy_trauma.sql | 2 + migrations/meta/0002_snapshot.json | 1419 +++++++++++++++++++ migrations/meta/_journal.json | 7 + src/actions/proof/schema.ts | 1 + src/actions/task/schema.ts | 1 + src/app/(member)/tasks/[taskId]/page.tsx | 9 +- src/app/(member)/tasks/page.tsx | 1 + src/app/admin/review/page.tsx | 1 + src/app/admin/tasks/page.tsx | 1 + src/components/admin/task/fields.tsx | 13 +- src/components/admin/task/model.ts | 1 + src/components/admin/task/workspaceView.tsx | 1 + src/components/proof/form.tsx | 19 +- src/components/proof/panel.tsx | 1 + src/components/review/card.tsx | 6 + src/components/review/model.ts | 1 + src/components/task/list.tsx | 2 + src/components/task/row.tsx | 10 +- src/core/ports/proof.ts | 1 + src/core/ports/task.ts | 1 + src/core/services/proof.ts | 7 + src/core/services/task.ts | 2 + src/domain/proof.ts | 1 + src/domain/task.ts | 1 + src/infra/db/proof/map.ts | 1 + src/infra/db/proof/model.ts | 1 + src/infra/db/proof/submit.ts | 6 +- src/infra/db/task/map.ts | 1 + src/infra/db/task/model.ts | 1 + tests/components/taskWorkspace.test.ts | 2 + tests/integration/authorization.test.ts | 2 + tests/integration/backup.test.ts | 1 + tests/integration/feed.test.ts | 1 + tests/integration/notifications.test.ts | 1 + tests/integration/photo.test.ts | 2 + tests/integration/proofs.test.ts | 2 + tests/integration/taskManagement.test.ts | 3 + tests/integration/textAnswer.test.ts | 101 ++ 38 files changed, 1623 insertions(+), 11 deletions(-) create mode 100644 migrations/0002_bouncy_trauma.sql create mode 100644 migrations/meta/0002_snapshot.json create mode 100644 tests/integration/textAnswer.test.ts diff --git a/migrations/0002_bouncy_trauma.sql b/migrations/0002_bouncy_trauma.sql new file mode 100644 index 0000000..1d198d9 --- /dev/null +++ b/migrations/0002_bouncy_trauma.sql @@ -0,0 +1,2 @@ +ALTER TABLE "proofs" ADD COLUMN "text_answer" text;--> statement-breakpoint +ALTER TABLE "tasks" ADD COLUMN "text_required" boolean DEFAULT false NOT NULL; \ No newline at end of file diff --git a/migrations/meta/0002_snapshot.json b/migrations/meta/0002_snapshot.json new file mode 100644 index 0000000..c3a0acb --- /dev/null +++ b/migrations/meta/0002_snapshot.json @@ -0,0 +1,1419 @@ +{ + "id": "1c7121a0-d880-489d-b24f-bb72ae6f2ffc", + "prevId": "13ba9111-2775-441c-b7b5-d35945a40a27", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.categories": { + "name": "categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "categories_name_key": { + "name": "categories_name_key", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "categories_slug_key": { + "name": "categories_slug_key", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.proof_photos": { + "name": "proof_photos", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "proof_id": { + "name": "proof_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "object_key": { + "name": "object_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size_bytes": { + "name": "size_bytes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "proof_photos_object_key_key": { + "name": "proof_photos_object_key_key", + "columns": [ + { + "expression": "object_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proof_photos_proof_idx": { + "name": "proof_photos_proof_idx", + "columns": [ + { + "expression": "proof_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "proof_photos_proof_id_proofs_id_fk": { + "name": "proof_photos_proof_id_proofs_id_fk", + "tableFrom": "proof_photos", + "tableTo": "proofs", + "columnsFrom": [ + "proof_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.proof_review_requests": { + "name": "proof_review_requests", + "schema": "", + "columns": { + "proof_id": { + "name": "proof_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "reviewer_id": { + "name": "reviewer_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "proof_review_requests_reviewer_idx": { + "name": "proof_review_requests_reviewer_idx", + "columns": [ + { + "expression": "reviewer_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "proof_review_requests_proof_id_proofs_id_fk": { + "name": "proof_review_requests_proof_id_proofs_id_fk", + "tableFrom": "proof_review_requests", + "tableTo": "proofs", + "columnsFrom": [ + "proof_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "proof_review_requests_reviewer_id_users_id_fk": { + "name": "proof_review_requests_reviewer_id_users_id_fk", + "tableFrom": "proof_review_requests", + "tableTo": "users", + "columnsFrom": [ + "reviewer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "proof_review_requests_proof_id_reviewer_id_pk": { + "name": "proof_review_requests_proof_id_reviewer_id_pk", + "columns": [ + "proof_id", + "reviewer_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.proofs": { + "name": "proofs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "policy": { + "name": "policy", + "type": "task_policy", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "proof_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "text_answer": { + "name": "text_answer", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rejection_reason": { + "name": "rejection_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "reviewed_at": { + "name": "reviewed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "reviewed_by": { + "name": "reviewed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "proofs_one_pending_per_user": { + "name": "proofs_one_pending_per_user", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"proofs\".\"status\" = 'pending'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "proofs_single_winner_exclusive": { + "name": "proofs_single_winner_exclusive", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "(\"proofs\".\"policy\" = 'single_winner' and \"proofs\".\"status\" in ('pending', 'approved'))", + "concurrently": false, + "method": "btree", + "with": {} + }, + "proofs_one_approved_per_user": { + "name": "proofs_one_approved_per_user", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "(\"proofs\".\"policy\" = 'one_per_user' and \"proofs\".\"status\" = 'approved')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "proofs_status_idx": { + "name": "proofs_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proofs_user_idx": { + "name": "proofs_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proofs_task_user_status_idx": { + "name": "proofs_task_user_status_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proofs_feed_idx": { + "name": "proofs_feed_idx", + "columns": [ + { + "expression": "reviewed_at", + "isExpression": false, + "asc": false, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"proofs\".\"status\" = 'approved'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "proofs_task_id_tasks_id_fk": { + "name": "proofs_task_id_tasks_id_fk", + "tableFrom": "proofs", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "proofs_user_id_users_id_fk": { + "name": "proofs_user_id_users_id_fk", + "tableFrom": "proofs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "proofs_reviewed_by_users_id_fk": { + "name": "proofs_reviewed_by_users_id_fk", + "tableFrom": "proofs", + "tableTo": "users", + "columnsFrom": [ + "reviewed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.proof_comments": { + "name": "proof_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "proof_id": { + "name": "proof_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "proof_comments_proof_idx": { + "name": "proof_comments_proof_idx", + "columns": [ + { + "expression": "proof_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proof_comments_user_recent_idx": { + "name": "proof_comments_user_recent_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "proof_comments_proof_id_proofs_id_fk": { + "name": "proof_comments_proof_id_proofs_id_fk", + "tableFrom": "proof_comments", + "tableTo": "proofs", + "columnsFrom": [ + "proof_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "proof_comments_user_id_users_id_fk": { + "name": "proof_comments_user_id_users_id_fk", + "tableFrom": "proof_comments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.proof_likes": { + "name": "proof_likes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "proof_id": { + "name": "proof_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "proof_likes_proof_user_key": { + "name": "proof_likes_proof_user_key", + "columns": [ + { + "expression": "proof_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "proof_likes_proof_id_proofs_id_fk": { + "name": "proof_likes_proof_id_proofs_id_fk", + "tableFrom": "proof_likes", + "tableTo": "proofs", + "columnsFrom": [ + "proof_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "proof_likes_user_id_users_id_fk": { + "name": "proof_likes_user_id_users_id_fk", + "tableFrom": "proof_likes", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "ipa_unique_id": { + "name": "ipa_unique_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "uid": { + "name": "uid", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "excluded": { + "name": "excluded", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "freeipa_groups": { + "name": "freeipa_groups", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "users_ipa_unique_id_key": { + "name": "users_ipa_unique_id_key", + "columns": [ + { + "expression": "ipa_unique_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_uid_key": { + "name": "users_uid_key", + "columns": [ + { + "expression": "uid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.notifications": { + "name": "notifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "recipient_user_id": { + "name": "recipient_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "notification_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "proof_id": { + "name": "proof_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "notifications_recipient_idx": { + "name": "notifications_recipient_idx", + "columns": [ + { + "expression": "recipient_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "notifications_unread_idx": { + "name": "notifications_unread_idx", + "columns": [ + { + "expression": "recipient_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"notifications\".\"read_at\" is null", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "notifications_recipient_user_id_users_id_fk": { + "name": "notifications_recipient_user_id_users_id_fk", + "tableFrom": "notifications", + "tableTo": "users", + "columnsFrom": [ + "recipient_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_proof_id_proofs_id_fk": { + "name": "notifications_proof_id_proofs_id_fk", + "tableFrom": "notifications", + "tableTo": "proofs", + "columnsFrom": [ + "proof_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_task_id_tasks_id_fk": { + "name": "notifications_task_id_tasks_id_fk", + "tableFrom": "notifications", + "tableTo": "tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.points_ledger": { + "name": "points_ledger", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "proof_id": { + "name": "proof_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "points": { + "name": "points", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "awarded_at": { + "name": "awarded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "points_ledger_proof_key": { + "name": "points_ledger_proof_key", + "columns": [ + { + "expression": "proof_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "points_ledger_user_idx": { + "name": "points_ledger_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "points_ledger_user_id_users_id_fk": { + "name": "points_ledger_user_id_users_id_fk", + "tableFrom": "points_ledger", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "points_ledger_proof_id_proofs_id_fk": { + "name": "points_ledger_proof_id_proofs_id_fk", + "tableFrom": "points_ledger", + "tableTo": "proofs", + "columnsFrom": [ + "proof_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "category_id": { + "name": "category_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "points": { + "name": "points", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "policy": { + "name": "policy", + "type": "task_policy", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "cooldown_seconds": { + "name": "cooldown_seconds", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "photo_required": { + "name": "photo_required", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "photo_instructions": { + "name": "photo_instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "text_required": { + "name": "text_required", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "tasks_category_idx": { + "name": "tasks_category_idx", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tasks_active_idx": { + "name": "tasks_active_idx", + "columns": [ + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tasks_active_category_title_idx": { + "name": "tasks_active_category_title_idx", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "title", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"tasks\".\"archived_at\" is null", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tasks_category_id_categories_id_fk": { + "name": "tasks_category_id_categories_id_fk", + "tableFrom": "tasks", + "tableTo": "categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.push_subscriptions": { + "name": "push_subscriptions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "p256dh": { + "name": "p256dh", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "auth": { + "name": "auth", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "push_subscriptions_endpoint_key": { + "name": "push_subscriptions_endpoint_key", + "columns": [ + { + "expression": "endpoint", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "push_subscriptions_user_idx": { + "name": "push_subscriptions_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "push_subscriptions_user_id_users_id_fk": { + "name": "push_subscriptions_user_id_users_id_fk", + "tableFrom": "push_subscriptions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.photo_backups": { + "name": "photo_backups", + "schema": "", + "columns": { + "object_key": { + "name": "object_key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "backed_up_at": { + "name": "backed_up_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "missing": { + "name": "missing", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.proof_status": { + "name": "proof_status", + "schema": "public", + "values": [ + "pending", + "approved", + "rejected" + ] + }, + "public.notification_type": { + "name": "notification_type", + "schema": "public", + "values": [ + "proof_submitted", + "review_requested", + "proof_approved", + "proof_rejected", + "proof_commented" + ] + }, + "public.task_policy": { + "name": "task_policy", + "schema": "public", + "values": [ + "single_winner", + "one_per_user", + "repeatable" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json index 6e3bb7c..460d2d5 100644 --- a/migrations/meta/_journal.json +++ b/migrations/meta/_journal.json @@ -15,6 +15,13 @@ "when": 1791971382062, "tag": "0001_misty_shatterstar", "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1792049123424, + "tag": "0002_bouncy_trauma", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/actions/proof/schema.ts b/src/actions/proof/schema.ts index 355957d..7b0d222 100644 --- a/src/actions/proof/schema.ts +++ b/src/actions/proof/schema.ts @@ -3,6 +3,7 @@ import { photoLimits } from "~/config/photo"; export const proofSchema = z.object({ taskId: z.string().min(1), + textAnswer: z.string().trim().max(2000), objectKeys: z.array(z.string().min(1)).max(photoLimits.maxPhotosPerProof), reviewerIds: z.array(z.uuid()).max(10), }); diff --git a/src/actions/task/schema.ts b/src/actions/task/schema.ts index f90191a..5cc080b 100644 --- a/src/actions/task/schema.ts +++ b/src/actions/task/schema.ts @@ -11,6 +11,7 @@ export const taskSchema = z.object({ cooldownSeconds: z.number("Enter a number.").int().min(0, "Cooldown cannot be negative."), photoRequired: z.boolean(), photoInstructions: z.string().trim().max(200), + textRequired: z.boolean(), }) satisfies z.ZodType; export const createTaskSchema = z.object({ task: taskSchema }); diff --git a/src/app/(member)/tasks/[taskId]/page.tsx b/src/app/(member)/tasks/[taskId]/page.tsx index e80c97e..0b302b6 100644 --- a/src/app/(member)/tasks/[taskId]/page.tsx +++ b/src/app/(member)/tasks/[taskId]/page.tsx @@ -1,4 +1,4 @@ -import { Camera, ChevronLeft } from "lucide-react"; +import { Camera, ChevronLeft, PenLine } from "lucide-react"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; @@ -64,6 +64,12 @@ const TaskPage: FC> = async ({ params }) => { photo required )} + {task.textRequired && ( + + + written answer + + )}
    {task.description && ( @@ -80,6 +86,7 @@ const TaskPage: FC> = async ({ params }) => { points={task.points} photoRequired={task.photoRequired} photoInstructions={task.photoInstructions} + textRequired={task.textRequired} reviewers={reviewers} status={item.userProofStatus} unavailable={describeUnavailability( diff --git a/src/app/(member)/tasks/page.tsx b/src/app/(member)/tasks/page.tsx index 440e875..6a82546 100644 --- a/src/app/(member)/tasks/page.tsx +++ b/src/app/(member)/tasks/page.tsx @@ -22,6 +22,7 @@ const TasksPage: FC = async () => { points: item.task.points, policy: describeTaskPolicy(item.task.policy), photoRequired: item.task.photoRequired, + textRequired: item.task.textRequired, availability: taskAvailability(item, now), cooldownUntil: item.userCooldownUntil && formatDate(item.userCooldownUntil), })); diff --git a/src/app/admin/review/page.tsx b/src/app/admin/review/page.tsx index 8232ce5..99d8047 100644 --- a/src/app/admin/review/page.tsx +++ b/src/app/admin/review/page.tsx @@ -33,6 +33,7 @@ const toPendingView = ( points: taskPoints, userDisplayName, submittedAt: proof.submittedAt.toISOString(), + textAnswer: proof.textAnswer, photoUrls: photos.map((item) => `/api/photos/${proof.id}/${item.id}`), requestedReviewers, requestedFromMe: requestedReviewers.some((reviewer) => reviewer.id === user.id), diff --git a/src/app/admin/tasks/page.tsx b/src/app/admin/tasks/page.tsx index d49de8a..0a7d10e 100644 --- a/src/app/admin/tasks/page.tsx +++ b/src/app/admin/tasks/page.tsx @@ -20,6 +20,7 @@ const toTaskView = ({ task, categoryName }: { task: Task; categoryName: string } cooldownSeconds: task.cooldownSeconds, photoRequired: task.photoRequired, photoInstructions: task.photoInstructions, + textRequired: task.textRequired, archived: task.archivedAt !== null, }); diff --git a/src/components/admin/task/fields.tsx b/src/components/admin/task/fields.tsx index 8bbf073..b958473 100644 --- a/src/components/admin/task/fields.tsx +++ b/src/components/admin/task/fields.tsx @@ -68,9 +68,14 @@ export const TaskFields: FC = ({ categories }) => { )}
    - - {(control) => } - +
    + + {(control) => } + + + {(control) => } + +
    {photoRequired && ( {(control) => } @@ -95,6 +100,7 @@ export function taskValues( cooldownSeconds: task.cooldownSeconds ?? 86_400, photoRequired: task.photoRequired, photoInstructions: task.photoInstructions ?? "", + textRequired: task.textRequired, }; } @@ -107,5 +113,6 @@ export function taskValues( cooldownSeconds: 86_400, photoRequired: false, photoInstructions: "", + textRequired: false, }; } diff --git a/src/components/admin/task/model.ts b/src/components/admin/task/model.ts index b6eadef..4ad5fc3 100644 --- a/src/components/admin/task/model.ts +++ b/src/components/admin/task/model.ts @@ -11,6 +11,7 @@ export interface TaskView { cooldownSeconds: number | null; photoRequired: boolean; photoInstructions: string | null; + textRequired: boolean; archived: boolean; } diff --git a/src/components/admin/task/workspaceView.tsx b/src/components/admin/task/workspaceView.tsx index 5c0f587..e508c5f 100644 --- a/src/components/admin/task/workspaceView.tsx +++ b/src/components/admin/task/workspaceView.tsx @@ -122,6 +122,7 @@ export const TaskWorkspaceView: FC = ({ policy={describeTaskPolicy(task.policy)} points={task.points} photoRequired={task.photoRequired} + textRequired={task.textRequired} muted={task.archived} status={task.archived && Archived} aria-label={`Edit ${task.title}`} diff --git a/src/components/proof/form.tsx b/src/components/proof/form.tsx index 23dc195..80564ae 100644 --- a/src/components/proof/form.tsx +++ b/src/components/proof/form.tsx @@ -9,8 +9,8 @@ import type { PublicUserView } from "~/domain/user"; import { useActionForm } from "~/lib/form"; import { UserAvatar } from "../ui/avatar"; import { Button } from "../ui/button"; -import { Checkbox } from "../ui/formControls"; -import { Form, FormActions, FormError } from "../ui/form"; +import { Checkbox, Textarea } from "../ui/formControls"; +import { Field, Form, FormActions, FormError } from "../ui/form"; import { PhotoPicker } from "./photoPicker"; interface Props { @@ -18,6 +18,7 @@ interface Props { points: number; photoRequired: boolean; photoInstructions: string | null; + textRequired: boolean; reviewers: ReadonlyArray; onSubmitted: () => void; } @@ -27,6 +28,7 @@ export const ProofForm: FC = ({ points, photoRequired, photoInstructions, + textRequired, reviewers, onSubmitted, }) => { @@ -34,16 +36,18 @@ export const ProofForm: FC = ({ const { form, submit, pending } = useActionForm(proofSchema, submitProofAction, { defaultValues: { taskId, + textAnswer: "", objectKeys: [], reviewerIds: [], }, onSuccess: onSubmitted, }); - const objectKeys = useWatch({ + const [objectKeys, textAnswer] = useWatch({ control: form.control, - name: "objectKeys", + name: ["objectKeys", "textAnswer"], }); const missingPhotos = photoRequired && objectKeys.length === 0; + const missingText = textRequired && textAnswer.trim().length === 0; return (
    = ({ className="gap-5 rounded-2xl border border-border bg-card p-4 shadow-card sm:p-5" >

    Submit proof

    + {textRequired && ( + + {(control) =>