mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-20 11:01:52 +00:00
4d5676f00e
Co-authored-by: Alan Buscaglia <alanbuscaglia@MacBook-Pro.local> Co-authored-by: alejandrobailo <alejandrobailo94@gmail.com> Co-authored-by: César Arroba <cesar@prowler.com> Co-authored-by: Alejandro Bailo <59607668+alejandrobailo@users.noreply.github.com>
118 lines
3.7 KiB
TypeScript
118 lines
3.7 KiB
TypeScript
"use client";
|
|
|
|
import { Button } from "@heroui/button";
|
|
import {
|
|
Dropdown,
|
|
DropdownItem,
|
|
DropdownMenu,
|
|
DropdownSection,
|
|
DropdownTrigger,
|
|
} from "@heroui/dropdown";
|
|
import {
|
|
DeleteDocumentBulkIcon,
|
|
EditDocumentBulkIcon,
|
|
} from "@heroui/shared-icons";
|
|
import { Row } from "@tanstack/react-table";
|
|
import clsx from "clsx";
|
|
import { useState } from "react";
|
|
|
|
import { VerticalDotsIcon } from "@/components/icons";
|
|
import { CustomAlertModal } from "@/components/ui/custom";
|
|
|
|
import { DeleteForm, EditForm } from "../forms";
|
|
|
|
interface DataTableRowActionsProps<UserProps> {
|
|
row: Row<UserProps>;
|
|
roles?: { id: string; name: string }[];
|
|
}
|
|
const iconClasses = "text-2xl text-default-500 pointer-events-none shrink-0";
|
|
|
|
export function DataTableRowActions<UserProps>({
|
|
row,
|
|
roles,
|
|
}: DataTableRowActionsProps<UserProps>) {
|
|
const [isEditOpen, setIsEditOpen] = useState(false);
|
|
const [isDeleteOpen, setIsDeleteOpen] = useState(false);
|
|
const userId = (row.original as { id: string }).id;
|
|
const userName = (row.original as any).attributes?.name;
|
|
const userEmail = (row.original as any).attributes?.email;
|
|
const userCompanyName = (row.original as any).attributes?.company_name;
|
|
const userRole = (row.original as any).attributes?.role?.name;
|
|
|
|
return (
|
|
<>
|
|
<CustomAlertModal
|
|
isOpen={isEditOpen}
|
|
onOpenChange={setIsEditOpen}
|
|
title="Edit user details"
|
|
>
|
|
<EditForm
|
|
userId={userId}
|
|
userName={userName}
|
|
userEmail={userEmail}
|
|
userCompanyName={userCompanyName}
|
|
currentRole={userRole}
|
|
roles={roles || []}
|
|
setIsOpen={setIsEditOpen}
|
|
/>
|
|
</CustomAlertModal>
|
|
<CustomAlertModal
|
|
isOpen={isDeleteOpen}
|
|
onOpenChange={setIsDeleteOpen}
|
|
title="Are you absolutely sure?"
|
|
description="This action cannot be undone. This will permanently delete your user account and remove your data from the server."
|
|
>
|
|
<DeleteForm userId={userId} setIsOpen={setIsDeleteOpen} />
|
|
</CustomAlertModal>
|
|
|
|
<div className="relative flex items-center justify-end gap-2">
|
|
<Dropdown
|
|
className="dark:bg-prowler-blue-800 shadow-xl"
|
|
placement="bottom"
|
|
>
|
|
<DropdownTrigger>
|
|
<Button isIconOnly radius="full" size="sm" variant="light">
|
|
<VerticalDotsIcon className="text-default-400" />
|
|
</Button>
|
|
</DropdownTrigger>
|
|
<DropdownMenu
|
|
closeOnSelect
|
|
aria-label="Actions"
|
|
color="default"
|
|
variant="flat"
|
|
>
|
|
<DropdownSection title="Actions">
|
|
<DropdownItem
|
|
key="edit"
|
|
description="Allows you to edit the user"
|
|
textValue="Edit User"
|
|
startContent={<EditDocumentBulkIcon className={iconClasses} />}
|
|
onPress={() => setIsEditOpen(true)}
|
|
>
|
|
Edit User
|
|
</DropdownItem>
|
|
</DropdownSection>
|
|
<DropdownSection title="Danger zone">
|
|
<DropdownItem
|
|
key="delete"
|
|
className="text-danger"
|
|
color="danger"
|
|
description="Delete the user permanently"
|
|
textValue="Delete User"
|
|
startContent={
|
|
<DeleteDocumentBulkIcon
|
|
className={clsx(iconClasses, "!text-danger")}
|
|
/>
|
|
}
|
|
onPress={() => setIsDeleteOpen(true)}
|
|
>
|
|
Delete User
|
|
</DropdownItem>
|
|
</DropdownSection>
|
|
</DropdownMenu>
|
|
</Dropdown>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|