fix bug in last commit where all entities would show up on select filter instead of user entities
This commit is contained in:
@@ -2,21 +2,18 @@ import Layout from "@/components/High/Layout";
|
||||
import Button from "@/components/Low/Button";
|
||||
import Select from "@/components/Low/Select";
|
||||
import useApprovalWorkflows from "@/hooks/useApprovalWorkflows";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import { Module, ModuleTypeLabels } from "@/interfaces";
|
||||
import { ApprovalWorkflow, ApprovalWorkflowStatus, ApprovalWorkflowStatusLabel, StepTypeLabel } from "@/interfaces/approval.workflow";
|
||||
import { EntityWithRoles } from "@/interfaces/entity";
|
||||
import { Entity, EntityWithRoles } from "@/interfaces/entity";
|
||||
import { TeacherUser, User } from "@/interfaces/user";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import { mapBy, redirect, serialize } from "@/utils";
|
||||
import { redirect, serialize } from "@/utils";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { getEntitiesWithRoles } from "@/utils/entities.be";
|
||||
import { getEntities } from "@/utils/entities.be";
|
||||
import { shouldRedirectHome } from "@/utils/navigation.disabled";
|
||||
import { findAllowedEntities } from "@/utils/permissions";
|
||||
import { isAdmin } from "@/utils/users";
|
||||
import { getUsers } from "@/utils/users.be";
|
||||
import { createColumnHelper, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
|
||||
import axios, { all } from "axios";
|
||||
import axios from "axios";
|
||||
import clsx from "clsx";
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import Head from "next/head";
|
||||
@@ -36,15 +33,15 @@ export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
||||
if (shouldRedirectHome(user) || !["admin", "developer", "teacher", "corporate", "mastercorporate"].includes(user.type))
|
||||
return redirect("/")
|
||||
|
||||
const entityIDS = mapBy(user.entities, "id");
|
||||
/* const entityIDS = mapBy(user.entities, "id");
|
||||
const entities = await getEntitiesWithRoles(isAdmin(user) ? undefined : entityIDS);
|
||||
const allowedEntities = findAllowedEntities(user, entities, "view_approval_workflows");
|
||||
const allowedEntities = findAllowedEntities(user, entities, "view_approval_workflows"); */
|
||||
|
||||
return {
|
||||
props: serialize({
|
||||
user,
|
||||
teachers: await getUsers({ type: "teacher" }) as TeacherUser[],
|
||||
allowedEntities,
|
||||
userEntitiesWithLabel: await getEntities(user.entities.map(entity => entity.id)),
|
||||
}),
|
||||
};
|
||||
}, sessionOptions);
|
||||
@@ -56,7 +53,7 @@ const StatusClassNames: { [key in ApprovalWorkflowStatus]: string } = {
|
||||
};
|
||||
|
||||
type CustomStatus = ApprovalWorkflowStatus | "all";
|
||||
type CustomEntity = EntityWithRoles["label"] | "all";
|
||||
type CustomEntity = EntityWithRoles | "all";
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{
|
||||
@@ -84,22 +81,23 @@ const STATUS_OPTIONS = [
|
||||
interface Props {
|
||||
user: User,
|
||||
teachers: TeacherUser[],
|
||||
allowedEntities: EntityWithRoles[],
|
||||
userEntitiesWithLabel: Entity[],
|
||||
}
|
||||
|
||||
export default function ApprovalWorkflows({ user, teachers, allowedEntities }: Props) {
|
||||
export default function ApprovalWorkflows({ user, teachers, userEntitiesWithLabel }: Props) {
|
||||
console.log(user);
|
||||
console.log(teachers);
|
||||
console.log(allowedEntities);
|
||||
console.log(userEntitiesWithLabel);
|
||||
|
||||
|
||||
const ENTITY_OPTIONS = [
|
||||
{
|
||||
label: "All",
|
||||
value: "all",
|
||||
filter: (x: ApprovalWorkflow) => true,
|
||||
filter: (x: ApprovalWorkflow) =>
|
||||
userEntitiesWithLabel.some(entity => entity.id === x.entityId),
|
||||
},
|
||||
...allowedEntities
|
||||
...userEntitiesWithLabel
|
||||
.map(entity => ({
|
||||
label: entity.label,
|
||||
value: entity.id,
|
||||
@@ -192,6 +190,14 @@ export default function ApprovalWorkflows({ user, teachers, allowedEntities }: P
|
||||
</span>
|
||||
),
|
||||
}),
|
||||
columnHelper.accessor("entityId", {
|
||||
header: "ENTITY",
|
||||
cell: (info) => (
|
||||
<span className="font-medium">
|
||||
{userEntitiesWithLabel.find((entity) => entity.id === info.getValue())?.label}
|
||||
</span>
|
||||
),
|
||||
}),
|
||||
columnHelper.accessor("steps", {
|
||||
id: "currentApprovers",
|
||||
header: "CURRENT APPROVERS",
|
||||
@@ -297,7 +303,7 @@ export default function ApprovalWorkflows({ user, teachers, allowedEntities }: P
|
||||
<Select
|
||||
options={ENTITY_OPTIONS}
|
||||
value={ENTITY_OPTIONS.find((x) => x.value === entityFilter)}
|
||||
onChange={(value) => setEntityFilter((value?.value as string) ?? undefined)}
|
||||
onChange={(value) => setEntityFilter((value?.value as CustomEntity) ?? undefined)}
|
||||
isClearable
|
||||
placeholder="Entity..."
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user