-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: optimize states in users/tasks context (#71)
* refactor: optimize states in tasks context * refactor: optimize states in users context
- Loading branch information
Showing
10 changed files
with
215 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { toast } from '@/hooks/use-toast' | ||
import { ConfirmDialog } from '@/components/confirm-dialog' | ||
import { useTasks } from '../context/tasks-context' | ||
import { TasksImportDialog } from './tasks-import-dialog' | ||
import { TasksMutateDrawer } from './tasks-mutate-drawer' | ||
|
||
export function TasksDialogs() { | ||
const { open, setOpen, currentRow, setCurrentRow } = useTasks() | ||
return ( | ||
<> | ||
<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' | ||
/> | ||
</> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { IconDownload, IconPlus } from '@tabler/icons-react' | ||
import { Button } from '@/components/ui/button' | ||
import { useTasks } from '../context/tasks-context' | ||
|
||
export function TasksPrimaryButtons() { | ||
const { setOpen } = useTasks() | ||
return ( | ||
<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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useUsers } from '../context/users-context' | ||
import { UsersActionDialog } from './users-action-dialog' | ||
import { UsersDeleteDialog } from './users-delete-dialog' | ||
import { UsersInviteDialog } from './users-invite-dialog' | ||
|
||
export function UsersDialogs() { | ||
const { open, setOpen, currentRow, setCurrentRow } = useUsers() | ||
return ( | ||
<> | ||
<UsersActionDialog | ||
key='user-add' | ||
open={open === 'add'} | ||
onOpenChange={() => setOpen('add')} | ||
/> | ||
|
||
<UsersInviteDialog | ||
key='user-invite' | ||
open={open === 'invite'} | ||
onOpenChange={() => setOpen('invite')} | ||
/> | ||
|
||
{currentRow && ( | ||
<> | ||
<UsersActionDialog | ||
key={`user-edit-${currentRow.id}`} | ||
open={open === 'edit'} | ||
onOpenChange={() => { | ||
setOpen('edit') | ||
setTimeout(() => { | ||
setCurrentRow(null) | ||
}, 500) | ||
}} | ||
currentRow={currentRow} | ||
/> | ||
|
||
<UsersDeleteDialog | ||
key={`user-delete-${currentRow.id}`} | ||
open={open === 'delete'} | ||
onOpenChange={() => { | ||
setOpen('delete') | ||
setTimeout(() => { | ||
setCurrentRow(null) | ||
}, 500) | ||
}} | ||
currentRow={currentRow} | ||
/> | ||
</> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { IconMailPlus, IconUserPlus } from '@tabler/icons-react' | ||
import { Button } from '@/components/ui/button' | ||
import { useUsers } from '../context/users-context' | ||
|
||
export function UsersPrimaryButtons() { | ||
const { setOpen } = useUsers() | ||
return ( | ||
<div className='flex gap-2'> | ||
<Button | ||
variant='outline' | ||
className='space-x-1' | ||
onClick={() => setOpen('invite')} | ||
> | ||
<span>Invite User</span> <IconMailPlus size={18} /> | ||
</Button> | ||
<Button className='space-x-1' onClick={() => setOpen('add')}> | ||
<span>Add User</span> <IconUserPlus size={18} /> | ||
</Button> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.