From 4da55a5a8a9df040243112d2e5d5d1f975f20153 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Tue, 21 Oct 2025 16:52:17 +0800 Subject: [PATCH] Integrasi API: Voting admin Add: - app/(application)/admin/voting/[id]/[status]/reject-input.tsx - app/(application)/admin/voting/history.tsx - components/Box/ReportBox.tsx - screens/Admin/Voting/ - utils/colorBadge.ts Fix: - app/(application)/(user)/job/[id]/[status]/detail.tsx - app/(application)/(user)/voting/[id]/[status]/detail.tsx - app/(application)/admin/job/[id]/[status]/index.tsx - app/(application)/admin/job/[id]/[status]/reject-input.tsx - app/(application)/admin/voting/[id]/[status]/index.tsx - app/(application)/admin/voting/[id]/reject-input.tsx - app/(application)/admin/voting/[status]/status.tsx - components/Container/CircleContainer.tsx - components/Text/TextCustom.tsx - components/_ShareComponent/Admin/ButtonReview.tsx - screens/Admin/Job/funUpdateStatus.ts - screens/Admin/listPageAdmin.tsx - service/api-admin/api-admin-voting.ts ### No Issue --- .../(user)/job/[id]/[status]/detail.tsx | 9 +- .../(user)/voting/[id]/[status]/detail.tsx | 11 ++ .../admin/job/[id]/[status]/index.tsx | 4 +- .../admin/job/[id]/[status]/reject-input.tsx | 4 +- .../admin/voting/[id]/[status]/index.tsx | 152 ++++++++++++------ .../voting/[id]/[status]/reject-input.tsx | 113 +++++++++++++ .../admin/voting/[id]/reject-input.tsx | 54 ------- .../admin/voting/[status]/status.tsx | 70 ++++---- app/(application)/admin/voting/history.tsx | 104 ++++++++++++ components/Box/ReportBox.tsx | 16 ++ components/Container/CircleContainer.tsx | 34 ++-- components/Text/TextCustom.tsx | 6 +- .../_ShareComponent/Admin/ButtonReview.tsx | 3 + screens/Admin/Job/funUpdateStatus.ts | 4 +- screens/Admin/Voting/funUpdateStatus.ts | 26 +++ screens/Admin/listPageAdmin.tsx | 4 +- service/api-admin/api-admin-voting.ts | 28 +++- utils/colorBadge.ts | 14 ++ 18 files changed, 494 insertions(+), 162 deletions(-) create mode 100644 app/(application)/admin/voting/[id]/[status]/reject-input.tsx delete mode 100644 app/(application)/admin/voting/[id]/reject-input.tsx create mode 100644 app/(application)/admin/voting/history.tsx create mode 100644 components/Box/ReportBox.tsx create mode 100644 screens/Admin/Voting/funUpdateStatus.ts create mode 100644 utils/colorBadge.ts diff --git a/app/(application)/(user)/job/[id]/[status]/detail.tsx b/app/(application)/(user)/job/[id]/[status]/detail.tsx index 3b18b15..c6b9529 100644 --- a/app/(application)/(user)/job/[id]/[status]/detail.tsx +++ b/app/(application)/(user)/job/[id]/[status]/detail.tsx @@ -11,6 +11,7 @@ import { } from "@/components"; import { IconEdit } from "@/components/_Icon"; import { IMenuDrawerItem } from "@/components/_Interface/types"; +import ReportBox from "@/components/Box/ReportBox"; import Job_BoxDetailSection from "@/screens/Job/BoxDetailSection"; import Job_ButtonStatusSection from "@/screens/Job/ButtonStatusSection"; import { apiJobGetOne } from "@/service/api-client/api-job"; @@ -70,7 +71,13 @@ export default function JobDetailStatus() { ) : ( <> - + + {data && + data?.catatan && + (status === "draft" || status === "rejected") && ( + + )} + )} + + {data && + data?.catatan && + (status === "draft" || status === "rejected") && ( + + )} + {status === "publish" ? ( { try { - const response = await funUpdateStatus({ + const response = await funUpdateStatusJob({ id: id as string, changeStatus, }); diff --git a/app/(application)/admin/job/[id]/[status]/reject-input.tsx b/app/(application)/admin/job/[id]/[status]/reject-input.tsx index 27b5571..fbc8d56 100644 --- a/app/(application)/admin/job/[id]/[status]/reject-input.tsx +++ b/app/(application)/admin/job/[id]/[status]/reject-input.tsx @@ -7,7 +7,7 @@ import { } from "@/components"; import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle"; import AdminButtonReject from "@/components/_ShareComponent/Admin/ButtonReject"; -import funUpdateStatus from "@/screens/Admin/Job/funUpdateStatus"; +import funUpdateStatusJob from "@/screens/Admin/Job/funUpdateStatus"; import { apiAdminJobGetById } from "@/service/api-admin/api-admin-job"; import { router, useFocusEffect, useLocalSearchParams } from "expo-router"; import { useCallback, useState } from "react"; @@ -45,7 +45,7 @@ export default function AdminJobRejectInput() { }) => { try { setIsLoading(true); - const response = await funUpdateStatus({ + const response = await funUpdateStatusJob({ id: id as string, changeStatus, data: data, diff --git a/app/(application)/admin/voting/[id]/[status]/index.tsx b/app/(application)/admin/voting/[id]/[status]/index.tsx index 35274ba..2f4541e 100644 --- a/app/(application)/admin/voting/[id]/[status]/index.tsx +++ b/app/(application)/admin/voting/[id]/[status]/index.tsx @@ -14,8 +14,11 @@ import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButt import AdminButtonReject from "@/components/_ShareComponent/Admin/ButtonReject"; import AdminButtonReview from "@/components/_ShareComponent/Admin/ButtonReview"; import { GridDetail_4_8 } from "@/components/_ShareComponent/GridDetail_4_8"; +import ReportBox from "@/components/Box/ReportBox"; import { MainColor } from "@/constants/color-palet"; +import funUpdateStatusVoting from "@/screens/Admin/Voting/funUpdateStatus"; import { apiAdminVotingById } from "@/service/api-admin/api-admin-voting"; +import { colorBadge } from "@/utils/colorBadge"; import { dateTimeView } from "@/utils/dateTimeView"; import { Entypo } from "@expo/vector-icons"; import dayjs from "dayjs"; @@ -23,11 +26,14 @@ import { router, useFocusEffect, useLocalSearchParams } from "expo-router"; import _ from "lodash"; import { useCallback, useState } from "react"; import { List } from "react-native-paper"; +import Toast from "react-native-toast-message"; export default function AdminVotingDetail() { const { id, status } = useLocalSearchParams(); - const [data, setData] = useState(null); + const [isLoading, setIsLoading] = useState(false); + + console.log("[status]", status); useFocusEffect( useCallback(() => { @@ -41,8 +47,6 @@ export default function AdminVotingDetail() { id: id as string, }); - console.log("[DATA BY ID]", JSON.stringify(response, null, 2)); - if (response.success) { setData(response.data); } @@ -51,18 +55,6 @@ export default function AdminVotingDetail() { } }; - const colorBadge = () => { - if (status === "publish") { - return MainColor.green; - } else if (status === "review") { - return MainColor.orange; - } else if (status === "reject") { - return MainColor.red; - } else { - return MainColor.placeholder; - } - }; - const listData = [ { label: "Username", @@ -76,8 +68,8 @@ export default function AdminVotingDetail() { label: "Status", value: data && data?.Voting_Status?.name ? ( - - {_.startCase(data?.Voting_Status?.name)} + + {status === "history" ? "Riwayat" : _.startCase(status as string)} ) : ( "-" @@ -116,6 +108,59 @@ export default function AdminVotingDetail() { }, ]; + const handleUpdate = async ({ + changeStatus, + }: { + changeStatus: "publish" | "review" | "reject"; + }) => { + try { + const dateNow = new Date(); + // const dateNowHour = dateNow.getHours(); + // const awalVoteHour = dayjs(data?.awalVote).hour(); + + const isBefore = dayjs(dateNow).diff(dayjs(data?.awalVote), "hours") < 0; + console.log("[IS BEFORE]", isBefore); + + if (!isBefore) { + Toast.show({ + type: "error", + text1: "Tanggal & waktu telah lewat", + text2: "Silahkan report dan ubah tanggal & waktu voting", + }); + return; + } + + Toast.show({ + type: "success", + text1: "Berhasil mempublikasikan data", + }); + + setIsLoading(true); + const response = await funUpdateStatusVoting({ + id: id as string, + changeStatus, + }); + + if (!response.success) { + Toast.show({ + type: "error", + text1: "Gagal mempublikasikan data", + }); + } + + Toast.show({ + type: "success", + text1: "Berhasil mempublikasikan data", + }); + + router.back(); + } catch (error) { + console.log("[ERROR]", error); + } finally { + setIsLoading(false); + } + }; + return ( <> - {status === "publish" && ( - - - Hasil Voting - - - - {Array.from({ length: 4 }).map((_, index) => ( - - - - - Pilihan {index + 1} - - - - ))} - - - )} + {status === "publish" || + (status === "history" && ( + + + Hasil Voting + + + + {data?.Voting_DaftarNamaVote?.map( + (item: any, index: number) => ( + + + + + {item?.value} + + + + ) + )} + + + ))} + + {data && + data?.catatan && + (status === "review" || status === "reject") && ( + + )} {status === "review" && ( { AlertDefaultSystem({ title: "Publish", message: "Apakah anda yakin ingin mempublikasikan data ini?", textLeft: "Cancel", textRight: "Publish", - onPressLeft: () => { - router.back(); - }, onPressRight: () => { - router.back(); + handleUpdate({ changeStatus: "publish" }); }, }); }} onReject={() => { - router.push(`/admin/voting/${id}/reject-input`); + router.push(`/admin/voting/${id}/${status}/reject-input`); }} /> )} @@ -187,7 +239,7 @@ export default function AdminVotingDetail() { { - router.push(`/admin/voting/${id}/reject-input`); + router.push(`/admin/voting/${id}/${status}/reject-input`); }} /> )} diff --git a/app/(application)/admin/voting/[id]/[status]/reject-input.tsx b/app/(application)/admin/voting/[id]/[status]/reject-input.tsx new file mode 100644 index 0000000..2ce875f --- /dev/null +++ b/app/(application)/admin/voting/[id]/[status]/reject-input.tsx @@ -0,0 +1,113 @@ +/* eslint-disable react-hooks/exhaustive-deps */ +import { + AlertDefaultSystem, + BoxButtonOnFooter, + TextAreaCustom, + ViewWrapper, +} from "@/components"; +import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle"; +import AdminButtonReject from "@/components/_ShareComponent/Admin/ButtonReject"; +import funUpdateStatusVoting from "@/screens/Admin/Voting/funUpdateStatus"; +import { apiAdminVotingById } from "@/service/api-admin/api-admin-voting"; +import { router, useFocusEffect, useLocalSearchParams } from "expo-router"; +import { useCallback, useState } from "react"; +import Toast from "react-native-toast-message"; + +export default function AdminVotingRejectInput() { + const { id, status } = useLocalSearchParams(); + const [data, setData] = useState(""); + const [isLoading, setIsLoading] = useState(false); + + useFocusEffect( + useCallback(() => { + onLoadData(); + }, [id]) + ); + + const onLoadData = async () => { + try { + const response = await apiAdminVotingById({ + id: id as string, + }); + + if (response.success) { + setData(response.data.catatan); + } + } catch (error) { + console.log("[ERROR]", error); + } + }; + + const handleUpdate = async ({ + changeStatus, + }: { + changeStatus: "publish" | "review" | "reject"; + }) => { + try { + setIsLoading(true); + const response = await funUpdateStatusVoting({ + id: id as string, + changeStatus, + data: data, + }); + + if (!response.success) { + Toast.show({ + type: "error", + text1: "Report gagal", + }); + } + + Toast.show({ + type: "success", + text1: "Report berhasil", + }); + + if (status === "review") { + router.replace(`/admin/voting/reject/status`); + } else if (status === "reject") { + router.back(); + } + } catch (error) { + console.log("[ERROR]", error); + } finally { + setIsLoading(false); + } + }; + + const buttonSubmit = ( + + + AlertDefaultSystem({ + title: "Reject", + message: "Apakah anda yakin ingin menolak data ini?", + textLeft: "Batal", + textRight: "Ya", + onPressRight: () => handleUpdate({ changeStatus: "reject" }), + }) + } + /> + + ); + + return ( + <> + } + > + + + + ); +} diff --git a/app/(application)/admin/voting/[id]/reject-input.tsx b/app/(application)/admin/voting/[id]/reject-input.tsx deleted file mode 100644 index 81bda02..0000000 --- a/app/(application)/admin/voting/[id]/reject-input.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import { - AlertDefaultSystem, - BoxButtonOnFooter, - ButtonCustom, - TextAreaCustom, - ViewWrapper, -} from "@/components"; -import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle"; -import AdminButtonReject from "@/components/_ShareComponent/Admin/ButtonReject"; -import { router, useLocalSearchParams } from "expo-router"; -import { useState } from "react"; - -export default function AdminVotingRejectInput() { - const { id } = useLocalSearchParams(); - const [value, setValue] = useState(id as string); - const buttonSubmit = ( - - - AlertDefaultSystem({ - title: "Reject", - message: "Apakah anda yakin ingin menolak data ini?", - textLeft: "Batal", - textRight: "Ya", - onPressRight: () => { - console.log("value:", value); - router.replace(`/admin/voting/reject/status`); - }, - }) - } - /> - - ); - - return ( - <> - } - > - - - - ); -} diff --git a/app/(application)/admin/voting/[status]/status.tsx b/app/(application)/admin/voting/[status]/status.tsx index dd01ee8..cf3bc34 100644 --- a/app/(application)/admin/voting/[status]/status.tsx +++ b/app/(application)/admin/voting/[status]/status.tsx @@ -1,10 +1,8 @@ /* eslint-disable react-hooks/exhaustive-deps */ import { ActionIcon, - BaseBox, LoaderCustom, SearchInput, - Spacing, StackCustom, TextCustom, ViewWrapper, @@ -18,13 +16,11 @@ import { apiAdminVoting } from "@/service/api-admin/api-admin-voting"; import { Octicons } from "@expo/vector-icons"; import { router, useFocusEffect, useLocalSearchParams } from "expo-router"; import _ from "lodash"; -import { useState, useCallback } from "react"; +import { useCallback, useState } from "react"; import { Divider } from "react-native-paper"; export default function AdminVotingStatus() { const { status } = useLocalSearchParams(); - console.log("[STATUS]", status); - const [list, setList] = useState(null); const [loadList, setLoadList] = useState(false); const [search, setSearch] = useState(""); @@ -43,8 +39,6 @@ export default function AdminVotingStatus() { search, }); - // console.log("[LIST BY STATUS]", JSON.stringify(response, null, 2)); - if (response.success) { setList(response.data); } @@ -79,31 +73,43 @@ export default function AdminVotingStatus() { /> - {loadList ? : _.isEmpty(list) ? Belum ada data : list.map((item: any, i: number) => ( - - } - onPress={() => { - router.push(`/admin/voting/${item.id}/${status}`); - }} - /> - } - value2={{item?.Author?.username || "-"}} - value3={ - - {item?.title || "-"} - - } - /> - ))} + {loadList ? ( + + ) : _.isEmpty(list) ? ( + + Belum ada data + + ) : ( + list.map((item: any, i: number) => ( + + } + onPress={() => { + router.push(`/admin/voting/${item.id}/${status}`); + }} + /> + } + value2={ + + {item?.Author?.username || "-"} + + } + value3={ + + {item?.title || "-"} + + } + /> + )) + )} diff --git a/app/(application)/admin/voting/history.tsx b/app/(application)/admin/voting/history.tsx new file mode 100644 index 0000000..8a7286b --- /dev/null +++ b/app/(application)/admin/voting/history.tsx @@ -0,0 +1,104 @@ +/* eslint-disable react-hooks/exhaustive-deps */ +import { + ActionIcon, + LoaderCustom, + SearchInput, + StackCustom, + TextCustom, + ViewWrapper +} from "@/components"; +import AdminComp_BoxTitle from "@/components/_ShareComponent/Admin/BoxTitlePage"; +import AdminTitleTable from "@/components/_ShareComponent/Admin/TableTitle"; +import AdminTableValue from "@/components/_ShareComponent/Admin/TableValue"; +import AdminTitlePage from "@/components/_ShareComponent/Admin/TitlePage"; +import { ICON_SIZE_BUTTON } from "@/constants/constans-value"; +import { apiAdminVoting } from "@/service/api-admin/api-admin-voting"; +import { Octicons } from "@expo/vector-icons"; +import { router, useFocusEffect } from "expo-router"; +import _ from "lodash"; +import { useCallback, useState } from "react"; +import { Divider } from "react-native-paper"; + +export default function AdminVotingHistory() { + const [list, setList] = useState(null); + const [loadList, setLoadList] = useState(false); + const [search, setSearch] = useState(""); + + useFocusEffect( + useCallback(() => { + onLoadData(); + }, [ search]) + ); + + const onLoadData = async () => { + try { + setLoadList(true); + const response = await apiAdminVoting({ + category: "history", + search, + }); + + if (response.success) { + setList(response.data); + } + } catch (error) { + console.log("[ERROR]", error); + } finally { + setLoadList(false); + } + }; + + const rightComponent = ( + + ); + return ( + <> + }> + + + + + + + {loadList ? : _.isEmpty(list) ? Belum ada data : list.map((item: any, i: number) => ( + + } + onPress={() => { + router.push(`/admin/voting/${item.id}/history`); + }} + /> + } + value2={{item?.Author?.username || "-"}} + value3={ + + {item?.title || "-"} + + } + /> + ))} + + + + ); +} diff --git a/components/Box/ReportBox.tsx b/components/Box/ReportBox.tsx new file mode 100644 index 0000000..22e0905 --- /dev/null +++ b/components/Box/ReportBox.tsx @@ -0,0 +1,16 @@ +import StackCustom from "../Stack/StackCustom"; +import TextCustom from "../Text/TextCustom"; +import BaseBox from "./BaseBox"; + +export default function ReportBox({ text }: { text: string }) { + return ( + + + + Catatan penolakan + + {text} + + + ); +} diff --git a/components/Container/CircleContainer.tsx b/components/Container/CircleContainer.tsx index 39987f9..ca8a6d9 100644 --- a/components/Container/CircleContainer.tsx +++ b/components/Container/CircleContainer.tsx @@ -1,27 +1,39 @@ import { MainColor } from "@/constants/color-palet"; import React from "react"; -import { StyleProp, StyleSheet, TextInput, View, ViewStyle } from "react-native"; +import { + StyleProp, + StyleSheet, + View, + ViewStyle +} from "react-native"; +import TextCustom from "../Text/TextCustom"; interface CircularInputProps { - value?: string | number + value?: string | number; onChange?: (value: string | number) => void; icon?: React.ReactNode; - style?: StyleProp + style?: StyleProp; } -const CircularInput: React.FC = ({ value, onChange, icon, style }) => { +const CircularInput: React.FC = ({ + value, + onChange, + icon, + style, +}) => { return ( {icon ? ( icon ) : ( - + // keyboardType="numeric" + // maxLength={2} // Batasan maksimal karakter + > + {value} + )} ); @@ -39,7 +51,7 @@ const styles = StyleSheet.create({ }, input: { color: MainColor.yellow, // Warna kuning - fontSize: 24, + fontSize: 18, fontWeight: "bold", textAlign: "center", padding: 0, diff --git a/components/Text/TextCustom.tsx b/components/Text/TextCustom.tsx index 49fbf3d..2ab1366 100644 --- a/components/Text/TextCustom.tsx +++ b/components/Text/TextCustom.tsx @@ -23,7 +23,7 @@ interface TextCustomProps { bold?: boolean; semiBold?: boolean; size?: "default" | "large" | "small" | "xlarge" | number - color?: "default" | "yellow" | "red" | "gray" | "green" | "black" + color?: "default" | "yellow" | "red" | "gray" | "green" | "black" | "orange" align?: TextAlign; // Prop untuk alignment truncate?: boolean | number; onPress?: () => void; @@ -62,6 +62,7 @@ const TextCustom: React.FC = ({ else if (color === "gray") selectedStyles.push(styles.gray); else if (color === "green") selectedStyles.push(styles.green); else if (color === "black") selectedStyles.push(styles.black); + else if (color === "orange") selectedStyles.push(styles.orange); // Alignment if (align) { @@ -140,4 +141,7 @@ export const styles = StyleSheet.create({ black: { color: MainColor.black, }, + orange: { + color: MainColor.orange, + }, }); diff --git a/components/_ShareComponent/Admin/ButtonReview.tsx b/components/_ShareComponent/Admin/ButtonReview.tsx index ea1075d..6ae182c 100644 --- a/components/_ShareComponent/Admin/ButtonReview.tsx +++ b/components/_ShareComponent/Admin/ButtonReview.tsx @@ -4,9 +4,11 @@ import Grid from "@/components/Grid/GridCustom"; import { MainColor } from "@/constants/color-palet"; export default function AdminButtonReview({ + isLoading, onPublish, onReject, }: { + isLoading?: boolean; onPublish: () => void; onReject: () => void; }) { @@ -15,6 +17,7 @@ export default function AdminButtonReview({ } backgroundColor={MainColor.green} textColor="white" diff --git a/screens/Admin/Job/funUpdateStatus.ts b/screens/Admin/Job/funUpdateStatus.ts index 26db182..c875a2c 100644 --- a/screens/Admin/Job/funUpdateStatus.ts +++ b/screens/Admin/Job/funUpdateStatus.ts @@ -1,6 +1,6 @@ import { apiAdminJobUpdate } from "@/service/api-admin/api-admin-job"; -const funUpdateStatus = async ({ +const funUpdateStatusJob = async ({ id, changeStatus, data, @@ -23,4 +23,4 @@ const funUpdateStatus = async ({ } }; -export default funUpdateStatus; +export default funUpdateStatusJob; diff --git a/screens/Admin/Voting/funUpdateStatus.ts b/screens/Admin/Voting/funUpdateStatus.ts new file mode 100644 index 0000000..b35e455 --- /dev/null +++ b/screens/Admin/Voting/funUpdateStatus.ts @@ -0,0 +1,26 @@ +import { apiAdminVotingUpdateStatus } from "@/service/api-admin/api-admin-voting"; + +const funUpdateStatusVoting = async ({ + id, + changeStatus, + data, +}: { + id: string; + changeStatus: "publish" | "review" | "reject"; + data?: string; +}) => { + try { + const response = await apiAdminVotingUpdateStatus({ + id: id, + status: changeStatus as any, + data: data, + }); + + return response; + } catch (error) { + console.log("[ERROR]", error); + throw error; + } +}; + +export default funUpdateStatusVoting; diff --git a/screens/Admin/listPageAdmin.tsx b/screens/Admin/listPageAdmin.tsx index 92770dd..78cef71 100644 --- a/screens/Admin/listPageAdmin.tsx +++ b/screens/Admin/listPageAdmin.tsx @@ -49,7 +49,7 @@ const adminListMenu: NavbarItem[] = [ { label: "Publish", link: "/admin/voting/publish/status" }, { label: "Review", link: "/admin/voting/review/status" }, { label: "Reject", link: "/admin/voting/reject/status" }, - { label: "Riwayat", link: "/admin/voting/riwayat/status" }, + { label: "Riwayat", link: "/admin/voting/history" }, ], }, { @@ -142,7 +142,7 @@ const superAdminListMenu: NavbarItem[] = [ { label: "Publish", link: "/admin/voting/publish/status" }, { label: "Review", link: "/admin/voting/review/status" }, { label: "Reject", link: "/admin/voting/reject/status" }, - { label: "Riwayat", link: "/admin/voting/riwayat/status" }, + { label: "Riwayat", link: "/admin/voting/history" }, ], }, { diff --git a/service/api-admin/api-admin-voting.ts b/service/api-admin/api-admin-voting.ts index 758e102..9deef56 100644 --- a/service/api-admin/api-admin-voting.ts +++ b/service/api-admin/api-admin-voting.ts @@ -17,11 +17,7 @@ export async function apiAdminVoting({ } } -export async function apiAdminVotingById({ - id, -}: { - id: string; -}) { +export async function apiAdminVotingById({ id }: { id: string }) { try { const response = await apiConfig.get(`/mobile/admin/voting/${id}`); return response.data; @@ -29,3 +25,25 @@ export async function apiAdminVotingById({ throw error; } } + +export async function apiAdminVotingUpdateStatus({ + id, + data, + status, +}: { + id: string; + data?: string; + status: "publish" | "review" | "reject"; +}) { + try { + const response = await apiConfig.put( + `/mobile/admin/voting/${id}?status=${status}`, + { + data: data, + } + ); + return response.data; + } catch (error) { + throw error; + } +} diff --git a/utils/colorBadge.ts b/utils/colorBadge.ts new file mode 100644 index 0000000..315e045 --- /dev/null +++ b/utils/colorBadge.ts @@ -0,0 +1,14 @@ +import { MainColor } from "@/constants/color-palet"; + +export const colorBadge = ({ status }: { status: string }) => { + const statusLowerCase = status.toLowerCase(); + if (statusLowerCase === "publish") { + return MainColor.green; + } else if (statusLowerCase === "review") { + return MainColor.orange; + } else if (statusLowerCase === "reject") { + return MainColor.red; + } else { + return MainColor.placeholder; + } +};