Skip to content

Commit

Permalink
Update BenchmarkListElement to show current task assignment status
Browse files Browse the repository at this point in the history
  • Loading branch information
francisli committed Feb 5, 2025
1 parent 136b9c3 commit 8ac4c6b
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 22 deletions.
28 changes: 27 additions & 1 deletion src/backend/routers/iep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,33 @@ export const iep = router({
const result = await req.ctx.db
.selectFrom("benchmark")
.where("goal_id", "=", goal_id)
.selectAll()
.select((eb) => [
"benchmark.benchmark_id",
"benchmark.status",
"benchmark.description",
"benchmark.instructions",
"benchmark.materials",
"benchmark.metric_name",
"benchmark.setup",
"benchmark.frequency",
"benchmark.number_of_trials",
"benchmark.attempts_per_trial",
"benchmark.trial_count",
"benchmark.baseline_level",
"benchmark.current_level",
"benchmark.target_level",
"benchmark.created_at",
"benchmark.due_date",
"benchmark.goal_id",
jsonArrayFrom(
eb
.selectFrom("user")
.innerJoin("task", "task.assignee_id", "user.user_id")
.whereRef("task.benchmark_id", "=", "benchmark.benchmark_id")
.orderBy("user.first_name")
.selectAll()
).as("assignees"),
])
.execute();

return result;
Expand Down
10 changes: 9 additions & 1 deletion src/client/lib/trpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { createTRPCReact } from "@trpc/react-query";
import {
createTRPCReact,
type inferReactQueryProcedureOptions,
} from "@trpc/react-query";
import type { inferRouterInputs, inferRouterOutputs } from "@trpc/server";
import { AppRouter } from "@/backend/routers/_app";

export type ReactQueryOptions = inferReactQueryProcedureOptions<AppRouter>;
export type RouterInputs = inferRouterInputs<AppRouter>;
export type RouterOutputs = inferRouterOutputs<AppRouter>;

export const trpc = createTRPCReact<AppRouter>();
55 changes: 55 additions & 0 deletions src/components/benchmarks/BenchmarkAssignees.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Box, Button, Stack } from "@mui/material";
import { BenchmarkWithAssignees } from "@/types/global";
import { format } from "date-fns";

import $button from "@/components/design_system/button/Button.module.css";

const BenchmarkAssignees = ({
benchmark,
onAssign,
}: {
benchmark: BenchmarkWithAssignees;
onAssign: () => void;
}) => {
const { assignees, due_date, trial_count } = benchmark;

return (
<>
{assignees.length === 0 && (
<Button
className={$button.secondary}
onClick={() => onAssign()}
sx={{
paddingTop: ".4rem !important",
paddingBottom: ".4rem !important",
paddingLeft: ".4rem !important",
paddingRight: ".4rem !important",
}}
>
Assign staff
</Button>
)}
{!!assignees.length && (
<Stack direction="row">
<Stack>
{assignees.map((u) => (
<Box key={u.user_id} fontWeight="bold" textAlign="left">
{u.first_name} {u.last_name}
</Box>
))}
{due_date && <Box>Until {format(new Date(due_date), "MMM d")}</Box>}
{!due_date && !!trial_count && <Box>{trial_count} times</Box>}
{!due_date && !trial_count && <Box>Until unassigned</Box>}
</Stack>
<Box>
<Button className={$button.tertiary} onClick={() => onAssign()}>
Change
</Button>
</Box>
</Stack>
)}
</>
);
};

export default BenchmarkAssignees;
29 changes: 12 additions & 17 deletions src/components/benchmarks/BenchmarkListElement.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Benchmark } from "@/types/global";
import { BenchmarkWithAssignees } from "@/types/global";
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Divider from "@mui/material/Divider";
import ContentPasteIcon from "@mui/icons-material/ContentPaste";
import { useState, type ReactNode } from "react";
import { BenchmarkAssignmentModal } from "./BenchmarkAssignmentModal";
import $button from "@/components/design_system/button/Button.module.css";
import { format } from "date-fns";
import Typography from "@mui/material/Typography";

import { BenchmarkAssignmentModal } from "./BenchmarkAssignmentModal";
import BenchmarkAssignees from "./BenchmarkAssignees";

interface BenchmarkProps {
benchmark: Benchmark;
benchmark: BenchmarkWithAssignees;
index?: number;
}

Expand Down Expand Up @@ -112,6 +115,12 @@ const BenchmarkListElement = ({ benchmark, index }: BenchmarkProps) => {
{" "}
{benchmark?.number_of_trials || "N/A"}
</Info>
<Info description={"STAFF"}>
<BenchmarkAssignees
benchmark={benchmark}
onAssign={() => setIsAssignmentModalOpen(true)}
/>
</Info>
<Info description="DATA">
<Box
sx={{
Expand Down Expand Up @@ -157,20 +166,6 @@ const BenchmarkListElement = ({ benchmark, index }: BenchmarkProps) => {
</Box>
</Box>
</Info>
<Info description={"STAFF"}>
<Button
className={$button.secondary}
onClick={() => setIsAssignmentModalOpen(true)}
sx={{
paddingTop: ".4rem !important",
paddingBottom: ".4rem !important",
paddingLeft: ".4rem !important",
paddingRight: ".4rem !important",
}}
>
Assign
</Button>
</Info>
</Box>
</Box>
<BenchmarkAssignmentModal
Expand Down
11 changes: 8 additions & 3 deletions src/pages/students/[student_id]/goals/[goal_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ const GoalPage = () => {
{ student_id: student_id },
{ enabled: Boolean(student_id), retry: false }
);
const { data: goals = [] } = trpc.iep.getGoals.useQuery({
iep_id: activeIep?.iep_id || "",
});
const { data: goals = [] } = trpc.iep.getGoals.useQuery(
{
iep_id: activeIep?.iep_id || "",
},
{
enabled: Boolean(activeIep),
}
);

const { data: goal } = trpc.iep.getGoal.useQuery(
{ goal_id: goal_id },
Expand Down
5 changes: 5 additions & 0 deletions src/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { SelectableForTable } from "zapatos/schema";

export type Goal = SelectableForTable<"goal">;
export type Benchmark = SelectableForTable<"benchmark">;
export type User = SelectableForTable<"user">;
export type ChangeEvent = React.ChangeEvent<HTMLInputElement>;
export type FormEvent = React.FormEvent<HTMLFormElement>;

export type SortProperty = "first_name" | "created_at";
export type SortDirection = "asc" | "desc";

export interface BenchmarkWithAssignees extends Benchmark {
assignees: User[];
}

export interface TaskData {
task_id: string;
first_name: string;
Expand Down

0 comments on commit 8ac4c6b

Please sign in to comment.