diff --git a/components/main/dashboard/chart/multiline-chart.tsx b/components/main/dashboard/chart/multiline-chart.tsx index 26f4dc3..d2c29b7 100644 --- a/components/main/dashboard/chart/multiline-chart.tsx +++ b/components/main/dashboard/chart/multiline-chart.tsx @@ -16,7 +16,7 @@ function getRangeAcrossMonths( const sortedData = data.sort((a, b) => a.month - b.month); console.log("sorted,data", sortedData); for (const monthData of sortedData) { - const { month, users: u } = monthData; + const { month, user_levels: u } = monthData; if (month < startMonth || month > endMonth) continue; console.log("uuu", month, startMonth, endMonth, u.length); @@ -70,7 +70,6 @@ const ApexMultiLineChart = (props: { useEffect(() => { initFetch(); - console.log("type", type); }, [date, type, range.start, range.end]); const initFetch = async () => { @@ -91,18 +90,11 @@ const ApexMultiLineChart = (props: { ); console.log("fetch", res?.data?.data); data = res?.data?.data; - data = dummy.data; + // data = dummy.data; setDatas(data); } if (type === "daily") { - console.log( - "aaa", - range.start.month, - range.start.day, - range.end.month, - range.end.day - ); const mappedData = getRangeAcrossMonths( data, range.start.month, @@ -121,8 +113,8 @@ const ApexMultiLineChart = (props: { a.month == Number(splitDate[0]) && a.year === Number(splitDate[1]) ); if (getDatas) { - console.log("datanya", getDatas.users); - setSeries(getDatas.users); + console.log("datanya", getDatas.user_levels); + setSeries(getDatas.user_levels); } else { setSeries([]); } @@ -226,7 +218,7 @@ const ApexMultiLineChart = (props: { text: "Articles", }, min: 0, - max: 50, + max: 70, }, legend: { position: "right", diff --git a/components/main/dashboard/dashboard-container.tsx b/components/main/dashboard/dashboard-container.tsx index f580049..e0334e6 100644 --- a/components/main/dashboard/dashboard-container.tsx +++ b/components/main/dashboard/dashboard-container.tsx @@ -1023,7 +1023,7 @@ export default function DashboardContainer() { {roleId && Number(roleId) < 3 && (
- +
diff --git a/components/ui/breadcrumb.tsx b/components/ui/breadcrumb.tsx index 1115a47..04285cb 100644 --- a/components/ui/breadcrumb.tsx +++ b/components/ui/breadcrumb.tsx @@ -34,8 +34,6 @@ export const Breadcrumb = () => { return capitalizedWords.join(" "); }); - console.log("pathname : ", pathnameTransformed); - useEffect(() => { setCurrentPage(pathnameSplit[pathnameSplit.length - 1]); }, [pathnameSplit]); diff --git a/components/ui/maps-charts.tsx b/components/ui/maps-charts.tsx index 8c5e666..90fd1b5 100644 --- a/components/ui/maps-charts.tsx +++ b/components/ui/maps-charts.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useRef, useState } from "react"; +import React, { useEffect, useMemo, useRef, useState } from "react"; import * as echarts from "echarts"; import indonesiaGeo from "../../public/assets/geo/indonesia.json"; import { getStatisticForMaps } from "@/services/article"; @@ -9,8 +9,33 @@ import { parseZonedDateTime, parseAbsoluteToLocal, } from "@internationalized/date"; +import { + Button, + DateRangePicker, + Popover, + PopoverContent, + PopoverTrigger, + Select, + SelectItem, +} from "@heroui/react"; +import { format } from "date-fns"; +import { ChevronLeftIcon, ChevronRightIcon } from "../icons"; +const months = [ + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec", +]; -const IndonesiaMap = (props: { data: any }) => { +const IndonesiaMap = () => { const chartRef = useRef(null); const myChart = useRef(null); const [selectedProvince, setSelectedProvince] = useState(""); @@ -31,11 +56,15 @@ const IndonesiaMap = (props: { data: any }) => { end: parseDate(convertDateFormatNoTimeV2(today)), }); - const [data, setData] = useState([]); + const handleMonthClick = (monthIndex: number) => { + setSelectedMonth(new Date(year, monthIndex, 1)); + }; + const [minMax, setMinMax] = useState({ min: 0, max: 0 }); + const [data, setData] = useState<{ name: string; value: number }[]>([]); useEffect(() => { fetchData(); - }, []); + }, [viewsDailyDate]); const fetchData = async () => { const getDate = (data: any) => { @@ -48,53 +77,76 @@ const IndonesiaMap = (props: { data: any }) => { getDate(viewsDailyDate.start), getDate(viewsDailyDate.end) ); - setData(res?.data?.data); + if (res?.data?.data) { + const temp = []; + let min = Infinity; + let max = -Infinity; + for (const element of res?.data?.data) { + const value = element.totalVisitor; + + const now = { + name: element.regionName.toUpperCase(), + value, + }; + + if (value < min) min = value; + if (value > max) max = value; + temp.push(now); + } + setData(temp); + setMinMax({ min: min, max: max }); + } else { + setData([]); + setMinMax({ min: 0, max: 0 }); + } }; - const option = { - backgroundColor: "#d3d3d3", - title: { - text: "Sebaran Data", - left: "center", - textStyle: { color: "#000" }, - }, - visualMap: { - min: 0, - max: 100, - show: true, - seriesIndex: 0, - inRange: { - color: ["#ff0000", "#ffffff"], + const option = useMemo( + () => ({ + backgroundColor: "#d3d3d3", + title: { + text: "Sebaran Data", + left: "center", + textStyle: { color: "#000" }, }, - }, - series: [ - { - type: "map", - map: "indonesia", - - roam: true, - zoom: 1.2, - center: [118, -2], - label: { - show: false, - color: "#000", + visualMap: { + min: minMax.min, + max: minMax.max, + show: true, + seriesIndex: 0, + inRange: { + color: ["#ff0000", "#ffffff"], }, - itemStyle: { - borderColor: "#999", - }, - emphasis: { + }, + series: [ + { + type: "map", + map: "indonesia", + roam: true, + zoom: 1.2, + center: [118, -2], label: { - show: true, + show: false, color: "#000", }, itemStyle: { - areaColor: "#ffcccc", + borderColor: "#999", }, + emphasis: { + label: { + show: true, + color: "#000", + }, + itemStyle: { + areaColor: "#ffcccc", + }, + }, + data: data, }, - data: data, - }, - ], - }; + ], + }), + [data, minMax] + ); useEffect(() => { if (!chartRef.current) return; @@ -127,7 +179,15 @@ const IndonesiaMap = (props: { data: any }) => { }; }, []); + useEffect(() => { + if (!myChart.current) return; + + chartOptionRef.current = option; + myChart.current.setOption(option); + }, [option]); + const highlightProvince = (name: string) => { + console.log("nameeed", name); if (!myChart.current || !chartOptionRef.current) return; myChart.current.clear(); @@ -144,6 +204,7 @@ const IndonesiaMap = (props: { data: any }) => { }); selectedProvinceRef.current = name; + setSelectedProvince(name); }; return ( @@ -152,24 +213,98 @@ const IndonesiaMap = (props: { data: any }) => {
- {props.data.map((list: any) => ( - highlightProvince(list.name)} - className={`w-full flex flex-row cursor-pointer gap-2 ${ - selectedProvince === list.name ? "bg-slate-300" : "" - }`} +
+ {/* */} + + {typeDate === "monthly" ? ( + + + + + +
+ + {year} + +
+ +
+ {months.map((month, idx) => ( + + ))} +
+
+
+ ) : ( +
+ e !== null && setViewsDailyDate(e)} + label="" + /> +
+ )} +
+ {data?.length > 0 && + data?.map((list: any) => ( +
highlightProvince(list.name)} + className={`w-full flex flex-row cursor-pointer gap-2 ${ + selectedProvince === list.name ? "bg-slate-300" : "" + }`} > - {list.value} -

-
- ))} +

{list.name}

{" "} +

+ {list.value} +

+ + ))}
); diff --git a/public/assets/geo/indonesia.json b/public/assets/geo/indonesia.json index d76e247..e5643b5 100644 --- a/public/assets/geo/indonesia.json +++ b/public/assets/geo/indonesia.json @@ -1283,7 +1283,7 @@ ] ] }, - "properties": { "KODE_PROV": "72", "PROVINSI": "Sulawesi Tengah" }, + "properties": { "KODE_PROV": "72", "PROVINSI": "CENTRAL SULAWESI" }, "id": "72" }, { @@ -1540,7 +1540,7 @@ ] ] }, - "properties": { "KODE_PROV": "76", "PROVINSI": "Sulawesi Barat" }, + "properties": { "KODE_PROV": "76", "PROVINSI": "WEST SULAWESI" }, "id": "76" }, { @@ -2189,7 +2189,7 @@ ] ] }, - "properties": { "KODE_PROV": "73", "PROVINSI": "Sulawesi Selatan" }, + "properties": { "KODE_PROV": "73", "PROVINSI": "SOUTH SULAWESI" }, "id": "73" }, { @@ -2731,7 +2731,7 @@ ] ] }, - "properties": { "KODE_PROV": "91", "PROVINSI": "Papua Tengah" }, + "properties": { "KODE_PROV": "91", "PROVINSI": "CENTRAL PAPUA" }, "id": "91-D" }, { @@ -4021,7 +4021,7 @@ ] ] }, - "properties": { "KODE_PROV": "92", "PROVINSI": "Papua Barat" }, + "properties": { "KODE_PROV": "92", "PROVINSI": "WEST PAPUA" }, "id": "92-A" }, { @@ -5616,7 +5616,7 @@ ] ] }, - "properties": { "KODE_PROV": "91", "PROVINSI": "Papua Selatan" }, + "properties": { "KODE_PROV": "91", "PROVINSI": "SOUTH PAPUA" }, "id": "91-C" }, { @@ -5691,7 +5691,7 @@ }, "properties": { "KODE_PROV": "34", - "PROVINSI": "Daerah Istimewa Yogyakarta" + "PROVINSI": "YOGYAKARTA" }, "id": "34" }, @@ -6288,7 +6288,7 @@ ] ] }, - "properties": { "KODE_PROV": "13", "PROVINSI": "Sumatera Barat" }, + "properties": { "KODE_PROV": "13", "PROVINSI": "WEST SUMATRA" }, "id": "13" }, { @@ -6332,7 +6332,7 @@ ] ] }, - "properties": { "KODE_PROV": "31", "PROVINSI": "DKI Jakarta" }, + "properties": { "KODE_PROV": "31", "PROVINSI": "JAKARTA" }, "id": "31" }, { @@ -8497,7 +8497,7 @@ ] ] }, - "properties": { "KODE_PROV": "81", "PROVINSI": "Maluku" }, + "properties": { "KODE_PROV": "81", "PROVINSI": "MALUKU" }, "id": "81" }, { @@ -10070,7 +10070,7 @@ ] ] }, - "properties": { "KODE_PROV": "91", "PROVINSI": "Papua" }, + "properties": { "KODE_PROV": "91", "PROVINSI": "PAPUA" }, "id": "91-A" }, { @@ -11167,7 +11167,7 @@ ] ] }, - "properties": { "KODE_PROV": "21", "PROVINSI": "Kepulauan Riau" }, + "properties": { "KODE_PROV": "21", "PROVINSI": "RIAU ISLANDS" }, "id": "21" }, { @@ -11714,7 +11714,7 @@ ] ] }, - "properties": { "KODE_PROV": "52", "PROVINSI": "Nusa Tenggara Barat" }, + "properties": { "KODE_PROV": "52", "PROVINSI": "WEST NUSA TENGGARA" }, "id": "52" }, { @@ -12027,7 +12027,7 @@ ] ] }, - "properties": { "KODE_PROV": "15", "PROVINSI": "Jambi" }, + "properties": { "KODE_PROV": "15", "PROVINSI": "JAMBI" }, "id": "15" }, { @@ -12168,7 +12168,7 @@ ] ] }, - "properties": { "KODE_PROV": "51", "PROVINSI": "Bali" }, + "properties": { "KODE_PROV": "51", "PROVINSI": "BALI" }, "id": "51" }, { @@ -12866,7 +12866,7 @@ ] ] }, - "properties": { "KODE_PROV": "35", "PROVINSI": "Jawa Timur" }, + "properties": { "KODE_PROV": "35", "PROVINSI": "EAST JAVA" }, "id": "35" }, { @@ -13685,7 +13685,7 @@ ] ] }, - "properties": { "KODE_PROV": "92", "PROVINSI": "Papua Barat Daya" }, + "properties": { "KODE_PROV": "92", "PROVINSI": "SOUTHWEST PAPUA" }, "id": "92-B" }, { @@ -14339,7 +14339,7 @@ ] ] }, - "properties": { "KODE_PROV": "12", "PROVINSI": "Sumatera Utara" }, + "properties": { "KODE_PROV": "12", "PROVINSI": "NORTH SUMATRA" }, "id": "12" }, { @@ -15158,7 +15158,7 @@ ] ] }, - "properties": { "KODE_PROV": "74", "PROVINSI": "Sulawesi Tenggara" }, + "properties": { "KODE_PROV": "74", "PROVINSI": "SOUTHEAST SULAWESI" }, "id": "74" }, { @@ -16418,7 +16418,7 @@ ] ] }, - "properties": { "KODE_PROV": "53", "PROVINSI": "Nusa Tenggara Timur" }, + "properties": { "KODE_PROV": "53", "PROVINSI": "EAST NUSA TENGGARA" }, "id": "53" }, { @@ -16830,7 +16830,7 @@ ] ] }, - "properties": { "KODE_PROV": "63", "PROVINSI": "Kalimantan Selatan" }, + "properties": { "KODE_PROV": "63", "PROVINSI": "SOUTH KALIMANTAN" }, "id": "63" }, { @@ -17371,7 +17371,7 @@ ] ] }, - "properties": { "KODE_PROV": "11", "PROVINSI": "Aceh" }, + "properties": { "KODE_PROV": "11", "PROVINSI": "ACEH" }, "id": "11" }, { @@ -17988,7 +17988,7 @@ ] ] }, - "properties": { "KODE_PROV": "62", "PROVINSI": "Kalimantan Tengah" }, + "properties": { "KODE_PROV": "62", "PROVINSI": "CENTRAL KALIMANTAN" }, "id": "62" }, { @@ -18458,7 +18458,7 @@ ] ] }, - "properties": { "KODE_PROV": "91", "PROVINSI": "Papua Pegunungan" }, + "properties": { "KODE_PROV": "91", "PROVINSI": "HIGHLAND PAPUA" }, "id": "91-B" }, { @@ -18847,7 +18847,7 @@ }, "properties": { "KODE_PROV": "19", - "PROVINSI": "Kepulauan Bangka Belitung" + "PROVINSI": "BANGKA BELITUNG ISLANDS" }, "id": "19" }, @@ -19364,7 +19364,7 @@ ] ] }, - "properties": { "KODE_PROV": "16", "PROVINSI": "Sumatera Selatan" }, + "properties": { "KODE_PROV": "16", "PROVINSI": "SOUTH SUMATRA" }, "id": "16" }, { @@ -19587,7 +19587,7 @@ ] ] }, - "properties": { "KODE_PROV": "36", "PROVINSI": "Banten" }, + "properties": { "KODE_PROV": "36", "PROVINSI": "BANTEN" }, "id": "36" }, { @@ -20073,7 +20073,7 @@ ] ] }, - "properties": { "KODE_PROV": "71", "PROVINSI": "Sulawesi Utara" }, + "properties": { "KODE_PROV": "71", "PROVINSI": "NORTH SULAWESI" }, "id": "71" }, { @@ -20901,7 +20901,7 @@ ] ] }, - "properties": { "KODE_PROV": "65", "PROVINSI": "Kalimantan Utara" }, + "properties": { "KODE_PROV": "65", "PROVINSI": "NORTH KALIMANTAN" }, "id": "65" }, { @@ -22194,7 +22194,7 @@ ] ] }, - "properties": { "KODE_PROV": "64", "PROVINSI": "Kalimantan Timur" }, + "properties": { "KODE_PROV": "64", "PROVINSI": "EAST KALIMANTAN" }, "id": "64" }, { @@ -22544,7 +22544,7 @@ ] ] }, - "properties": { "KODE_PROV": "33", "PROVINSI": "Jawa Tengah" }, + "properties": { "KODE_PROV": "33", "PROVINSI": "CENTRAL JAVA" }, "id": "33" }, { @@ -23769,7 +23769,7 @@ ] ] }, - "properties": { "KODE_PROV": "82", "PROVINSI": "Maluku Utara" }, + "properties": { "KODE_PROV": "82", "PROVINSI": "NORTH MALUKU" }, "id": "82" }, { @@ -24822,7 +24822,7 @@ ] ] }, - "properties": { "KODE_PROV": "61", "PROVINSI": "Kalimantan Barat" }, + "properties": { "KODE_PROV": "61", "PROVINSI": "WEST KALIMANTAN" }, "id": "61" }, { @@ -25065,7 +25065,7 @@ ] ] }, - "properties": { "KODE_PROV": "32", "PROVINSI": "Jawa Barat" }, + "properties": { "KODE_PROV": "32", "PROVINSI": "WEST JAVA" }, "id": "32" } ] diff --git a/services/article.ts b/services/article.ts index b73108f..ef7afc0 100644 --- a/services/article.ts +++ b/services/article.ts @@ -222,7 +222,7 @@ export async function getStatisticForMaps(startDate: string, endDate: string) { // Authorization: `Bearer ${token}`, }; return await httpGet( - `/activity-logs/visitors-by-reesgion-stats?startDate=${startDate}&endDate=${endDate}`, + `/activity-logs/visitors-by-region-stats?startDate=${startDate}&endDate=${endDate}`, headers ); }