"use client"; import { Card, FileInput } from "flowbite-react"; import { Label, TextInput, Select } from "flowbite-react"; import { useState } from "react"; import { HiUser, HiAnnotation } from "react-icons/hi"; import { Button } from "flowbite-react"; import { useRouter } from "next/navigation"; import mc from "../../../api/mc_version.json"; import { PACKS_ENDPOINT, PACK_ENDPOINT } from "@/api/ENDPOINTS"; import { toast } from "react-toastify"; const mcr = mc.reverse(); export default function PackNew() { const router = useRouter(); const [image, setImage] = useState(null); const [imageMime, setImageMime] = useState(null); const [packInfo, setPackInfo] = useState({ title: "", author: "", modloader: "Forge", version: "1.21.5", }); // eslint-disable-next-line @typescript-eslint/no-explicit-any const handleImagePreview = (e: any) => { const file = e.target.files[0]; const fileReader = new FileReader(); fileReader.onloadend = () => { const content = fileReader.result; setImage(content as string); setImageMime(file.type); e.target.value = ""; }; fileReader.readAsDataURL(file); }; // eslint-disable-next-line @typescript-eslint/no-explicit-any function handleInput(e: any) { const regex = /[^a-zA-Zа-яА-Я0-9_.()\- \[\]]/g; setPackInfo({ ...packInfo, [e.target.name]: e.target.value.replace(regex, ""), }); } // eslint-disable-next-line @typescript-eslint/no-explicit-any function submit(e: any) { e.preventDefault(); async function _submit() { const tid = toast.loading(`Creating Pack "${packInfo.title}"`); const res = await fetch(PACKS_ENDPOINT("createPack"), { method: "POST", body: JSON.stringify(packInfo), headers: { "content-type": "application/json", accept: "application/json", }, }); const data = await res.json(); if (data.status != "ok") { toast.update(tid, { render: data.message, type: "error", isLoading: false, autoClose: 2500, closeOnClick: true, draggable: true, }); return; } if (image) { await fetch(`${PACK_ENDPOINT("editPackImage", data.id)}`, { method: "POST", body: JSON.stringify({ image: image, mimetype: imageMime, }), headers: { "content-type": "application/json", accept: "application/json", }, }); } toast.update(tid, { render: data.message, type: "success", isLoading: false, autoClose: 2500, closeOnClick: true, draggable: true, }); router.push(`/pack/?id=${data.id}`); } _submit(); } return (
submit(e)} >
handleInput(e)} value={packInfo.title} icon={HiAnnotation} required />
handleInput(e)} value={packInfo.author} icon={HiUser} required />
); }