Skip to content

Commit

Permalink
feat: user and role management
Browse files Browse the repository at this point in the history
  • Loading branch information
zekhoi committed Aug 26, 2024
1 parent cca0096 commit 6c9ad7f
Show file tree
Hide file tree
Showing 38 changed files with 907 additions and 70 deletions.
2 changes: 1 addition & 1 deletion drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from 'drizzle-kit';
import env from '@/env';

export default defineConfig({
schema: './src/database/schema/index.ts',
schema: './src/database/tables/index.ts',
dialect: 'postgresql',
out: './drizzle',
dbCredentials: {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-scroll-area": "^1.1.0",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-toast": "^1.2.1",
"@tanstack/react-query": "^5.52.1",
"arctic": "^1.9.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
Expand Down
107 changes: 107 additions & 0 deletions pnpm-lock.yaml

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

20 changes: 20 additions & 0 deletions src/app/(private)/dashboard/(admin)/users/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Metadata } from 'next';

export const metadata: Metadata = {
title: 'Users | Sainseni Dashboard',
authors: [
{
name: 'Khoironi Kurnia Syah',
url: 'https://zekhoi.dev',
},
],
description: 'Community for community',
};

export default function UsersLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return <>{children}</>;
}
140 changes: 140 additions & 0 deletions src/app/(private)/dashboard/(admin)/users/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
'use client';

import { Menu, Users } from 'lucide-react';
import { useState } from 'react';

import { useGetRoles } from '@/lib/queries/roles.query';
import { useGetUsers } from '@/lib/queries/users.query';

import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { ScrollArea } from '@/components/ui/scroll-area';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';

import RoleFormDialog from './role-form';
export default function Component() {
const {
data: roleData,
isLoading: isRoleLoading,
error: roleError,
} = useGetRoles({});

const {
data: userData,
isLoading: isuserLoading,
error: userError,
} = useGetUsers({});
const [newMember, setNewMember] = useState({
name: '',
email: '',
role: '',
});
const [newRole, setNewRole] = useState('');
const [editingRole, setEditingRole] = useState('');
console.error(userData, 'userData');

return (
<div className='container mx-auto p-4 space-y-8'>
<header className='flex flex-col sm:flex-row justify-between items-start sm:items-center space-y-4 sm:space-y-0'>
<h1 className='text-2xl font-bold flex items-center gap-2'>
<Users className='h-6 w-6' />
User Management
</h1>
<div className='flex flex-col sm:flex-row space-y-2 sm:space-y-0 sm:space-x-2 w-full sm:w-auto'>
<RoleFormDialog />
</div>
</header>

<main>
<Card>
<CardHeader>
<CardTitle>User List</CardTitle>
</CardHeader>
<CardContent>
<ScrollArea className='h-[300px] sm:h-[400px]'>
<Table>
<TableHeader>
<TableRow>
<TableHead className='w-[200px]'>
Name
</TableHead>
<TableHead className='hidden sm:table-cell'>
Email
</TableHead>
<TableHead>Role</TableHead>
<TableHead className='text-right'>
Actions
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{userData &&
userData.map((member) => (
<TableRow key={member.id}>
<TableCell className='font-medium'>
{member.name}
</TableCell>
<TableCell className='hidden sm:table-cell'>
{member.email}
</TableCell>
<TableCell>
{member.roleName}
</TableCell>
<TableCell className='text-right'>
<DropdownMenu>
<DropdownMenuTrigger
asChild
>
<Button
variant='ghost'
className='h-8 w-8 p-0'
>
<span className='sr-only'>
Open menu
</span>
<Menu className='h-4 w-4' />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align='end'>
<DropdownMenuLabel>
Actions
</DropdownMenuLabel>
<DropdownMenuItem>
Edit User
</DropdownMenuItem>
<DropdownMenuItem>
Change Role
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>
Delete User
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</ScrollArea>
</CardContent>
</Card>
</main>
</div>
);
}
Loading

0 comments on commit 6c9ad7f

Please sign in to comment.