"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { DataTable } from "@/components/data-table/data-table"; import { useBucketList, useCreateBucket, useDeleteBucket } from "@/modules/cms/bucket/hooks"; import { useToast } from "@/hooks/use-toast"; import { Plus, Trash } from "lucide-react"; import { ColumnDef } from "@tanstack/react-table"; import { Bucket } from "@/modules/cms/bucket/schemas"; export default function BucketsPage() { const { toast } = useToast(); const { data, isLoading } = useBucketList(); const createMutation = useCreateBucket(); const deleteMutation = useDeleteBucket(); const [open, setOpen] = useState(false); const [bucketName, setBucketName] = useState(""); const [deleteBucket, setDeleteBucket] = useState<{ name: string; id: string } | null>(null); const handleCreate = async () => { if (!bucketName) return; try { await createMutation.mutateAsync({ bucketName }); toast({ title: "Bucket created", description: "Bucket created successfully" }); setOpen(false); setBucketName(""); } catch (error) { toast({ title: "Create failed", variant: "destructive" }); } }; const handleDelete = async () => { if (!deleteBucket) return; try { await deleteMutation.mutateAsync(deleteBucket.name); toast({ title: "Bucket deleted", description: "Bucket has been deleted successfully" }); setDeleteBucket(null); } catch (error) { toast({ title: "Delete failed", variant: "destructive" }); setDeleteBucket(null); } }; const columns: ColumnDef[] = [ { accessorKey: "name", header: "Bucket Name" }, { accessorKey: "policy", header: "Policy" }, { id: "actions", cell: ({ row }) => ( ), }, ]; const buckets = data?.data || []; return (

CMS Buckets

Manage storage buckets

Create Bucket
setBucketName(e.target.value)} placeholder="my-bucket" />
{isLoading ? (
Loading...
) : ( )} !open && setDeleteBucket(null)}> Delete Bucket Are you sure you want to delete bucket "{deleteBucket?.name}"? This action cannot be undone and will remove all data in this bucket. Cancel Delete
); }