import {Ticket, TicketType, TicketTypeLabel} from "@/interfaces/ticket"; import {User} from "@/interfaces/user"; import axios from "axios"; import {useState} from "react"; import {toast} from "react-toastify"; import ShortUniqueId from "short-unique-id"; import Button from "../Low/Button"; import Input from "../Low/Input"; import Select from "../Low/Select"; interface Props { user: User; page: string; onClose: () => void; } export default function TicketSubmission({user, page, onClose}: Props) { const [subject, setSubject] = useState(""); const [type, setType] = useState(); const [description, setDescription] = useState(""); const [isLoading, setIsLoading] = useState(false); const submit = () => { if (!type) return toast.error("Please choose a type!", {toastId: "missing-type"}); if (subject.trim() === "") return toast.error("Please input a subject!", { toastId: "missing-subject", }); if (description.trim() === "") return toast.error("Please describe your ticket!", { toastId: "missing-desc", }); setIsLoading(true); const shortUID = new ShortUniqueId(); const ticket: Ticket = { id: shortUID.randomUUID(8), date: new Date().toISOString(), reporter: { id: user.id, email: user.email, name: user.name, type: user.type, }, status: "submitted", subject, type, reportedFrom: page, description, }; axios .post(`/api/tickets`, ticket) .then(() => { toast.success(`Your ticket has been submitted! You will be contacted by e-mail for further discussion.`, {toastId: "submitted"}); onClose(); }) .catch((e) => { console.error(e); toast.error("Something went wrong, please try again later!", { toastId: "error", }); }) .finally(() => setIsLoading(false)); }; return (
setSubject(e)} />
null} value={`${user.name} - ${user.email}`} disabled />