1
- import { useState } from 'react'
2
- import { IconMailPlus , IconUserPlus } from '@tabler/icons-react'
3
- import useDialogState from '@/hooks/use-dialog-state'
4
- import { Button } from '@/components/ui/button'
5
1
import { Header } from '@/components/layout/header'
6
2
import { Main } from '@/components/layout/main'
7
3
import { ProfileDropdown } from '@/components/profile-dropdown'
8
4
import { Search } from '@/components/search'
9
5
import { ThemeSwitch } from '@/components/theme-switch'
10
- import { UsersActionDialog } from './components/users-action-dialog'
11
6
import { columns } from './components/users-columns'
12
- import { UsersDeleteDialog } from './components/users-delete-dialog '
13
- import { UsersInviteDialog } from './components/users-invite-dialog '
7
+ import { UsersDialogs } from './components/users-dialogs '
8
+ import { UsersPrimaryButtons } from './components/users-primary-buttons '
14
9
import { UsersTable } from './components/users-table'
15
- import UsersContextProvider , {
16
- type UsersDialogType ,
17
- } from './context/users-context'
18
- import { User , userListSchema } from './data/schema'
10
+ import UsersProvider from './context/users-context'
11
+ import { userListSchema } from './data/schema'
19
12
import { users } from './data/users'
20
13
21
14
export default function Users ( ) {
22
- // Dialog states
23
- const [ currentRow , setCurrentRow ] = useState < User | null > ( null )
24
- const [ open , setOpen ] = useDialogState < UsersDialogType > ( null )
25
-
26
15
// Parse user list
27
16
const userList = userListSchema . parse ( users )
28
17
29
18
return (
30
- < UsersContextProvider value = { { open, setOpen, currentRow, setCurrentRow } } >
31
- { /* ===== Top Heading ===== */ }
19
+ < UsersProvider >
32
20
< Header fixed >
33
21
< Search />
34
22
< div className = 'ml-auto flex items-center space-x-4' >
@@ -45,63 +33,14 @@ export default function Users() {
45
33
Manage your users and their roles here.
46
34
</ p >
47
35
</ div >
48
- < div className = 'flex gap-2' >
49
- < Button
50
- variant = 'outline'
51
- className = 'space-x-1'
52
- onClick = { ( ) => setOpen ( 'invite' ) }
53
- >
54
- < span > Invite User</ span > < IconMailPlus size = { 18 } />
55
- </ Button >
56
- < Button className = 'space-x-1' onClick = { ( ) => setOpen ( 'add' ) } >
57
- < span > Add User</ span > < IconUserPlus size = { 18 } />
58
- </ Button >
59
- </ div >
36
+ < UsersPrimaryButtons />
60
37
</ div >
61
38
< div className = '-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0' >
62
39
< UsersTable data = { userList } columns = { columns } />
63
40
</ div >
64
41
</ Main >
65
42
66
- < UsersActionDialog
67
- key = 'user-add'
68
- open = { open === 'add' }
69
- onOpenChange = { ( ) => setOpen ( 'add' ) }
70
- />
71
-
72
- < UsersInviteDialog
73
- key = 'user-invite'
74
- open = { open === 'invite' }
75
- onOpenChange = { ( ) => setOpen ( 'invite' ) }
76
- />
77
-
78
- { currentRow && (
79
- < >
80
- < UsersActionDialog
81
- key = { `user-edit-${ currentRow . id } ` }
82
- open = { open === 'edit' }
83
- onOpenChange = { ( ) => {
84
- setOpen ( 'edit' )
85
- setTimeout ( ( ) => {
86
- setCurrentRow ( null )
87
- } , 500 )
88
- } }
89
- currentRow = { currentRow }
90
- />
91
-
92
- < UsersDeleteDialog
93
- key = { `user-delete-${ currentRow . id } ` }
94
- open = { open === 'delete' }
95
- onOpenChange = { ( ) => {
96
- setOpen ( 'delete' )
97
- setTimeout ( ( ) => {
98
- setCurrentRow ( null )
99
- } , 500 )
100
- } }
101
- currentRow = { currentRow }
102
- />
103
- </ >
104
- ) }
105
- </ UsersContextProvider >
43
+ < UsersDialogs />
44
+ </ UsersProvider >
106
45
)
107
46
}
0 commit comments