import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog" import { buttonVariants } from "@/components/ui/button" import { IconButton } from "@/components/xui/icon-button" import { useTranslation } from "react-i18next" import { toast } from "sonner" import { KeyedMutator } from "swr" interface ButtonGroupProps { className?: string children?: React.ReactNode delete: { fn: (id: E[]) => Promise; id: E[]; mutate: KeyedMutator } } interface ButtonBlockGroupProps { className?: string children?: React.ReactNode block: { fn: (id: E[]) => Promise; id: E[]; mutate: KeyedMutator } } export function HeaderButtonGroup({ className, children, delete: { fn, id, mutate }, }: ButtonGroupProps) { const { t } = useTranslation() const handleDelete = async () => { try { await fn(id) } catch (error: any) { toast(t("Error"), { description: error.message, }) } await mutate() } return (
{id.length < 1 ? ( <> { toast(t("Error"), { description: t("Results.NoRowsAreSelected"), }) }} /> {children} ) : ( <> {t("ConfirmDeletion")} {t("Results.ThisOperationIsUnrecoverable")} {t("Close")} {t("Confirm")} {children} )}
) } export function HeaderBlockButtonGroup({ className, children, block: { fn, id, mutate }, }: ButtonBlockGroupProps) { const { t } = useTranslation() const handleBlock = async () => { try { await fn(id) } catch (error: any) { toast(t("Error"), { description: error.message, }) } await mutate() } return (
{id.length < 1 ? ( <> { toast(t("Error"), { description: t("Results.NoRowsAreSelected"), }) }} /> {children} ) : ( <> {t("ConfirmBlock")} {t("Results.ThisOperationIsUnrecoverable")} {t("Close")} {t("Confirm")} {children} )}
) }