From d5bffc9baddb4fa5efbadf2979e500e95ce3ab68 Mon Sep 17 00:00:00 2001 From: Joao Correia Date: Sun, 9 Feb 2025 18:10:59 +0000 Subject: [PATCH] Add pagination to approval workflows table and change module styling to match project colors. --- src/pages/approval-workflows/index.tsx | 65 +++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/src/pages/approval-workflows/index.tsx b/src/pages/approval-workflows/index.tsx index 58d4e54e..07bfc513 100644 --- a/src/pages/approval-workflows/index.tsx +++ b/src/pages/approval-workflows/index.tsx @@ -1,24 +1,22 @@ import Tip from "@/components/ApprovalWorkflows/Tip"; -import Layout from "@/components/High/Layout"; import Button from "@/components/Low/Button"; import Input from "@/components/Low/Input"; import Select from "@/components/Low/Select"; import useApprovalWorkflows from "@/hooks/useApprovalWorkflows"; -import { useAllowedEntities, useAllowedEntitiesSomePermissions, useEntityPermission } from "@/hooks/useEntityPermissions"; import { Module, ModuleTypeLabels } from "@/interfaces"; import { ApprovalWorkflow, ApprovalWorkflowStatus, ApprovalWorkflowStatusLabel, StepTypeLabel } from "@/interfaces/approval.workflow"; -import { Entity, EntityWithRoles } from "@/interfaces/entity"; +import { EntityWithRoles } from "@/interfaces/entity"; import { User } from "@/interfaces/user"; import { sessionOptions } from "@/lib/session"; import { mapBy, redirect, serialize } from "@/utils"; import { requestUser } from "@/utils/api"; import { getApprovalWorkflows } from "@/utils/approval.workflows.be"; -import { getEntities, getEntitiesWithRoles } from "@/utils/entities.be"; +import { getEntitiesWithRoles } from "@/utils/entities.be"; import { shouldRedirectHome } from "@/utils/navigation.disabled"; import { doesEntityAllow, findAllowedEntities } from "@/utils/permissions"; import { isAdmin } from "@/utils/users"; import { getSpecificUsers } from "@/utils/users.be"; -import { createColumnHelper, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table"; +import { createColumnHelper, flexRender, getCoreRowModel, useReactTable, getPaginationRowModel } from "@tanstack/react-table"; import axios from "axios"; import clsx from "clsx"; import { withIronSessionSsr } from "iron-session/next"; @@ -192,7 +190,15 @@ export default function ApprovalWorkflows({ user, initialWorkflows, workflowsAss {info.getValue().map((module: Module, index: number) => ( + /* className="inline-block rounded-full px-3 py-1 text-sm font-medium bg-indigo-100 border border-indigo-300 text-indigo-900"> */ + className={clsx("inline-block rounded-full px-3 py-1 text-sm font-medium text-white", + module === "speaking" ? "bg-ielts-speaking" : + module === "reading" ? "bg-ielts-reading" : + module === "writing" ? "bg-ielts-writing" : + module === "listening" ? "bg-ielts-listening" : + module === "level" ? "bg-ielts-level" : + "bg-slate-700" + )}> {ModuleTypeLabels[module]} ))} @@ -297,10 +303,20 @@ export default function ApprovalWorkflows({ user, initialWorkflows, workflowsAss }), ]; + const [pagination, setPagination] = useState({ + pageIndex: 0, + pageSize: 10, + }); + const table = useReactTable({ data: filteredWorkflows, columns: columns, + state: { + pagination, + }, + onPaginationChange: setPagination, getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), }); return ( @@ -396,6 +412,43 @@ export default function ApprovalWorkflows({ user, initialWorkflows, workflowsAss ))} +
+ + + + Page {table.getState().pagination.pageIndex + 1} of {table.getPageCount()} + + + +
);