完成博客权限修改

This commit is contained in:
2025-06-23 00:07:23 +08:00
parent a38463837f
commit edc605fb62
10 changed files with 178 additions and 2 deletions

View File

@@ -0,0 +1,82 @@
'use client';
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { AdminApi } from "@/lib/api";
import React, { useEffect, useState } from "react";
import { toast } from "sonner";
interface SetPasswordDialogProps {
id: string;
children: React.ReactNode;
}
export function SetPasswordDialog({ id, children }: SetPasswordDialogProps) {
const [open, setOpen] = useState(false);
const [password, setPassword] = useState('');
const handleSubmit = async () => {
if (!password) {
return toast.error('请输入密码');
}
await AdminApi.web.blog.setPassword(id, password).then(() => {
toast.success('修改成功');
setOpen(false);
}).catch(e => {
toast.error(`${e.message || e || '请求失败'}`)
});
}
useEffect(() => {
if (open) {
setPassword('');
}
}, [open])
return (
<Dialog open={open} onOpenChange={v => setOpen(v)}>
<form>
<DialogTrigger asChild>
{children}
</DialogTrigger>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle></DialogTitle>
<DialogDescription>
访
</DialogDescription>
</DialogHeader>
<div className="grid gap-4">
<div className="grid gap-3">
<Label htmlFor="new-password"></Label>
<Input
id="new-password"
name="password"
value={password}
onChange={e => setPassword(e.target.value)}
/>
</div>
</div>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline"></Button>
</DialogClose>
<Button type="submit" onClick={handleSubmit}></Button>
</DialogFooter>
</DialogContent>
</form>
</Dialog>
)
}