Skip to content

Commit 0185e0f

Browse files
committed
AB-66: improve profile load, refactor db slightly, add show specialist from admin panel
1 parent 0530be9 commit 0185e0f

File tree

15 files changed

+244
-117
lines changed

15 files changed

+244
-117
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@prisma/client": "4.14.1",
1616
"@t3-oss/env-nextjs": "0.2.2",
1717
"@tanstack/react-query": "4.29.5",
18+
"@tanstack/react-query-devtools": "4.29.14",
1819
"@tanstack/react-table": "8.9.2",
1920
"@trpc/client": "10.23.0",
2021
"@trpc/next": "10.23.0",

src/components/AdminPanel/UserList/columns.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { ColumnDef } from '@tanstack/react-table';
2+
import dayjs from 'dayjs';
3+
import { AiOutlineCheck } from 'react-icons/ai';
24

35
import { DataTableColumnHeader } from './data-table-column-header';
4-
import { Task } from 'components/AdminPanel/UserList/schema';
5-
import { AiOutlineCheck } from 'react-icons/ai';
6-
import dayjs from 'dayjs';
6+
import { User } from 'components/AdminPanel/UserList/schema';
7+
import { DataTableRowActions } from 'components/AdminPanel/UserList/data-table-row-actions';
78

8-
export const columns: ColumnDef<Task>[] = [
9+
export const columns: ColumnDef<User>[] = [
910
{
1011
accessorKey: 'name',
1112
header: ({ column }) => (
@@ -49,4 +50,8 @@ export const columns: ColumnDef<Task>[] = [
4950
// @ts-ignore
5051
cell: ({ row }) => <div className="w-[250px]">{dayjs(row.getValue('created_at').toString()).format('YYYY-MM-DD HH:mm:ss')}</div>,
5152
},
53+
{
54+
id: 'actions',
55+
cell: ({ row }) => <DataTableRowActions row={row} />,
56+
},
5257
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Row } from '@tanstack/react-table';
2+
import { userSchema } from 'components/AdminPanel/UserList/schema';
3+
import { ROLES } from '@prisma/client';
4+
import { BsArrowUpRightSquare } from 'react-icons/bs';
5+
6+
interface DataTableRowActionsProps<TData> {
7+
row: Row<TData>
8+
}
9+
10+
export function DataTableRowActions<TData> ({
11+
row,
12+
}: DataTableRowActionsProps<TData>) {
13+
// const [isOpen, setIsOpen] = useState(false);
14+
const user = userSchema.parse(row.original);
15+
16+
if (user.role !== ROLES.SPECIALIST) return null;
17+
return (
18+
<>
19+
<a
20+
target="_blank"
21+
rel="noopener noreferrer"
22+
href={`./dashboard/community/${user.id}`}
23+
className="p-1"
24+
>
25+
<BsArrowUpRightSquare size={32} />
26+
</a>
27+
{/*<button*/}
28+
{/* id="dropdownDefaultButton"*/}
29+
{/* className="text-black hover:bg-gray-400 p-2 text-center"*/}
30+
{/* onClick={() => setIsOpen(!isOpen)}*/}
31+
{/*>*/}
32+
{/* <HiDotsHorizontal />*/}
33+
{/*</button>*/}
34+
{/*{isOpen*/}
35+
{/* ? <div*/}
36+
{/* id="dropdown"*/}
37+
{/* className="z-10 absolute bg-white"*/}
38+
{/* >*/}
39+
{/* <ul className="py-2 text-sm text-gray-700" aria-labelledby="dropdownDefaultButton">*/}
40+
{/* <li>*/}
41+
{/* <a*/}
42+
{/* target="_blank"*/}
43+
{/* rel="noopener noreferrer"*/}
44+
{/* href={`./dashboard/community/${user.id}`}*/}
45+
{/* className="block px-4 py-2 hover:bg-gray-100"*/}
46+
{/* >*/}
47+
{/* Podgląd*/}
48+
{/* </a>*/}
49+
{/* </li>*/}
50+
{/* </ul>*/}
51+
{/* </div>*/}
52+
{/* : null*/}
53+
{/*}*/}
54+
</>
55+
);
56+
}

src/components/AdminPanel/UserList/data-table.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ export function DataTable<TData, TValue> ({
2424
columns,
2525
data,
2626
}: DataTableProps<TData, TValue>) {
27+
const [rowSelection, setRowSelection] = React.useState({});
28+
2729
const table = useReactTable({
2830
data,
2931
columns,
32+
state: {
33+
rowSelection,
34+
},
3035
getCoreRowModel: getCoreRowModel(),
36+
enableRowSelection: true,
37+
onRowSelectionChange: setRowSelection,
3138
});
3239

3340
return (
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { z } from 'zod';
22

3-
export const schema = z.object({
4-
name: z.string().optional(),
5-
surname: z.string().optional(),
6-
clerk_user_id: z.string().optional(),
7-
email: z.string().optional(),
8-
created_at: z.string().optional(),
9-
role: z.any(),
3+
export const userSchema = z.object({
4+
id: z.any().optional(),
5+
name: z.any().optional(),
6+
surname: z.any().optional(),
7+
clerk_user_id: z.any().optional(),
8+
email: z.any().optional(),
9+
created_at: z.any().optional(),
10+
role: z.any().optional(),
1011
});
1112

12-
export type Task = z.infer<typeof schema>
13+
export type User = z.infer<typeof userSchema>

src/components/Dashboard/Layout/sidebar/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const Sidebar = ({ open, setOpen }: ISidebar) => {
6363
<Links routes={routes} />
6464
</ul>
6565
<button
66-
onClick={() => signOut().then(() => push('./'))}
66+
onClick={() => signOut().then(() => push('./join-us'))}
6767
className={'absolute left-10 bottom-20 flex items-center gap-2 text-gray-400 text-lg'}
6868
>
6969
<MdLogout size={24} /> Wyloguj się

0 commit comments

Comments
 (0)