|
@@ -1,9 +1,3 @@
|
|
|
-import { useState } from 'react'
|
|
|
|
|
-import { IconDownload, IconPlus } from '@tabler/icons-react'
|
|
|
|
|
-import useDialogState from '@/hooks/use-dialog-state'
|
|
|
|
|
-import { toast } from '@/hooks/use-toast'
|
|
|
|
|
-import { Button } from '@/components/ui/button'
|
|
|
|
|
-import { ConfirmDialog } from '@/components/confirm-dialog'
|
|
|
|
|
import { Header } from '@/components/layout/header'
|
|
import { Header } from '@/components/layout/header'
|
|
|
import { Main } from '@/components/layout/main'
|
|
import { Main } from '@/components/layout/main'
|
|
|
import { ProfileDropdown } from '@/components/profile-dropdown'
|
|
import { ProfileDropdown } from '@/components/profile-dropdown'
|
|
@@ -11,20 +5,14 @@ import { Search } from '@/components/search'
|
|
|
import { ThemeSwitch } from '@/components/theme-switch'
|
|
import { ThemeSwitch } from '@/components/theme-switch'
|
|
|
import { columns } from './components/columns'
|
|
import { columns } from './components/columns'
|
|
|
import { DataTable } from './components/data-table'
|
|
import { DataTable } from './components/data-table'
|
|
|
-import { TasksImportDialog } from './components/tasks-import-dialog'
|
|
|
|
|
-import { TasksMutateDrawer } from './components/tasks-mutate-drawer'
|
|
|
|
|
-import TasksContextProvider, { TasksDialogType } from './context/tasks-context'
|
|
|
|
|
-import { Task } from './data/schema'
|
|
|
|
|
|
|
+import { TasksDialogs } from './components/tasks-dialogs'
|
|
|
|
|
+import { TasksPrimaryButtons } from './components/tasks-primary-buttons'
|
|
|
|
|
+import TasksProvider from './context/tasks-context'
|
|
|
import { tasks } from './data/tasks'
|
|
import { tasks } from './data/tasks'
|
|
|
|
|
|
|
|
export default function Tasks() {
|
|
export default function Tasks() {
|
|
|
- // Local states
|
|
|
|
|
- const [currentRow, setCurrentRow] = useState<Task | null>(null)
|
|
|
|
|
- const [open, setOpen] = useDialogState<TasksDialogType>(null)
|
|
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
- <TasksContextProvider value={{ open, setOpen, currentRow, setCurrentRow }}>
|
|
|
|
|
- {/* ===== Top Heading ===== */}
|
|
|
|
|
|
|
+ <TasksProvider>
|
|
|
<Header fixed>
|
|
<Header fixed>
|
|
|
<Search />
|
|
<Search />
|
|
|
<div className='ml-auto flex items-center space-x-4'>
|
|
<div className='ml-auto flex items-center space-x-4'>
|
|
@@ -41,89 +29,14 @@ export default function Tasks() {
|
|
|
Here's a list of your tasks for this month!
|
|
Here's a list of your tasks for this month!
|
|
|
</p>
|
|
</p>
|
|
|
</div>
|
|
</div>
|
|
|
- <div className='flex gap-2'>
|
|
|
|
|
- <Button
|
|
|
|
|
- variant='outline'
|
|
|
|
|
- className='space-x-1'
|
|
|
|
|
- onClick={() => setOpen('import')}
|
|
|
|
|
- >
|
|
|
|
|
- <span>Import</span> <IconDownload size={18} />
|
|
|
|
|
- </Button>
|
|
|
|
|
- <Button className='space-x-1' onClick={() => setOpen('create')}>
|
|
|
|
|
- <span>Create</span> <IconPlus size={18} />
|
|
|
|
|
- </Button>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <TasksPrimaryButtons />
|
|
|
</div>
|
|
</div>
|
|
|
<div className='-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0'>
|
|
<div className='-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0'>
|
|
|
<DataTable data={tasks} columns={columns} />
|
|
<DataTable data={tasks} columns={columns} />
|
|
|
</div>
|
|
</div>
|
|
|
</Main>
|
|
</Main>
|
|
|
|
|
|
|
|
- <TasksMutateDrawer
|
|
|
|
|
- key='task-create'
|
|
|
|
|
- open={open === 'create'}
|
|
|
|
|
- onOpenChange={() => setOpen('create')}
|
|
|
|
|
- />
|
|
|
|
|
-
|
|
|
|
|
- <TasksImportDialog
|
|
|
|
|
- key='tasks-import'
|
|
|
|
|
- open={open === 'import'}
|
|
|
|
|
- onOpenChange={() => setOpen('import')}
|
|
|
|
|
- />
|
|
|
|
|
-
|
|
|
|
|
- {currentRow && (
|
|
|
|
|
- <>
|
|
|
|
|
- <TasksMutateDrawer
|
|
|
|
|
- key={`task-update-${currentRow.id}`}
|
|
|
|
|
- open={open === 'update'}
|
|
|
|
|
- onOpenChange={() => {
|
|
|
|
|
- setOpen('update')
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- setCurrentRow(null)
|
|
|
|
|
- }, 500)
|
|
|
|
|
- }}
|
|
|
|
|
- currentRow={currentRow}
|
|
|
|
|
- />
|
|
|
|
|
-
|
|
|
|
|
- <ConfirmDialog
|
|
|
|
|
- key='task-delete'
|
|
|
|
|
- destructive
|
|
|
|
|
- open={open === 'delete'}
|
|
|
|
|
- onOpenChange={() => {
|
|
|
|
|
- setOpen('delete')
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- setCurrentRow(null)
|
|
|
|
|
- }, 500)
|
|
|
|
|
- }}
|
|
|
|
|
- handleConfirm={() => {
|
|
|
|
|
- setOpen(null)
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- setCurrentRow(null)
|
|
|
|
|
- }, 500)
|
|
|
|
|
- toast({
|
|
|
|
|
- title: 'The following task has been deleted:',
|
|
|
|
|
- description: (
|
|
|
|
|
- <pre className='mt-2 w-[340px] rounded-md bg-slate-950 p-4'>
|
|
|
|
|
- <code className='text-white'>
|
|
|
|
|
- {JSON.stringify(currentRow, null, 2)}
|
|
|
|
|
- </code>
|
|
|
|
|
- </pre>
|
|
|
|
|
- ),
|
|
|
|
|
- })
|
|
|
|
|
- }}
|
|
|
|
|
- className='max-w-md'
|
|
|
|
|
- title={`Delete this task: ${currentRow.id} ?`}
|
|
|
|
|
- desc={
|
|
|
|
|
- <>
|
|
|
|
|
- You are about to delete a task with the ID{' '}
|
|
|
|
|
- <strong>{currentRow.id}</strong>. <br />
|
|
|
|
|
- This action cannot be undone.
|
|
|
|
|
- </>
|
|
|
|
|
- }
|
|
|
|
|
- confirmText='Delete'
|
|
|
|
|
- />
|
|
|
|
|
- </>
|
|
|
|
|
- )}
|
|
|
|
|
- </TasksContextProvider>
|
|
|
|
|
|
|
+ <TasksDialogs />
|
|
|
|
|
+ </TasksProvider>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|