fix voting admin:

deskripsi:
- fix voting table review
This commit is contained in:
2025-02-24 16:55:34 +08:00
parent 8f80419eb2
commit f2d3930bd1
6 changed files with 771 additions and 724 deletions

View File

@@ -1,64 +1,87 @@
export {
apiGetAdminVoteStatusCountDashboard,
apiGetAdminVoteRiwayatCount,
apiGetAdminVotingByStatus
}
const apiGetAdminVoteStatusCountDashboard = async ({ name }: {
name: "Publish" | "Review" | "Reject";
apiGetAdminVoteStatusCountDashboard,
apiGetAdminVoteRiwayatCount,
apiGetAdminVotingByStatus,
};
const apiGetAdminVoteStatusCountDashboard = async ({
name,
}: {
name: "Publish" | "Review" | "Reject";
}) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/admin/vote/dashboard/${name}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
const response = await fetch(`/api/admin/vote/dashboard/${name}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
});
return await response.json().catch(() => null);
}
const apiGetAdminVoteRiwayatCount = async () => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/admin/vote/dashboard/riwayat`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
});
return await response.json().catch(() => null);
}
const response = await fetch(`/api/admin/vote/dashboard/riwayat`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
const apiGetAdminVotingByStatus = async ({
name,
page,
search }: {
name: "Publish" | "Review" | "Reject";
page: string;
search: string;
}) => {
const apiGetAdminVotingByStatus = async ({
name,
page,
search,
}: {
name: "Publish" | "Review" | "Reject";
page: string;
search: string;
}) => {
try {
// Fetch token from cookie
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
if (!token) {
console.error("No token found");
return null;
}
const isPage = page ? `?page=${page}` : "";
const isSearch = search ? `&search=${search}` : "";
const response = await fetch(
`/api/admin/vote/status/${name}${isPage}${isSearch}`,
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`
}
}
)
return await response.json().catch(() => null);
}
`/api/admin/vote/status/${name}${isPage}${isSearch}`,
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
}
);
// Check if the response is OK
if (!response.ok) {
const errorData = await response.json().catch(() => null);
console.error(
"Error get data voting admin",
errorData?.message || "Unknown error"
);
return null;
}
return response.json();
} catch (error) {
console.log("Error get data voting admin", error);
throw error;
}
};