mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-09-20 10:10:14 +00:00
* feat: add user_template setting * style: header * style: page padding * style: header * feat: header now time * style: login page * feat: nav indicator * style: button inset shadow * style: footer text size * feat: header show login_ip * fix: error toast * fix: frontend_templates setting * fix: lint * feat: pr auto format * chore: auto-fix linting and formatting issues --------- Co-authored-by: hamster1963 <hamster1963@users.noreply.github.com>
86 lines
2.9 KiB
TypeScript
86 lines
2.9 KiB
TypeScript
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<E, U> {
|
|
className?: string
|
|
children?: React.ReactNode
|
|
delete: { fn: (id: E[]) => Promise<void>; id: E[]; mutate: KeyedMutator<U> }
|
|
}
|
|
|
|
export function HeaderButtonGroup<E, U>({
|
|
className,
|
|
children,
|
|
delete: { fn, id, mutate },
|
|
}: ButtonGroupProps<E, U>) {
|
|
const { t } = useTranslation()
|
|
|
|
const handleDelete = async () => {
|
|
try {
|
|
await fn(id)
|
|
} catch (error: any) {
|
|
toast(t("Error"), {
|
|
description: error.message,
|
|
})
|
|
}
|
|
await mutate()
|
|
}
|
|
return (
|
|
<div className={className}>
|
|
{id.length < 1 ? (
|
|
<>
|
|
<IconButton
|
|
variant="destructive"
|
|
icon="trash"
|
|
onClick={() => {
|
|
toast(t("Error"), {
|
|
description: t("Results.NoRowsAreSelected"),
|
|
})
|
|
}}
|
|
/>
|
|
{children}
|
|
</>
|
|
) : (
|
|
<>
|
|
<AlertDialog>
|
|
<AlertDialogTrigger asChild>
|
|
<IconButton variant="destructive" icon="trash" />
|
|
</AlertDialogTrigger>
|
|
<AlertDialogContent className="sm:max-w-lg">
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{t("ConfirmDeletion")}</AlertDialogTitle>
|
|
<AlertDialogDescription>
|
|
{t("Results.ThisOperationIsUnrecoverable")}
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>{t("Close")}</AlertDialogCancel>
|
|
<AlertDialogAction
|
|
className={buttonVariants({ variant: "destructive" })}
|
|
onClick={handleDelete}
|
|
>
|
|
{t("Confirm")}
|
|
</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
{children}
|
|
</>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|