{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "action-button", "description": "A button that performs an action when clicked and optionally asks for user confirmation.", "registryDependencies": [ "alert-dialog", "button", "sonner", "https://aqt-ui.netlify.app/r/loading-swap.json" ], "files": [ { "path": "src/registry/new-york/items/action-button/components/action-button.tsx", "content": "\"use client\"\n\nimport { type ComponentProps, type ReactNode, useTransition } from \"react\"\nimport { Button } from \"@/components/ui/button\"\nimport { toast } from \"sonner\"\nimport { LoadingSwap } from \"@/components/ui/loading-swap\"\nimport {\n AlertDialog,\n AlertDialogDescription,\n AlertDialogTitle,\n AlertDialogAction,\n AlertDialogCancel,\n AlertDialogContent,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogTrigger,\n} from \"@/components/ui/alert-dialog\"\n\nexport function ActionButton({\n action,\n requireAreYouSure = false,\n areYouSureDescription = \"This action cannot be undone.\",\n ...props\n}: ComponentProps & {\n action: () => Promise<{ error: boolean; message?: string }>\n requireAreYouSure?: boolean\n areYouSureDescription?: ReactNode\n}) {\n const [isLoading, startTransition] = useTransition()\n\n function performAction() {\n startTransition(async () => {\n const data = await action()\n if (data.error) toast.error(data.message ?? \"Error\")\n })\n }\n\n if (requireAreYouSure) {\n return (\n \n \n \n )\n}\n", "type": "registry:ui" } ], "type": "registry:component" }