Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: review matching and review page overhaul #243

Closed
11 changes: 4 additions & 7 deletions app/members/components/Columns.tsx → app/members/columns.tsx
BehsadRiemer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";
BehsadRiemer marked this conversation as resolved.
Show resolved Hide resolved

import * as React from "react";
import { ColumnDef } from "@tanstack/react-table";
import { MoreHorizontal } from "lucide-react";

import { Button } from "@components/ui/button";
Expand All @@ -11,14 +12,10 @@ import {
DropdownMenuLabel,
DropdownMenuTrigger,
} from "@components/ui/dropdown-menu";
import { DataTableColumnHeader } from "./DataTabelHeader";
import { DataTableColumnHeader } from "./components/DataTableHeader";
import { SpaceRole } from "@prisma/client";
import { Avatar, AvatarFallback, AvatarImage } from "@components/ui/avatar";
import { RowUser } from "./DataTableTypes";

export type ExtendedColumnDef<TData, TUnknown> = ColumnDef<TData, TUnknown> & {
label: string;
};
import { ExtendedColumnDef, RowUser } from "./components/DataTableTypes";

export const columns: ExtendedColumnDef<RowUser, unknown>[] = [
{
Expand Down
23 changes: 14 additions & 9 deletions app/members/components/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from "react";
import {
ColumnFiltersState,
SortingState,
TableOptions,
VisibilityState,
flexRender,
getCoreRowModel,
Expand All @@ -24,15 +25,19 @@ import {
TableRow,
} from "@components/ui/table";

import { columns } from "./Columns";
import { RowUser, ColumnData } from "./DataTableTypes";
import { ColumnDefs, ExtendedColumnDef } from "./DataTableTypes";

interface DataTableProps {
rowData: RowUser[];
columnData: ColumnData;
interface DataTableProps<RowType> {
rowData: RowType[];
columnData: ExtendedColumnDef<RowType, unknown>[];
columnDefs: ColumnDefs;
}

export function DataTable({ rowData, columnData }: DataTableProps) {
export interface CustomTableOptions<RowType> extends TableOptions<unknown> {
columnData: ExtendedColumnDef<RowType, unknown>[];
}

export function DataTable<RowType>({ rowData, columnData, columnDefs }: DataTableProps<RowType>) {
const [data] = React.useState(rowData);
const [sorting, setSorting] = React.useState<SortingState>([]);
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
Expand All @@ -45,7 +50,7 @@ export function DataTable({ rowData, columnData }: DataTableProps) {

const table = useReactTable({
data,
columns,
columns: columnData,
onSortingChange: setSorting,
onColumnFiltersChange: setColumnFilters,
getCoreRowModel: getCoreRowModel(),
Expand All @@ -64,7 +69,7 @@ export function DataTable({ rowData, columnData }: DataTableProps) {

return (
<div className="space-y-4">
<DataTableToolbar table={table} columnData={columnData} />
<DataTableToolbar table={table} columnDefs={columnDefs} />
<div className="rounded-md border">
<Table>
<TableHeader>
Expand Down Expand Up @@ -105,7 +110,7 @@ export function DataTable({ rowData, columnData }: DataTableProps) {
) : (
<TableRow>
<TableCell
colSpan={columns.length}
colSpan={columnData.length}
className="h-24 text-center"
>
{!error ? (
Expand Down
16 changes: 8 additions & 8 deletions app/members/components/DataTableToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import { DataTableViewOptions } from "./DataTableViewOptions";

import { DataTableFacetedFilter } from "./DataTableFacetedFilter";
import React, { useState, useEffect } from "react";
import { ColumnData, Option, RowUser } from "./DataTableTypes";
import { ExtendedColumnDef } from "./Columns";
import { ColumnDefs, ExtendedColumnDef, Option, RowUser } from "./DataTableTypes";


interface DataTableToolbarProps<TData> {
table: Table<TData>;
columnData: ColumnData;
columnDefs: ColumnDefs;
}

export function DataTableToolbar<TData>({
table,
columnData,
columnDefs,
}: DataTableToolbarProps<TData>) {
const isFiltered = table.getState().columnFilters.length > 0;
const [departments, setDepartments] = useState<Option[]>([]);
const [roles, setRoles] = useState<Option[]>([]);
const [positions, setPositions] = useState<Option[]>([]);

useEffect(() => {
setDepartments(columnData.departments);
setRoles(columnData.roles);
setPositions(columnData.positions);
}, [columnData.departments, columnData.positions, columnData.roles]);
setDepartments(columnDefs.departments);
setRoles(columnDefs.roles);
setPositions(columnDefs.positions);
}, [columnDefs.departments, columnDefs.positions, columnDefs.roles]);

// Remove the unused getSelectedRows function
// const getSelectedRows = () => {
Expand Down
7 changes: 6 additions & 1 deletion app/members/components/DataTableTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { SpaceRole } from "@prisma/client";
import { ColumnDef } from "@tanstack/react-table";

export type ExtendedColumnDef<TData, TUnknown> = ColumnDef<TData, TUnknown> & {
label: string;
};

export interface Option {
label: string | number;
Expand All @@ -15,7 +20,7 @@ export interface RowUser {
currentDepartmentPosition: string;
}

export interface ColumnData {
export interface ColumnDefs {
departments: Option[];
roles: Option[];
positions: Option[];
Expand Down
5 changes: 2 additions & 3 deletions app/members/components/DataTableViewOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
DropdownMenuLabel,
DropdownMenuSeparator,
} from "@components/ui/dropdown-menu";
import { ExtendedColumnDef } from "./Columns";
import { RowUser } from "./DataTableTypes";
import { ExtendedColumnDef } from "./DataTableTypes";

interface DataTableViewOptionsProps<TData> {
table: Table<TData>;
Expand Down Expand Up @@ -48,7 +47,7 @@ export function DataTableViewOptions<TData>({
onCheckedChange={(value) => column.toggleVisibility(!!value)}
>
{
(column.columnDef as ExtendedColumnDef<RowUser, unknown>)
(column.columnDef as ExtendedColumnDef<unknown, unknown>)
.label
}
</DropdownMenuCheckboxItem>
Expand Down
11 changes: 8 additions & 3 deletions app/members/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { DataTable } from "./components/DataTable";
import { RowUser } from "./components/DataTableTypes";
import db from "server/db";
import { DepartmentRole, SpaceRole } from "@prisma/client";
import { getServerAuthSession } from "server/auth";
import { redirect } from "next/navigation";
import { columns } from "./columns";
import { RowUser } from "./components/DataTableTypes";
import Breadcrumbs from "@components/ui/breadcrumbs";

export default async function MembersPage() {
Expand Down Expand Up @@ -53,7 +54,7 @@ export default async function MembersPage() {
value: position[1],
}));

const columnData = {
const columnDefs = {
departments: departments,
roles: roles,
positions: positions,
Expand All @@ -68,7 +69,11 @@ export default async function MembersPage() {
</h1>
<p className="text-muted-foreground">Manage and list members</p>
</div>
<DataTable rowData={profiles} columnData={columnData}></DataTable>
<DataTable<RowUser>
rowData={profiles}
columnData={columns}
columnDefs={columnDefs}
></DataTable>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ export default async function Review({ params }: ReviewProps) {
const session = await getServerAuthSession();
if (!session?.user?.id) redirect("/auth");


const review = await db.review.findUnique({
where: {
id: Number(params.review_id),
user: { id: session.user.id },
},
include: { application: true, questionnaire: true },
include: { application: true, questionnaire: true, user: true },
});

if (!review) redirect("/404");

const opportunityTitle = db.opportunity.findUnique({
where: {
id: review?.application.opportunityId,
},
}).then((opportunity) => opportunity?.title);

if (!review) redirect("/404");

const questions = review.questionnaire.questions as Question[];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export const ReviewForm = ({
review,
opportunityTitle,
}: ReviewFormProps) => {
const applicationFields = (application.content as Tally).data.fields;
const applicationFields = (application?.content as Tally).data?.fields ?? [];

const form = useForm<Question["value"][]>();
const defaultValues = (review.content as Question[]).map((question) => {
return question.value;
return question.value;
});
// Workaround to set default values
defaultValues.forEach((value, index) => {
Expand All @@ -46,11 +46,15 @@ export const ReviewForm = ({
const onSubmit: SubmitHandler<Question["value"][]> = (data) => {
const content = QuestionSchema.array().parse(
questions.map((question, index) => ({
...question,
value: data[index],
...question,
})),
);

console.log(questions);
console.log(data);
console.log(content);

toast.promise(
updateMutation
.mutateAsync({
Expand Down
25 changes: 13 additions & 12 deletions app/opportunities/[opportunity_id]/review/columns.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
"use client";

import { ColumnDef } from "@tanstack/react-table";
import { DataTableColumnHeader } from "@components/ui/data-table-column-header";
import {
Application,
Questionnaire,
Review as PrismaReview,
Phase,
} from "@prisma/client";
import { RowType } from "./components/DataTableTypes";

import { Button } from "@components/ui/button";
import Link from "next/link";
import { Edit } from "lucide-react";
import { DeleteAlertDialog } from "./components/review-altert-dialog";
import { ExtendedColumnDef } from "./components/DataTableTypes";

export type Review = PrismaReview & {
application: Application;
} & { questionnaire: Questionnaire & { phase: Phase } };

export const columns: ColumnDef<Review>[] = [
export const columns: ExtendedColumnDef<RowType, unknown>[] = [
{
accessorKey: "application.id",
header: "Application",
label: "Application",
},
{
accessorKey: "user.name",
header: "Reviewer",
label: "Reviewer",
},
{
accessorKey: "questionnaire.phase.name",
header: "Phase",
label: "Phase",
},
{
accessorKey: "questionnaire.name",
header: "Questionnaire",
label: "Questionnaire",
},
{
accessorKey: "status",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Status" />
),
label: "Status",
},
{
id: "actions",
label: "Actions",
cell: ({ row }) => {
const review = row.original;
return (
Expand Down
Loading
Loading