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