1
- import { useState } from 'react'
2
- import { IconDownload , IconPlus } from '@tabler/icons-react'
3
- import useDialogState from '@/hooks/use-dialog-state'
4
- import { toast } from '@/hooks/use-toast'
5
- import { Button } from '@/components/ui/button'
6
- import { ConfirmDialog } from '@/components/confirm-dialog'
7
1
import { Header } from '@/components/layout/header'
8
2
import { Main } from '@/components/layout/main'
9
3
import { ProfileDropdown } from '@/components/profile-dropdown'
10
4
import { Search } from '@/components/search'
11
5
import { ThemeSwitch } from '@/components/theme-switch'
12
6
import { columns } from './components/columns'
13
7
import { DataTable } from './components/data-table'
14
- import { TasksImportDialog } from './components/tasks-import-dialog'
15
- import { TasksMutateDrawer } from './components/tasks-mutate-drawer'
16
- import TasksContextProvider , { TasksDialogType } from './context/tasks-context'
17
- import { Task } from './data/schema'
8
+ import { TasksDialogs } from './components/tasks-dialogs'
9
+ import { TasksPrimaryButtons } from './components/tasks-primary-buttons'
10
+ import TasksProvider from './context/tasks-context'
18
11
import { tasks } from './data/tasks'
19
12
20
13
export default function Tasks ( ) {
21
- // Local states
22
- const [ currentRow , setCurrentRow ] = useState < Task | null > ( null )
23
- const [ open , setOpen ] = useDialogState < TasksDialogType > ( null )
24
-
25
14
return (
26
- < TasksContextProvider value = { { open, setOpen, currentRow, setCurrentRow } } >
27
- { /* ===== Top Heading ===== */ }
15
+ < TasksProvider >
28
16
< Header fixed >
29
17
< Search />
30
18
< div className = 'ml-auto flex items-center space-x-4' >
@@ -41,89 +29,14 @@ export default function Tasks() {
41
29
Here's a list of your tasks for this month!
42
30
</ p >
43
31
</ div >
44
- < div className = 'flex gap-2' >
45
- < Button
46
- variant = 'outline'
47
- className = 'space-x-1'
48
- onClick = { ( ) => setOpen ( 'import' ) }
49
- >
50
- < span > Import</ span > < IconDownload size = { 18 } />
51
- </ Button >
52
- < Button className = 'space-x-1' onClick = { ( ) => setOpen ( 'create' ) } >
53
- < span > Create</ span > < IconPlus size = { 18 } />
54
- </ Button >
55
- </ div >
32
+ < TasksPrimaryButtons />
56
33
</ div >
57
34
< div className = '-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0' >
58
35
< DataTable data = { tasks } columns = { columns } />
59
36
</ div >
60
37
</ Main >
61
38
62
- < TasksMutateDrawer
63
- key = 'task-create'
64
- open = { open === 'create' }
65
- onOpenChange = { ( ) => setOpen ( 'create' ) }
66
- />
67
-
68
- < TasksImportDialog
69
- key = 'tasks-import'
70
- open = { open === 'import' }
71
- onOpenChange = { ( ) => setOpen ( 'import' ) }
72
- />
73
-
74
- { currentRow && (
75
- < >
76
- < TasksMutateDrawer
77
- key = { `task-update-${ currentRow . id } ` }
78
- open = { open === 'update' }
79
- onOpenChange = { ( ) => {
80
- setOpen ( 'update' )
81
- setTimeout ( ( ) => {
82
- setCurrentRow ( null )
83
- } , 500 )
84
- } }
85
- currentRow = { currentRow }
86
- />
87
-
88
- < ConfirmDialog
89
- key = 'task-delete'
90
- destructive
91
- open = { open === 'delete' }
92
- onOpenChange = { ( ) => {
93
- setOpen ( 'delete' )
94
- setTimeout ( ( ) => {
95
- setCurrentRow ( null )
96
- } , 500 )
97
- } }
98
- handleConfirm = { ( ) => {
99
- setOpen ( null )
100
- setTimeout ( ( ) => {
101
- setCurrentRow ( null )
102
- } , 500 )
103
- toast ( {
104
- title : 'The following task has been deleted:' ,
105
- description : (
106
- < pre className = 'mt-2 w-[340px] rounded-md bg-slate-950 p-4' >
107
- < code className = 'text-white' >
108
- { JSON . stringify ( currentRow , null , 2 ) }
109
- </ code >
110
- </ pre >
111
- ) ,
112
- } )
113
- } }
114
- className = 'max-w-md'
115
- title = { `Delete this task: ${ currentRow . id } ?` }
116
- desc = {
117
- < >
118
- You are about to delete a task with the ID{ ' ' }
119
- < strong > { currentRow . id } </ strong > . < br />
120
- This action cannot be undone.
121
- </ >
122
- }
123
- confirmText = 'Delete'
124
- />
125
- </ >
126
- ) }
127
- </ TasksContextProvider >
39
+ < TasksDialogs />
40
+ </ TasksProvider >
128
41
)
129
42
}
0 commit comments