Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6175a7f
feat: add data table hook
G3root Aug 28, 2024
9267b5a
feat: add new data table hook
G3root Aug 28, 2024
c8ae1ac
chore: rename hook
G3root Aug 28, 2024
a0106f4
feat: add paginated hook
G3root Aug 28, 2024
99ff880
feat: add offset schema
G3root Aug 28, 2024
07f2d55
feat: use offset schema
G3root Aug 28, 2024
5c8a3d3
fix: session
G3root Aug 28, 2024
1238f71
feat: add const
G3root Aug 28, 2024
612238a
chore: fix error handling
G3root Aug 28, 2024
733b70d
chore: make header optional
G3root Aug 28, 2024
36c9a72
feat: add api client
G3root Aug 28, 2024
bcede0d
chore: add nuqs
G3root Aug 28, 2024
399b222
feat: use pagination
G3root Aug 28, 2024
b207ff0
refactor: hook
G3root Aug 29, 2024
fd34967
feat: add sort
G3root Aug 29, 2024
e7e7449
feat: add sort
G3root Aug 29, 2024
85116f3
chore: hide select
G3root Aug 29, 2024
4ddcf2a
feat: add search filter
G3root Aug 29, 2024
9851bf3
feat: refactor data
G3root Aug 29, 2024
69a423e
feat: add debounce component
G3root Aug 29, 2024
2409c0d
feat: add debounce input
G3root Aug 29, 2024
3523911
feat: add search
G3root Aug 30, 2024
8810540
fix: query
G3root Aug 30, 2024
5acdd81
feat: update tables
G3root Aug 30, 2024
6c5d5f1
feat: add seed
G3root Aug 30, 2024
2fe228f
Merge branch 'main' into pagination-table
G3root Aug 30, 2024
92d651d
chore: add tax id
G3root Sep 2, 2024
e733531
chore: upgrade trpc
G3root Sep 2, 2024
fcf2db6
feat: use new trpc
G3root Sep 2, 2024
9ca66a6
feat: add error boundary
G3root Sep 2, 2024
233b004
chore: rename loading
G3root Sep 2, 2024
33ba09b
feat: use useSuspense
G3root Sep 2, 2024
b91f92d
fix: data
G3root Sep 2, 2024
c477f15
feat: add search param hook
G3root Sep 17, 2024
160cf3d
feat: add search
G3root Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add error boundary
  • Loading branch information
G3root committed Sep 2, 2024
commit 9ca66a620625f1aadd562ff5c9ed9d685086ffb7
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-email": "2.1.6",
"react-error-boundary": "^4.0.13",
"react-hook-form": "^7.52.1",
"react-number-format": "^5.3.4",
"react-pdf": "^8.0.2",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import EmptyState from "@/components/common/empty-state";
import StakeholderDropdown from "@/components/stakeholder/stakeholder-dropdown";
import StakeholderTable from "@/components/stakeholder/stakeholder-table";
import { Card } from "@/components/ui/card";
import { UnAuthorizedState } from "@/components/ui/un-authorized-state";
import { serverAccessControl } from "@/lib/rbac/access-control";
import { withServerSession } from "@/server/auth";
import { api } from "@/trpc/server";
import { RiGroup2Fill } from "@remixicon/react";
import type { Metadata } from "next";
import { Suspense } from "react";
import { ErrorBoundary } from "react-error-boundary";

export const metadata: Metadata = {
title: "Stakeholders",
};

const StakeholdersPage = async () => {
const StakeholdersPage = async ({
searchParams,
}: {
searchParams: Record<string, string | string[] | undefined>;
}) => {
const session = await withServerSession();

const { allow } = await serverAccessControl();
const stakeholders = await allow(api.stakeholder.getStakeholders(), [
"stakeholder",
"read",
]);
const stakeholders = allow(true, ["stakeholder", "read"]);

const stakeholderDropdown = allow(
<StakeholderDropdown />,
Expand All @@ -32,18 +31,6 @@ const StakeholdersPage = async () => {
return <UnAuthorizedState />;
}

if (stakeholders.length === 0) {
return (
<EmptyState
icon={<RiGroup2Fill />}
title="You do not have any stakeholders!"
subtitle="Please click the button below to add or import stakeholders."
>
{stakeholderDropdown}
</EmptyState>
);
}

return (
<div className="flex flex-col gap-y-3">
<div className="flex items-center justify-between gap-y-3">
Expand All @@ -57,12 +44,11 @@ const StakeholdersPage = async () => {
<div>{stakeholderDropdown}</div>
</div>

<Card className="mx-auto mt-3 w-[28rem] sm:w-[38rem] md:w-full">
<StakeholderTable
companyId={session.user.companyId}
stakeholders={stakeholders}
/>
</Card>
<ErrorBoundary fallback={<div>Something went wrong</div>}>
<Suspense>
<StakeholderTable companyId={session.user.companyId} />
</Suspense>
</ErrorBoundary>
</div>
);
};
Expand Down
48 changes: 31 additions & 17 deletions src/components/stakeholder/stakeholder-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { pushModal } from "@/components/modals";
import { Badge } from "@/components/ui/badge";
import { Checkbox } from "@/components/ui/checkbox";
import { DataTable } from "@/components/ui/data-table/data-table";
import { DataTableBody } from "@/components/ui/data-table/data-table-body";
import { DataTableContent } from "@/components/ui/data-table/data-table-content";
Expand All @@ -17,13 +16,14 @@ import {
import type { TGetManyStakeholderRes } from "@/server/api/client-handlers/stakeholder";
import { useManyStakeholder } from "@/server/api/client-hooks/stakeholder";
import { ManyStakeholderSortParams } from "@/server/api/schema/stakeholder";
import type { RouterOutputs } from "@/trpc/shared";
import { RiMore2Fill } from "@remixicon/react";
import { RiGroup2Fill, RiMore2Fill } from "@remixicon/react";
import { createColumnHelper } from "@tanstack/react-table";

import { parseAsString } from "nuqs";
import EmptyState from "../common/empty-state";
import { Allow } from "../rbac/allow";
import { Button } from "../ui/button";
import { Card } from "../ui/card";
import {
DropdownMenu,
DropdownMenuContent,
Expand All @@ -32,12 +32,10 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "../ui/dropdown-menu";
import StakeholderDropdown from "./stakeholder-dropdown";
import { StakeholderTableToolbar } from "./stakeholder-table-toolbar";

type Stakeholder = RouterOutputs["stakeholder"]["getStakeholders"];

type StakeholderTableType = {
stakeholders: Stakeholder;
companyId: string;
};

Expand Down Expand Up @@ -200,7 +198,7 @@ const StakeholderTable = ({ companyId }: StakeholderTableType) => {
const table = usePaginatedTable({
pageCount: data?.meta.pageCount ?? -1,
columns,
data: data?.data ?? [],
data: data.data,
state: {
pagination,
sorting,
Expand All @@ -211,17 +209,33 @@ const StakeholderTable = ({ companyId }: StakeholderTableType) => {
onColumnFiltersChange,
});

if (data?.data?.length === 0 && data.meta.totalCount === 0) {
return (
<EmptyState
icon={<RiGroup2Fill />}
title="You do not have any stakeholders!"
subtitle="Please click the button below to add or import stakeholders."
>
<Allow action="create" subject="stakeholder">
<StakeholderDropdown />
</Allow>
</EmptyState>
);
}

return (
<div className="w-full p-6">
<DataTable table={table}>
<StakeholderTableToolbar />
<DataTableContent>
<DataTableHeader />
<DataTableBody />
</DataTableContent>
<DataTablePagination />
</DataTable>
</div>
<Card className="mx-auto mt-3 w-[28rem] sm:w-[38rem] md:w-full">
<div className="w-full p-6">
<DataTable table={table}>
<StakeholderTableToolbar />
<DataTableContent>
<DataTableHeader />
<DataTableBody />
</DataTableContent>
<DataTablePagination />
</DataTable>
</div>
</Card>
);
};

Expand Down