add revoke
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { formatCPF } from '@brazilian-utils/brazilian-utils'
|
||||
import { type ColumnDef } from '@tanstack/react-table'
|
||||
import { type ColumnDef, type RowData } from '@tanstack/react-table'
|
||||
import { useToggle } from 'ahooks'
|
||||
import {
|
||||
EllipsisVerticalIcon,
|
||||
@@ -113,55 +113,59 @@ export const columns: ColumnDef<User>[] = [
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
cell: ({ row }) => (
|
||||
<div className="flex justify-end items-center">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="data-[state=open]:bg-muted text-muted-foreground cursor-pointer"
|
||||
size="icon-sm"
|
||||
>
|
||||
<EllipsisVerticalIcon />
|
||||
<span className="sr-only">Abrir menu</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-36 *:cursor-pointer">
|
||||
<DropdownMenuItem asChild onSelect={(e) => e.preventDefault()}>
|
||||
<NavLink to={`${row.id}`}>
|
||||
{({ isPending }) => (
|
||||
<>
|
||||
{isPending ? <Spinner /> : <PencilIcon />}
|
||||
Editar
|
||||
</>
|
||||
)}
|
||||
</NavLink>
|
||||
</DropdownMenuItem>
|
||||
<UnlinkMenuItem userId={row.id} />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
)
|
||||
cell: ({ row }) => <ActionMenu row={row} />
|
||||
}
|
||||
]
|
||||
|
||||
function UnlinkMenuItem({ userId }: { userId: string }) {
|
||||
function ActionMenu({ row }: { row: any }) {
|
||||
return (
|
||||
<div className="flex justify-end items-center">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="data-[state=open]:bg-muted text-muted-foreground cursor-pointer"
|
||||
size="icon-sm"
|
||||
>
|
||||
<EllipsisVerticalIcon />
|
||||
<span className="sr-only">Abrir menu</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-36 *:cursor-pointer">
|
||||
<DropdownMenuItem asChild onSelect={(e) => e.preventDefault()}>
|
||||
<NavLink to={`${row.id}`}>
|
||||
{({ isPending }) => (
|
||||
<>
|
||||
{isPending ? <Spinner /> : <PencilIcon />}
|
||||
Editar
|
||||
</>
|
||||
)}
|
||||
</NavLink>
|
||||
</DropdownMenuItem>
|
||||
<UnlinkItem id={row.id} />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function UnlinkItem({ id }: { id: string }) {
|
||||
const [loading, { set }] = useToggle(false)
|
||||
const { orgid } = useParams()
|
||||
const { table } = useDataTable<User>()
|
||||
|
||||
const unlink = async (e) => {
|
||||
const unlink = async (e: MouseEvent) => {
|
||||
e.preventDefault()
|
||||
set(true)
|
||||
|
||||
const r = await fetch(`/~/api/orgs/${orgid}/users/${userId}`, {
|
||||
const r = await fetch(`/~/api/orgs/${orgid}/users/${id}`, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
|
||||
if (r.ok) {
|
||||
toast.info('O colaborador foi desvinculado')
|
||||
// @ts-ignore
|
||||
table.options.meta?.removeRow?.(userId)
|
||||
table.options.meta?.removeRow?.(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +188,7 @@ function UnlinkMenuItem({ userId }: { userId: string }) {
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter className="*:cursor-pointer">
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogCancel>Cancelar</AlertDialogCancel>
|
||||
<AlertDialogAction asChild>
|
||||
<Button onClick={unlink} disabled={loading} variant="destructive">
|
||||
{loading ? <Spinner /> : null} Continuar
|
||||
|
||||
Reference in New Issue
Block a user