add close to notif

This commit is contained in:
Kentai Radiquum 2025-05-05 23:25:28 +05:00
parent afc9504dd2
commit 9d9bfa8aa8
Signed by: Radiquum
GPG key ID: 858E8EE696525EED

View file

@ -13,7 +13,7 @@ import { toast } from "react-toastify";
const mcr = mc.reverse(); const mcr = mc.reverse();
export default function PackNew() { export default function PackNew() {
const router = useRouter() const router = useRouter();
const [image, setImage] = useState<null | string>(null); const [image, setImage] = useState<null | string>(null);
const [imageMime, setImageMime] = useState<null | string>(null); const [imageMime, setImageMime] = useState<null | string>(null);
const [packInfo, setPackInfo] = useState({ const [packInfo, setPackInfo] = useState({
@ -50,7 +50,7 @@ export default function PackNew() {
e.preventDefault(); e.preventDefault();
async function _submit() { async function _submit() {
const tid = toast.loading(`Creating Pack "${packInfo.title}"`) const tid = toast.loading(`Creating Pack "${packInfo.title}"`);
const res = await fetch(PACKS_ENDPOINT("createPack"), { const res = await fetch(PACKS_ENDPOINT("createPack"), {
method: "POST", method: "POST",
@ -63,7 +63,14 @@ export default function PackNew() {
const data = await res.json(); const data = await res.json();
if (data.status != "ok") { if (data.status != "ok") {
toast.update(tid, {render: data.message, type: "error", isLoading: false}) toast.update(tid, {
render: data.message,
type: "error",
isLoading: false,
autoClose: 2500,
closeOnClick: true,
draggable: true,
});
return; return;
} }
@ -72,7 +79,7 @@ export default function PackNew() {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
image: image, image: image,
mimetype: imageMime mimetype: imageMime,
}), }),
headers: { headers: {
"content-type": "application/json", "content-type": "application/json",
@ -81,8 +88,15 @@ export default function PackNew() {
}); });
} }
toast.update(tid, {render: data.message, type: "success", isLoading: false}) toast.update(tid, {
router.push(`/pack/?id=${data.id}`) render: data.message,
type: "success",
isLoading: false,
autoClose: 2500,
closeOnClick: true,
draggable: true,
});
router.push(`/pack/?id=${data.id}`);
} }
_submit(); _submit();