diff --git a/app/(admin)/admin/article/page.tsx b/app/(admin)/admin/article/page.tsx
index f71a4fd..60b34ad 100644
--- a/app/(admin)/admin/article/page.tsx
+++ b/app/(admin)/admin/article/page.tsx
@@ -1,24 +1,25 @@
-"use client"
+"use client";
import { AddIcon } from "@/components/icons";
import ArticleTable from "@/components/table/article-table";
import { Button, Card } from "@nextui-org/react";
import Link from "next/link";
export default function BasicPage() {
- return (
-
-
-
-
-
-
-
-
-
-
-
+ return (
+
+ );
}
diff --git a/components/form/form-article.tsx b/components/form/form-article.tsx
index 72ddd67..674556d 100644
--- a/components/form/form-article.tsx
+++ b/components/form/form-article.tsx
@@ -1,328 +1,394 @@
-'use client'
-import { error } from '@/config/swal';
-import { createArticle } from '@/service/article';
-import { zodResolver } from '@hookform/resolvers/zod';
-import { Button, Card, Chip, Input, Select, SelectItem, Selection } from '@nextui-org/react';
-import JoditEditor from 'jodit-react';
-import Link from 'next/link';
-import { useRouter } from 'next/navigation';
-import React, { ChangeEvent, useRef, useState } from 'react';
-import { useForm } from 'react-hook-form';
-import Swal from 'sweetalert2';
-import withReactContent from 'sweetalert2-react-content';
+"use client";
+import { error } from "@/config/swal";
+import { createArticle } from "@/service/article";
+import { zodResolver } from "@hookform/resolvers/zod";
+import {
+ Button,
+ Card,
+ Chip,
+ Input,
+ Select,
+ SelectItem,
+ Selection,
+} from "@nextui-org/react";
+import JoditEditor from "jodit-react";
+import Link from "next/link";
+import { useRouter } from "next/navigation";
+import React, { ChangeEvent, useEffect, useRef, useState } from "react";
+import { useForm } from "react-hook-form";
+import Swal from "sweetalert2";
+import withReactContent from "sweetalert2-react-content";
import * as z from "zod";
+import ReactSelect from "react-select";
+import makeAnimated from "react-select/animated";
const articleSchema = z.object({
- title: z.string().min(1, { message: "Required" }),
- article: z.string().min(1, { message: "Required" }),
- slug: z.string().min(1, { message: "Required" }),
- tags: z.string().min(0, { message: "Required" }).optional(),
- description: z.string().min(0, { message: "Required" }).optional(),
-
+ title: z.string().min(1, { message: "Required" }),
+ article: z.string().min(1, { message: "Required" }),
+ slug: z.string().min(1, { message: "Required" }),
+ tags: z.string().min(0, { message: "Required" }).optional(),
+ description: z.string().min(0, { message: "Required" }).optional(),
});
+const dummyCategory = [
+ {
+ id: 1,
+ label: "Category 1",
+ value: "category-1",
+ },
+ {
+ id: 2,
+ label: "Category 2",
+ value: "category-2",
+ },
+ {
+ id: 3,
+ label: "Category 3",
+ value: "category-3",
+ },
+ {
+ id: 4,
+ label: "Category 4",
+ value: "category-4",
+ },
+ {
+ id: 5,
+ label: "Category 5",
+ value: "category-5",
+ },
+];
+
export default function FormArticle() {
- const router = useRouter();
- const [title, setTitle] = useState
("");
- const [article, setArticle] = React.useState(new Set([]));
- const [slug, setSlug] = useState("");
- const [tags, setTags] = useState([]);
- const [newTags, setNewTags] = useState("");
- const editor = useRef(null);
- const [content, setContent] = useState('');
- const MySwal = withReactContent(Swal);
- const [selectedImages, setSelectedImages] = useState([]);
+ const animatedComponents = makeAnimated();
- const formOptions = { resolver: zodResolver(articleSchema) };
- type MicroIssueSchema = z.infer;
- const {
- register,
- control,
- handleSubmit,
- setValue,
- formState: { errors },
- } = useForm(formOptions);
+ const router = useRouter();
+ const [title, setTitle] = useState("");
+ const [article, setArticle] = React.useState(new Set([]));
+ const [slug, setSlug] = useState("");
+ const [tags, setTags] = useState([]);
+ const [newTags, setNewTags] = useState("");
+ const editor = useRef(null);
+ const [content, setContent] = useState("");
+ const MySwal = withReactContent(Swal);
+ const [selectedImages, setSelectedImages] = useState([]);
+ const [selectedCategory, setSelectedCategory] = useState();
- const TypeId = [
- {
- key: 1,
- label: "Article"
- },
- {
- key: 2,
- label: "Magazine"
- },
- ]
+ useEffect(() => {
+ console.log("selected", selectedCategory);
+ }, [selectedCategory]);
- const handleImageChange = (event: ChangeEvent) => {
- if (event.target.files) {
- const files = Array.from(event.target.files);
- setSelectedImages((prevImages) => [...prevImages, ...files]);
- }
+ const formOptions = { resolver: zodResolver(articleSchema) };
+ type MicroIssueSchema = z.infer;
+ const {
+ register,
+ control,
+ handleSubmit,
+ setValue,
+ formState: { errors },
+ } = useForm(formOptions);
+
+ const TypeId = [
+ {
+ key: 1,
+ label: "Article",
+ },
+ {
+ key: 2,
+ label: "Magazine",
+ },
+ ];
+
+ const handleImageChange = (event: ChangeEvent) => {
+ if (event.target.files) {
+ const files = Array.from(event.target.files);
+ setSelectedImages((prevImages) => [...prevImages, ...files]);
+ }
+ };
+
+ const handleRemoveImage = (index: number) => {
+ setSelectedImages((prevImages) => prevImages.filter((_, i) => i !== index));
+ };
+
+ // const handleSubmitImage = (event: any) => {
+ // event.preventDefault();
+ // // Lakukan penanganan pengunggahan gambar di sini
+ // if (selectedImage) {
+ // console.log('Gambar yang dipilih:', selectedImage);
+ // // Anda dapat melakukan pengunggahan gambar ke server di sini
+ // } else {
+ // console.log('Pilih gambar terlebih dahulu.');
+ // }
+ // };
+
+ const handleClose = (tagsToRemove: string) => {
+ setTags(tags.filter((tag) => tag !== tagsToRemove));
+ if (tags.length === 1) {
+ setTags([]);
+ }
+ };
+
+ const handleAddTags = (e: any) => {
+ if (newTags.trim() !== "") {
+ setTags([...tags, newTags.trim()]);
+ setNewTags("");
+ e.preventDefault();
+ }
+ };
+
+ const handleKeyDown = (event: any) => {
+ if (event.key === "Enter") {
+ handleAddTags(event);
+ }
+ };
+
+ async function save(data: any) {
+ const formData = {
+ title: title,
+ typeId: parseInt(String(Array.from(article)[0])),
+ slug: slug,
+ tags: tags.join(","),
+ description: content,
+ htmlDescription: content,
};
- const handleRemoveImage = (index: number) => {
- setSelectedImages((prevImages) =>
- prevImages.filter((_, i) => i !== index)
- );
- };
+ console.log("Form Data:", formData);
+ const response = await createArticle(formData);
- // const handleSubmitImage = (event: any) => {
- // event.preventDefault();
- // // Lakukan penanganan pengunggahan gambar di sini
- // if (selectedImage) {
- // console.log('Gambar yang dipilih:', selectedImage);
- // // Anda dapat melakukan pengunggahan gambar ke server di sini
- // } else {
- // console.log('Pilih gambar terlebih dahulu.');
- // }
- // };
-
- const handleClose = (tagsToRemove: string) => {
- setTags(tags.filter((tag) => tag !== tagsToRemove));
- if (tags.length === 1) {
- setTags([]);
- }
- };
-
- const handleAddTags = (e: any) => {
- if (newTags.trim() !== "") {
- setTags([...tags, newTags.trim()]);
- setNewTags("");
- e.preventDefault();
- }
- };
-
- const handleKeyDown = (event: any) => {
- if (event.key === "Enter") {
- handleAddTags(event);
- }
- };
-
-
- async function save(data: any) {
- const formData = {
- title: title,
- typeId: parseInt(String(Array.from(article)[0])),
- slug: slug,
- tags: tags.join(','),
- description: content,
- htmlDescription: content,
- };
-
- console.log("Form Data:", formData);
- const response = await createArticle(formData);
-
- if (response?.error) {
- error(response.message);
- return false;
- }
-
- successSubmit("/admin/article");
- };
-
- function successSubmit(redirect: any) {
- MySwal.fire({
- title: "Sukses",
- icon: "success",
- confirmButtonColor: "#3085d6",
- confirmButtonText: "OK",
- }).then((result) => {
- if (result.isConfirmed) {
- router.push(redirect);
- }
- });
+ if (response?.error) {
+ error(response.message);
+ return false;
}
- async function onSubmit(data: any) {
- MySwal.fire({
- title: "Simpan Data",
- text: "",
- icon: "warning",
- showCancelButton: true,
- cancelButtonColor: "#d33",
- confirmButtonColor: "#3085d6",
- confirmButtonText: "Simpan",
- }).then((result) => {
- if (result.isConfirmed) {
- save(data);
- }
- });
- }
- return (
-