diff --git a/components/form/magazine/create-magazine-form.tsx b/components/form/magazine/create-magazine-form.tsx index 6575916..9c510e6 100644 --- a/components/form/magazine/create-magazine-form.tsx +++ b/components/form/magazine/create-magazine-form.tsx @@ -81,6 +81,9 @@ const createArticleSchema = z.object({ }), }) ), + category: z.array(categorySchema).nonempty({ + message: "Kategori harus memiliki setidaknya satu item", + }), }); export default function NewCreateMagazineForm() { @@ -90,6 +93,30 @@ export default function NewCreateMagazineForm() { const editor = useRef(null); const [files, setFiles] = useState([]); const [thumbnailImg, setThumbnailImg] = useState([]); + const [listCategory, setListCategory] = useState([]); + + useEffect(() => { + fetchCategory(); + }, []); + + const fetchCategory = async () => { + const res = await getArticleByCategory(); + if (res?.data?.data) { + setupCategory(res?.data?.data); + } + }; + + const setupCategory = (data: any) => { + const temp = []; + for (const element of data) { + temp.push({ + id: element.id, + label: element.title, + value: element.id, + }); + } + setListCategory(temp); + }; const { getRootProps, getInputProps } = useDropzone({ onDrop: (acceptedFiles) => { @@ -153,6 +180,8 @@ export default function NewCreateMagazineForm() { typeId: 1, slug: values.slug, statusId: 1, + categoryIds: values.category.map((a) => a.id).join(","), + // description: htmlToString(removeImgTags(values.description)), description: values.description, // rows: values.rows, @@ -385,6 +414,37 @@ export default function NewCreateMagazineForm() { {errors?.slug && (

{errors.slug?.message}

)} + +

Kategori

+ ( + + "!rounded-lg bg-white !border-1 !border-gray-200 dark:!border-stone-500", + }} + classNamePrefix="select" + onChange={onChange} + closeMenuOnSelect={false} + components={animatedComponents} + isClearable={true} + isSearchable={true} + isMulti={true} + placeholder="Kategori..." + name="sub-module" + options={listCategory} + /> + )} + /> + {errors?.category && ( +

+ {errors.category?.message} +

+ )} +

Thumbnail

{thumbnailImg.length > 0 ? ( diff --git a/components/main/dashboard/dashboard-container.tsx b/components/main/dashboard/dashboard-container.tsx index e216131..fc027bd 100644 --- a/components/main/dashboard/dashboard-container.tsx +++ b/components/main/dashboard/dashboard-container.tsx @@ -89,6 +89,15 @@ export default function DashboardContainer() { endDate: parseDate(convertDateFormatNoTimeV2(new Date())), }); + const [topContentDate, setTopContentDate] = useState({ + startDate: parseDate( + convertDateFormatNoTimeV2( + new Date(new Date().setDate(new Date().getDate() - 7)) + ) + ), + endDate: parseDate(convertDateFormatNoTimeV2(new Date())), + }); + const [typeDate, setTypeDate] = useState("monthly"); const [summary, setSummary] = useState(); @@ -122,7 +131,17 @@ export default function DashboardContainer() { useEffect(() => { fetchTopPages(); - }, [topPagespage]); + }, [topPagespage, topContentDate]); + + const getDate = (data: any) => { + if (data === null) { + return ""; + } else { + return `${data.year}-${data.month < 10 ? `0${data.month}` : data.month}-${ + data.day < 10 ? `0${data.day}` : data.day + }`; + } + }; async function fetchTopPages() { const req = { @@ -130,6 +149,8 @@ export default function DashboardContainer() { page: topPagespage, search: "", sort: "desc", + startDate: getDate(topContentDate.startDate), + endDate: getDate(topContentDate.endDate), }; const res = await getTopArticles(req); setTopPages(getTableNumber(10, res.data?.data)); @@ -139,6 +160,7 @@ export default function DashboardContainer() { useEffect(() => { fetchPostCount(); }, [postContentDate]); + async function fetchPostCount() { const getDate = (data: any) => { return `${data.year}-${data.month < 10 ? `0${data.month}` : data.month}-${ @@ -432,14 +454,6 @@ export default function DashboardContainer() { Mingguan
- {/* setStartDateValue(e)} - inputClassName="z-50 w-full text-xs lg:text-sm bg-transparent border-1 border-gray-200 px-2 py-[6px] rounded-sm lg:rounded-lg h-[30px] lg:h-[40px] text-gray-600 dark:text-gray-300" - /> */}

Top Pages

+
+ + + + {convertDateFormatNoTime(topContentDate.startDate)} + + + + + setTopContentDate({ + startDate: e, + endDate: topContentDate.endDate, + }) + } + maxValue={topContentDate.endDate} + /> + + + - + + + + {convertDateFormatNoTime(topContentDate.endDate)} + + + + + setTopContentDate({ + startDate: topContentDate.startDate, + endDate: e, + }) + } + minValue={topContentDate.startDate} + /> + + +
No
Title
Visits
+ {(!topPages || topPages?.length < 1) && ( +
+ Tidak ada Data +
+ )} {topPages?.map((list) => (
{list?.no}
@@ -485,23 +551,25 @@ export default function DashboardContainer() {
{list?.viewCount}
))} -
- setTopPagesPage(page)} - /> -
+ {topPages?.length > 0 && ( +
+ setTopPagesPage(page)} + /> +
+ )}