-
-
Notifications
You must be signed in to change notification settings - Fork 388
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 context
- Loading branch information
Showing
5 changed files
with
95 additions
and
79 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,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> | ||
) | ||
} |
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