"use client"; import React from "react"; import { useState, useRef, useEffect } from "react"; import styles from "../../../../styles/modules/AdminArticlesCreate.module.scss"; import { PostArticle } from "../../../../types/postData"; import Markdown from "../../../Markdown"; import { Category } from "@prisma/client"; import "../../../../styles/inputs.scss"; import Select, { GroupBase, OptionsOrGroups } from "react-select"; import { apiUrl } from "../../../global"; import urlJoin from "url-join"; import { getUrlSafeString } from "../../../utils"; export default function AdminArticlesCreate() { const [formData, setFormData] = useState(null); const [title, setTitle] = useState(""); const [markdown, setMarkdown] = useState(""); const [selectCategoriesOptions, setSelectCategoriesOptions] = useState([]); const titleRef = useRef(null); const categorySelectRef = useRef(null); const introductionRef = useRef(null); const markdownTextAreaRef = useRef(null); function handleFormChange() { setMarkdown(markdownTextAreaRef.current.value); setTitle(titleRef.current.value); setFormData({ name: getUrlSafeString(titleRef.current.value), title: titleRef.current.value, introduction: introductionRef.current.value, markdown: markdown, categoryId: Number(categorySelectRef?.current?.getValue()[0]?.value), }); } async function postData() { console.log(formData); await fetch("/api/articles/create", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify(formData), }); } useEffect(() => { const fetchCategoryOptions = async () => { const result: Response = await fetch(urlJoin(apiUrl, `categories`), { cache: "no-cache", next: { revalidate: 60 * 1 }, }); console.log(); const categories = await result.json(); let newSelectCategoriesOptions = []; categories?.forEach((c) => { newSelectCategoriesOptions.push({ value: c.id, label: c.title }); }); setSelectCategoriesOptions(newSelectCategoriesOptions); }; fetchCategoryOptions().catch((err) => { console.log(err); }); }, []); return (

Create a new article

contenttable
); }