实现资源删除管理

This commit is contained in:
2025-05-12 22:13:09 +08:00
parent 53665f8847
commit 5159fa3606

View File

@@ -22,6 +22,18 @@ import { AdminApi } from "@/lib/api"
import useSWR from "swr" import useSWR from "swr"
import { ApiError } from "next/dist/server/api-utils" import { ApiError } from "next/dist/server/api-utils"
import { Skeleton } from "@/components/ui/skeleton" import { Skeleton } from "@/components/ui/skeleton"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
interface ResourceEditProps { interface ResourceEditProps {
children: React.ReactNode children: React.ReactNode
id: string; id: string;
@@ -60,6 +72,17 @@ export default function ResourceEdit({ children, id, onRefresh }: ResourceEditPr
} }
} }
const handleRemove = async (id: string) => {
try {
await AdminApi.web.resource.remove(id);
toast.success("资源删除成功");
onRefresh();
setOpen(false);
} catch (error) {
toast.error((error as ApiError).message || "资源删除失败");
}
}
return ( return (
<Dialog open={open} onOpenChange={setOpen}> <Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild> <DialogTrigger asChild>
@@ -154,7 +177,29 @@ export default function ResourceEdit({ children, id, onRefresh }: ResourceEditPr
</div> </div>
</div> </div>
<DialogFooter> <DialogFooter>
<Button type="submit" onClick={handleSubmit}></Button> <div className="w-full flex justify-between">
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant={'destructive'}></Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>?</AlertDialogTitle>
<AlertDialogDescription>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel></AlertDialogCancel>
<AlertDialogAction onClick={() => handleRemove(id)}></AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<div >
<Button variant={'secondary'} onClick={() => setOpen(false)}></Button>
<Button type="button" onClick={handleSubmit} className="ml-3"></Button>
</div>
</div>
</DialogFooter> </DialogFooter>
</> </>
)} )}