fix : list pengaduan error

This commit is contained in:
2025-11-17 17:25:14 +08:00
parent 282b9678b3
commit 3e09c934d4

View File

@@ -24,7 +24,7 @@ import {
import { useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import useSwr from "swr";
import { proxy } from "valtio";
import { proxy, subscribe } from "valtio";
const state = proxy({ reload: "" });
function reloadState() {
@@ -124,21 +124,28 @@ function ListPengaduan({ status }: { status: StatusKey }) {
const navigate = useNavigate();
const [page, setPage] = useState(1);
const [value, setValue] = useState("");
const { data, mutate, isLoading } = useSwr("/", () =>
apiFetch.api.pengaduan.list.get({
const { data, mutate, isLoading } = useSwr("/", async () => {
const res = await apiFetch.api.pengaduan.list.get({
query: {
status,
search: value,
take: "",
page: "",
},
}),
);
});
return Array.isArray(res?.data) ? res.data : []; // ⬅ paksa return array
});
useShallowEffect(() => {
mutate();
}, [status, value]);
useShallowEffect(() => {
const unsubscribe = subscribe(state, () => mutate());
return () => unsubscribe();
}, []);
if (isLoading)
return (
<Card
@@ -156,7 +163,7 @@ function ListPengaduan({ status }: { status: StatusKey }) {
</Card>
);
const list = data?.data || [];
const list = data || [];
return (
<Stack gap="xl">
@@ -190,7 +197,7 @@ function ListPengaduan({ status }: { status: StatusKey }) {
</Stack>
</Flex>
) : (
list?.map((v: any) => (
Array.isArray(list) && list?.map((v: any) => (
<Card
key={v.id}
radius="lg"