| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- "use client";
- import { useState } from "react";
- import { Button } from "@/components/ui/button";
- import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- } from "@/components/ui/dialog";
- import { deleteLayoutSection } from "@/app/actions/layout-configurations";
- import { useToast } from "@/hooks/use-toast";
- interface DeleteSectionDialogProps {
- open: boolean;
- onOpenChange: (open: boolean) => void;
- section: {
- id: number;
- name: string;
- };
- onSuccess?: () => void;
- }
- export function DeleteSectionDialog({
- open,
- onOpenChange,
- section,
- onSuccess,
- }: DeleteSectionDialogProps) {
- const [isDeleting, setIsDeleting] = useState(false);
- const { toast } = useToast();
- const handleDelete = async () => {
- setIsDeleting(true);
- try {
- const result = await deleteLayoutSection(section.id);
-
- if (result.success) {
- toast({
- title: "Section deleted",
- description: `Successfully deleted section "${section.name}"`,
- });
- onOpenChange(false);
- onSuccess?.();
- } else {
- toast({
- title: "Error",
- description: result.error || "Failed to delete section",
- variant: "destructive",
- });
- }
- } catch {
- toast({
- title: "Error",
- description: "An unexpected error occurred while deleting the section",
- variant: "destructive",
- });
- } finally {
- setIsDeleting(false);
- }
- };
- return (
- <Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Delete Section</DialogTitle>
- <DialogDescription>
- Are you sure you want to delete the section "{section.name}"? This action
- cannot be undone. All fields within this section will also be deleted.
- </DialogDescription>
- </DialogHeader>
- <DialogFooter>
- <Button
- variant="outline"
- onClick={() => onOpenChange(false)}
- disabled={isDeleting}
- >
- Cancel
- </Button>
- <Button
- variant="destructive"
- onClick={handleDelete}
- disabled={isDeleting}
- >
- {isDeleting ? "Deleting..." : "Delete"}
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- );
- }
|