From 333b1d2512ccbff9e478f920f3bad058b95731ca Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Fri, 19 Sep 2025 17:51:08 +0800 Subject: [PATCH] Voting Fix: Semua tampilan sudah terintegrasi API ### No Issue --- .../(user)/voting/(tabs)/contribution.tsx | 46 ++++++++- .../(user)/voting/(tabs)/history.tsx | 58 +++++++++-- .../(user)/voting/(tabs)/index.tsx | 17 ++-- .../(user)/voting/[id]/[status]/detail.tsx | 79 ++++++++++++--- .../(user)/voting/[id]/contribution.tsx | 96 +++++++++++++++--- app/(application)/(user)/voting/[id]/edit.tsx | 1 + .../(user)/voting/[id]/history.tsx | 97 ++++++++++++++++--- .../(user)/voting/[id]/index.tsx | 78 +++++++++------ .../voting/[id]/list-of-contributor.tsx | 69 ++++++++++--- screens/Voting/BoxDetailContribution.tsx | 19 +++- .../Voting/BoxDetailHasilVotingSection.tsx | 2 +- screens/Voting/BoxDetailHistorySection.tsx | 19 +++- screens/Voting/BoxDetailPublishSection.tsx | 35 +++++-- service/api-client/api-voting.ts | 24 +++-- utils/dateTimeView.ts | 1 + 15 files changed, 521 insertions(+), 120 deletions(-) diff --git a/app/(application)/(user)/voting/(tabs)/contribution.tsx b/app/(application)/(user)/voting/(tabs)/contribution.tsx index d25d423..bb555ad 100644 --- a/app/(application)/(user)/voting/(tabs)/contribution.tsx +++ b/app/(application)/(user)/voting/(tabs)/contribution.tsx @@ -1,15 +1,57 @@ +/* eslint-disable react-hooks/exhaustive-deps */ import { + LoaderCustom, + TextCustom, ViewWrapper } from "@/components"; +import { useAuth } from "@/hooks/use-auth"; import Voting_BoxPublishSection from "@/screens/Voting/BoxPublishSection"; +import { apiVotingGetAll } from "@/service/api-client/api-voting"; +import { useFocusEffect } from "expo-router"; +import _ from "lodash"; +import { useState, useCallback } from "react"; export default function VotingContribution() { + const { user } = useAuth(); + const [listData, setListData] = useState([]); + const [loadingGetData, setLoadingGetData] = useState(false); + + + useFocusEffect( + useCallback(() => { + onLoadData(); + }, []) + ); + + const onLoadData = async () => { + try { + setLoadingGetData(true); + const response = await apiVotingGetAll({ + category: "contribution", + authorId: user?.id as string, + }); + + if (response.success) { + setListData(response.data); + } + } catch (error) { + console.log("[ERROR]", error); + } finally { + setLoadingGetData(false); + } + }; + return ( - {Array.from({ length: 5 }).map((_, index) => ( + {loadingGetData ? ( + + ) : _.isEmpty(listData) ? ( + Tidak ada kontribusi + ) : listData.map((item: any, index: number) => ( ))} diff --git a/app/(application)/(user)/voting/(tabs)/history.tsx b/app/(application)/(user)/voting/(tabs)/history.tsx index 992282d..38f3354 100644 --- a/app/(application)/(user)/voting/(tabs)/history.tsx +++ b/app/(application)/(user)/voting/(tabs)/history.tsx @@ -1,11 +1,44 @@ -import { ViewWrapper } from "@/components"; +/* eslint-disable react-hooks/exhaustive-deps */ +import { LoaderCustom, TextCustom, ViewWrapper } from "@/components"; import TabsTwoButtonCustom from "@/components/_ShareComponent/TabsTwoHeaderCustom"; import Voting_BoxPublishSection from "@/screens/Voting/BoxPublishSection"; -import { useState } from "react"; +import { useAuth } from "@/hooks/use-auth"; +import { useCallback, useState } from "react"; +import { apiVotingGetAll } from "@/service/api-client/api-voting"; +import { useFocusEffect } from "expo-router"; +import _ from "lodash"; export default function VotingHistory() { + const { user } = useAuth(); const [activeCategory, setActiveCategory] = useState("all"); + const [listData, setListData] = useState([]); + const [loadingGetData, setLoadingGetData] = useState(false); + + useFocusEffect( + useCallback(() => { + onLoadData(); + }, [activeCategory]) + ); + + const onLoadData = async () => { + try { + setLoadingGetData(true); + const response = await apiVotingGetAll({ + category: activeCategory === "all" ? "all-history" : "my-history", + authorId: user?.id as string, + }); + + if (response.success) { + setListData(response.data); + } + } catch (error) { + console.log("[ERROR]", error); + } finally { + setLoadingGetData(false); + } + }; + const handlePress = (item: any) => { setActiveCategory(item); // tambahkan logika lain seperti filter dsb. @@ -25,13 +58,20 @@ export default function VotingHistory() { /> } > - {Array.from({ length: 10 }).map((_, index) => ( - - ))} + {loadingGetData ? ( + + ) : _.isEmpty(listData) ? ( + Tidak ada riwayat + ) : ( + listData.map((item: any, index: number) => ( + + )) + )} ); } diff --git a/app/(application)/(user)/voting/(tabs)/index.tsx b/app/(application)/(user)/voting/(tabs)/index.tsx index f5a1d62..f6beef4 100644 --- a/app/(application)/(user)/voting/(tabs)/index.tsx +++ b/app/(application)/(user)/voting/(tabs)/index.tsx @@ -8,23 +8,28 @@ import { } from "@/components"; import Voting_BoxPublishSection from "@/screens/Voting/BoxPublishSection"; import { apiVotingGetAll } from "@/service/api-client/api-voting"; -import { router } from "expo-router"; +import { router, useFocusEffect } from "expo-router"; import _ from "lodash"; -import { useEffect, useState } from "react"; +import { useCallback, useState } from "react"; export default function VotingBeranda() { const [listData, setListData] = useState([]); const [loadingGetData, setLoadingGetData] = useState(false); const [search, setSearch] = useState(""); - useEffect(() => { - onLoadData(); - }, [search]); + useFocusEffect( + useCallback(() => { + onLoadData(); + }, [search]) + ); const onLoadData = async () => { try { setLoadingGetData(true); - const response = await apiVotingGetAll({ search }); + const response = await apiVotingGetAll({ + search, + category: "beranda", + }); if (response.success) { setListData(response.data); } diff --git a/app/(application)/(user)/voting/[id]/[status]/detail.tsx b/app/(application)/(user)/voting/[id]/[status]/detail.tsx index 5f3e792..c20962e 100644 --- a/app/(application)/(user)/voting/[id]/[status]/detail.tsx +++ b/app/(application)/(user)/voting/[id]/[status]/detail.tsx @@ -2,17 +2,24 @@ import { AlertDefaultSystem, BackButton, + BaseBox, DotButton, DrawerCustom, + LoaderCustom, MenuDrawerDynamicGrid, Spacing, + TextCustom, ViewWrapper, } from "@/components"; import { IconArchive, IconContribution, IconEdit } from "@/components/_Icon"; import { IMenuDrawerItem } from "@/components/_Interface/types"; +import Voting_BoxDetailHasilVotingSection from "@/screens/Voting/BoxDetailHasilVotingSection"; import { Voting_BoxDetailSection } from "@/screens/Voting/BoxDetailSection"; import Voting_ButtonStatusSection from "@/screens/Voting/ButtonStatusSection"; -import { apiVotingGetOne } from "@/service/api-client/api-voting"; +import { + apiVotingGetOne, + apiVotingUpdateData, +} from "@/service/api-client/api-voting"; import { router, Stack, @@ -20,12 +27,14 @@ import { useLocalSearchParams, } from "expo-router"; import { useCallback, useState } from "react"; +import Toast from "react-native-toast-message"; export default function VotingDetailStatus() { const { id, status } = useLocalSearchParams(); const [openDrawerDraft, setOpenDrawerDraft] = useState(false); const [openDrawerPublish, setOpenDrawerPublish] = useState(false); const [isLoading, setIsLoading] = useState(false); + const [loadingGetData, setLoadingGetData] = useState(false); const [data, setData] = useState(null); @@ -37,12 +46,16 @@ export default function VotingDetailStatus() { const onLoadData = async () => { try { + setLoadingGetData(true); const response = await apiVotingGetOne({ id: id as string }); - if(response.success){ + + if (response.success) { setData(response.data); } } catch (error) { console.log("[ERROR]", error); + } finally { + setLoadingGetData(false); } }; @@ -59,9 +72,24 @@ export default function VotingDetailStatus() { message: "Apakah Anda yakin ingin mengarsipkan voting ini?", textLeft: "Batal", textRight: "Ya", - onPressRight: () => { - console.log("Arsip voting"); - router.back(); + onPressRight: async () => { + try { + const response = await apiVotingUpdateData({ + id: id as string, + data: data.isArsip ? false : true, + category: "archive", + }); + + if (response.success) { + Toast.show({ + type: "success", + text1: response.message, + }); + router.back(); + } + } catch (error) { + console.log("[ERROR]", error); + } }, }); } @@ -73,7 +101,7 @@ export default function VotingDetailStatus() { <> , headerRight: () => status === "draft" ? ( @@ -84,14 +112,37 @@ export default function VotingDetailStatus() { }} /> - - - + {loadingGetData ? ( + + ) : ( + <> + {status === "publish" && ( + + + Status:{" "} + + {data?.isArsip ? "Arsip" : "Publish"} + + + + )} + + + {status === "publish" ? ( + + ) : ( + + )} + + + )} {/* ========= Draft Drawer ========= */} diff --git a/app/(application)/(user)/voting/[id]/contribution.tsx b/app/(application)/(user)/voting/[id]/contribution.tsx index 34a05b1..5b4d063 100644 --- a/app/(application)/(user)/voting/[id]/contribution.tsx +++ b/app/(application)/(user)/voting/[id]/contribution.tsx @@ -1,22 +1,76 @@ +/* eslint-disable react-hooks/exhaustive-deps */ import { - AvatarUsernameAndOtherComponent, - BackButton, - DotButton, - DrawerCustom, - MenuDrawerDynamicGrid, - Spacing, - ViewWrapper, + AvatarUsernameAndOtherComponent, + BackButton, + DotButton, + DrawerCustom, + LoaderCustom, + MenuDrawerDynamicGrid, + Spacing, + ViewWrapper, } from "@/components"; import { IconContribution } from "@/components/_Icon"; import { IMenuDrawerItem } from "@/components/_Interface/types"; +import { useAuth } from "@/hooks/use-auth"; import { Voting_BoxDetailContributionSection } from "@/screens/Voting/BoxDetailContribution"; import Voting_BoxDetailHasilVotingSection from "@/screens/Voting/BoxDetailHasilVotingSection"; +import { + apiVotingContribution, + apiVotingGetOne, +} from "@/service/api-client/api-voting"; import { router, Stack, useLocalSearchParams } from "expo-router"; -import { useState } from "react"; +import { useEffect, useState } from "react"; export default function VotingDetailContribution() { + const { user } = useAuth(); const { id } = useLocalSearchParams(); const [openDrawerPublish, setOpenDrawerPublish] = useState(false); + const [data, setData] = useState(null); + const [loadingGetData, setLoadingGetData] = useState(false); + const [nameChoice, setNameChoice] = useState(""); + + useEffect(() => { + handlerLoadData(); + }, [id, user?.id]); + + async function handlerLoadData() { + try { + setLoadingGetData(true); + await onLoadData(); + await onLoadCheckContribution(); + } catch (error) { + console.log("[ERROR]", error); + } finally { + setLoadingGetData(false); + } + } + + const onLoadData = async () => { + try { + const response = await apiVotingGetOne({ id: id as string }); + if (response.success) { + setData(response.data); + } + } catch (error) { + console.log("[ERROR]", error); + } + }; + + const onLoadCheckContribution = async () => { + try { + const response = await apiVotingContribution({ + id: id as string, + authorId: user?.id as string, + category: "checked", + }); + + if (response.success) { + setNameChoice(response.data.nameChoice); + } + } catch (error) { + console.log("[ERROR]", error); + } + }; const handlePressPublish = (item: IMenuDrawerItem) => { router.navigate(item.path as any); @@ -36,11 +90,27 @@ export default function VotingDetailContribution() { /> - } - /> - - + {loadingGetData ? ( + + ) : ( + <> + + } + /> + + + + )} {/* ========= Publish Drawer ========= */} diff --git a/app/(application)/(user)/voting/[id]/edit.tsx b/app/(application)/(user)/voting/[id]/edit.tsx index ba2823d..a224656 100644 --- a/app/(application)/(user)/voting/[id]/edit.tsx +++ b/app/(application)/(user)/voting/[id]/edit.tsx @@ -150,6 +150,7 @@ export default function VotingEdit() { const response = await apiVotingUpdateData({ id: id as string, data: newData, + category: "edit", }); if (response.success) { diff --git a/app/(application)/(user)/voting/[id]/history.tsx b/app/(application)/(user)/voting/[id]/history.tsx index 678bc7c..b0c6892 100644 --- a/app/(application)/(user)/voting/[id]/history.tsx +++ b/app/(application)/(user)/voting/[id]/history.tsx @@ -1,23 +1,78 @@ +/* eslint-disable react-hooks/exhaustive-deps */ import { - AvatarUsernameAndOtherComponent, - BackButton, - DotButton, - DrawerCustom, - MenuDrawerDynamicGrid, - Spacing, - ViewWrapper, + AvatarUsernameAndOtherComponent, + BackButton, + DotButton, + DrawerCustom, + LoaderCustom, + MenuDrawerDynamicGrid, + Spacing, + ViewWrapper, } from "@/components"; import { IconContribution } from "@/components/_Icon"; import { IMenuDrawerItem } from "@/components/_Interface/types"; +import { useAuth } from "@/hooks/use-auth"; import Voting_BoxDetailHasilVotingSection from "@/screens/Voting/BoxDetailHasilVotingSection"; import { Voting_BoxDetailHistorySection } from "@/screens/Voting/BoxDetailHistorySection"; +import { + apiVotingContribution, + apiVotingGetOne, +} from "@/service/api-client/api-voting"; import { router, Stack, useLocalSearchParams } from "expo-router"; -import { useState } from "react"; +import { useEffect, useState } from "react"; export default function VotingDetailHistory() { const { id } = useLocalSearchParams(); + const { user } = useAuth(); const [openDrawerPublish, setOpenDrawerPublish] = useState(false); + const [data, setData] = useState(null); + const [loadingGetData, setLoadingGetData] = useState(false); + const [nameChoice, setNameChoice] = useState(""); + + useEffect(() => { + handlerLoadData(); + }, [id, user?.id]); + + async function handlerLoadData() { + try { + setLoadingGetData(true); + await onLoadData(); + await onLoadCheckContribution(); + } catch (error) { + console.log("[ERROR]", error); + } finally { + setLoadingGetData(false); + } + } + + const onLoadData = async () => { + try { + const response = await apiVotingGetOne({ id: id as string }); + if (response.success) { + setData(response.data); + } + } catch (error) { + console.log("[ERROR]", error); + } + }; + + const onLoadCheckContribution = async () => { + try { + const response = await apiVotingContribution({ + id: id as string, + authorId: user?.id as string, + category: "checked", + }); + + if (response.success) { + setNameChoice(response.data.nameChoice); + } + } catch (error) { + console.log("[ERROR]", error); + } + }; + const handlePressPublish = (item: IMenuDrawerItem) => { router.navigate(item.path as any); setOpenDrawerPublish(false); @@ -35,11 +90,27 @@ export default function VotingDetailHistory() { }} /> - } - /> - - + {loadingGetData ? ( + + ) : ( + <> + + } + /> + + + + )} {/* ========= Publish Drawer ========= */} diff --git a/app/(application)/(user)/voting/[id]/index.tsx b/app/(application)/(user)/voting/[id]/index.tsx index 5b76ac4..e30e040 100644 --- a/app/(application)/(user)/voting/[id]/index.tsx +++ b/app/(application)/(user)/voting/[id]/index.tsx @@ -9,17 +9,19 @@ import { LoaderCustom, MenuDrawerDynamicGrid, StackCustom, - TextCustom, ViewWrapper, } from "@/components"; import { IconArchive, IconContribution } from "@/components/_Icon"; import { IMenuDrawerItem } from "@/components/_Interface/types"; +import { useAuth } from "@/hooks/use-auth"; import Voting_BoxDetailHasilVotingSection from "@/screens/Voting/BoxDetailHasilVotingSection"; import { Voting_BoxDetailPublishSection } from "@/screens/Voting/BoxDetailPublishSection"; import { - apiVotingCheckContribution, + apiVotingContribution, apiVotingGetOne, + apiVotingUpdateData, } from "@/service/api-client/api-voting"; +import { today } from "@/utils/dateTimeView"; import { router, Stack, @@ -27,14 +29,11 @@ import { useLocalSearchParams, } from "expo-router"; import React, { useCallback, useState } from "react"; -import { useAuth } from "@/hooks/use-auth"; +import Toast from "react-native-toast-message"; export default function VotingDetail() { const { id } = useLocalSearchParams(); const { user } = useAuth(); - console.log("[ID]", id); - const dateNow = new Date(); - console.log("[DATE NOW]", dateNow); const [openDrawerPublish, setOpenDrawerPublish] = useState(false); const [data, setData] = useState(null); @@ -42,8 +41,6 @@ export default function VotingDetail() { const [isContribution, setIsContribution] = useState(false); const [nameChoice, setNameChoice] = useState(""); - console.log("[DATA AWAL]", data?.awalVote); - useFocusEffect( useCallback(() => { handlerLoadData(); @@ -65,7 +62,6 @@ export default function VotingDetail() { const onLoadData = async () => { try { const response = await apiVotingGetOne({ id: id as string }); - // console.log("[DATA]", JSON.stringify(response.data, null, 2)); if (response.success) { setData(response.data); } @@ -76,11 +72,12 @@ export default function VotingDetail() { const onLoadCheckContribution = async () => { try { - const response = await apiVotingCheckContribution({ + const response = await apiVotingContribution({ id: id as string, authorId: user?.id as string, + category: "checked", }); - console.log("[DATA CONTRIBUION]", response.data); + if (response.success) { setIsContribution(response.data.isContribution); setNameChoice(response.data.nameChoice); @@ -97,9 +94,24 @@ export default function VotingDetail() { message: "Apakah Anda yakin ingin mengarsipkan voting ini?", textLeft: "Batal", textRight: "Ya", - onPressRight: () => { - console.log("Hapus"); - router.back(); + onPressRight: async () => { + try { + const response = await apiVotingUpdateData({ + id: id as string, + data: data.isArsip ? false : true, + category: "archive", + }); + + if (response.success) { + Toast.show({ + type: "success", + text1: response.message, + }); + router.back(); + } + } catch (error) { + console.log("[ERROR]", error); + } }, }); } @@ -124,8 +136,8 @@ export default function VotingDetail() { ) : ( - {dateNow < new Date(data?.awalVote) && ( - + {today.getDate() < new Date(data?.awalVote).getDate() && ( + )} , - label: "Daftar Kontributor", - path: `/voting/${id}/list-of-contributor`, - }, - { - icon: , - label: "Update Arsip", - path: "" as any, - }, - ]} + data={ + user?.id === data?.Author?.id + ? [ + { + icon: , + label: "Daftar Kontributor", + path: `/voting/${id}/list-of-contributor`, + }, + { + icon: , + label: "Update Arsip", + path: "" as any, + }, + ] + : [ + { + icon: , + label: "Daftar Kontributor", + path: `/voting/${id}/list-of-contributor`, + }, + ] + } onPressItem={handlePressPublish as any} /> diff --git a/app/(application)/(user)/voting/[id]/list-of-contributor.tsx b/app/(application)/(user)/voting/[id]/list-of-contributor.tsx index eab08a5..b7bb593 100644 --- a/app/(application)/(user)/voting/[id]/list-of-contributor.tsx +++ b/app/(application)/(user)/voting/[id]/list-of-contributor.tsx @@ -1,26 +1,69 @@ +/* eslint-disable react-hooks/exhaustive-deps */ import { AvatarUsernameAndOtherComponent, BadgeCustom, BaseBox, + LoaderCustom, + TextCustom, ViewWrapper, } from "@/components"; +import { apiVotingContribution } from "@/service/api-client/api-voting"; +import { useFocusEffect, useLocalSearchParams } from "expo-router"; +import _ from "lodash"; +import { useCallback, useState } from "react"; export default function Voting_ListOfContributor() { + const { id } = useLocalSearchParams(); + const [listData, setListData] = useState([]); + const [isLoadData, setIsLoadData] = useState(false); + + useFocusEffect( + useCallback(() => { + onLoadList(); + }, [id]) + ); + + const onLoadList = async () => { + try { + setIsLoadData(true); + const response = await apiVotingContribution({ + id: id as string, + authorId: "", + category: "list", + }); + + if (response.success) { + setListData(response.data); + } + } catch (error) { + console.log("[ERROR]", error); + } finally { + setIsLoadData(false); + } + }; + return ( - {Array.from({ length: 10 }).map((_, index) => ( - - - Pilihan {index + 1} - - } - /> - - ))} + {isLoadData ? ( + + ) : _.isEmpty(listData) ? ( + Tidak ada kontributor + ) : ( + listData.map((item: any, index: number) => ( + + + {item?.Voting_DaftarNamaVote?.value} + + } + /> + + )) + )} ); } diff --git a/screens/Voting/BoxDetailContribution.tsx b/screens/Voting/BoxDetailContribution.tsx index a6d4bfa..fd21c23 100644 --- a/screens/Voting/BoxDetailContribution.tsx +++ b/screens/Voting/BoxDetailContribution.tsx @@ -9,23 +9,32 @@ import { GStyles } from "@/styles/global-styles"; import { Voting_ComponentDetailDataSection } from "./ComponentDetailDataSection"; export function Voting_BoxDetailContributionSection({ + data, headerAvatar, + nameChoice, }: { + data: any; headerAvatar?: React.ReactNode; + nameChoice?: string; }) { return ( <> - {headerAvatar ? headerAvatar : } + {headerAvatar && ( + <> + {headerAvatar} + + + )} - + - + Pilihan Anda - - Pilihan 1 + + {nameChoice || "-"} diff --git a/screens/Voting/BoxDetailHasilVotingSection.tsx b/screens/Voting/BoxDetailHasilVotingSection.tsx index 9802d26..790e052 100644 --- a/screens/Voting/BoxDetailHasilVotingSection.tsx +++ b/screens/Voting/BoxDetailHasilVotingSection.tsx @@ -9,7 +9,7 @@ import { export default function Voting_BoxDetailHasilVotingSection({ listData, }: { - listData?: any[]; + listData: any[]; }) { return ( <> diff --git a/screens/Voting/BoxDetailHistorySection.tsx b/screens/Voting/BoxDetailHistorySection.tsx index 87fab2a..fce0fc6 100644 --- a/screens/Voting/BoxDetailHistorySection.tsx +++ b/screens/Voting/BoxDetailHistorySection.tsx @@ -1,21 +1,36 @@ import { + BadgeCustom, BoxWithHeaderSection, Spacing, - StackCustom + StackCustom, + TextCustom } from "@/components"; import { Voting_ComponentDetailDataSection } from "./ComponentDetailDataSection"; +import { GStyles } from "@/styles/global-styles"; export function Voting_BoxDetailHistorySection({ headerAvatar, + data, + nameChoice, }: { headerAvatar?: React.ReactNode; + data: any; + nameChoice: string; }) { return ( <> {headerAvatar ? headerAvatar : } - + + + + Pilihan Anda + + + {nameChoice || "-"} + + diff --git a/screens/Voting/BoxDetailPublishSection.tsx b/screens/Voting/BoxDetailPublishSection.tsx index 99ed3ff..6b88c73 100644 --- a/screens/Voting/BoxDetailPublishSection.tsx +++ b/screens/Voting/BoxDetailPublishSection.tsx @@ -1,18 +1,19 @@ import { + AlertDefaultSystem, BadgeCustom, BoxWithHeaderSection, ButtonCustom, - CenterCustom, Spacing, StackCustom, - TextCustom, + TextCustom } from "@/components"; import { RadioCustom, RadioGroup } from "@/components/Radio/RadioCustom"; +import { apiVotingVote } from "@/service/api-client/api-voting"; +import { today } from "@/utils/dateTimeView"; +import { router } from "expo-router"; import { useState } from "react"; import { View } from "react-native"; import { Voting_ComponentDetailDataSection } from "./ComponentDetailDataSection"; -import { apiVotingVote } from "@/service/api-client/api-voting"; -import { useAuth } from "@/hooks/use-auth"; export function Voting_BoxDetailPublishSection({ headerAvatar, @@ -40,7 +41,10 @@ export function Voting_BoxDetailPublishSection({ id: data?.id, data: newData, }); - console.log("[RES VOTE]", response); + + if (response.success) { + router.push(`/voting/${data?.id}/list-of-contributor`); + } } catch (error) { console.log("[ERROR]", error); } @@ -79,13 +83,30 @@ export function Voting_BoxDetailPublishSection({ {data?.Voting_DaftarNamaVote?.map((item: any, i: number) => ( - + ))} - + { + AlertDefaultSystem({ + title: "Anda melaukan voting", + message: "Yakin dengan pilihan anda ini ?", + textLeft: "Batal", + textRight: "Ya", + onPressRight: () => handlerSubmitVote(), + }); + }} + > Vote diff --git a/service/api-client/api-voting.ts b/service/api-client/api-voting.ts index 62f00eb..3f7b0d2 100644 --- a/service/api-client/api-voting.ts +++ b/service/api-client/api-voting.ts @@ -62,12 +62,15 @@ export async function apiVotingDelete({ id }: { id: string }) { export async function apiVotingUpdateData({ id, data, + category, }: { id: string; data: any; + category: "edit" | "archive"; }) { + const categoryQuery = `?category=${category}`; try { - const response = await apiConfig.put(`/mobile/voting/${id}`, { + const response = await apiConfig.put(`/mobile/voting/${id}${categoryQuery}`, { data: data, }); return response.data; @@ -76,10 +79,12 @@ export async function apiVotingUpdateData({ } } -export async function apiVotingGetAll({ search }: { search: string }) { +export async function apiVotingGetAll({ search, category, authorId }: { search?: string, category: "beranda" | "contribution" | "all-history" | "my-history", authorId?: string }) { try { - const searchQuery = search ? `?search=${search}` : ""; - const response = await apiConfig.get(`/mobile/voting${searchQuery}`); + const categoryQuery = category ? `?category=${category}` : ""; + const searchQuery = search ? `&search=${search}` : ""; + const authorIdQuery = authorId ? `&authorId=${authorId}` : ""; + const response = await apiConfig.get(`/mobile/voting${categoryQuery}${searchQuery}${authorIdQuery}`); return response.data; } catch (error) { throw error; @@ -97,18 +102,23 @@ export async function apiVotingVote({ id, data }: { id: string; data: any }) { } } -export async function apiVotingCheckContribution({ +export async function apiVotingContribution({ id, authorId, + category, }: { id: string; authorId: string; + category: "list" | "checked"; }) { + const query = + category === "list" + ? "?category=list" + : `?category=checked&authorId=${authorId}`; try { const response = await apiConfig.get( - `/mobile/voting/${id}/contribution?authorId=${authorId}` + `/mobile/voting/${id}/contribution${query}` ); - console.log("[DATA CONTRIBUION]", response.data); return response.data; } catch (error) { throw error; diff --git a/utils/dateTimeView.ts b/utils/dateTimeView.ts index bbed84a..b0de7b8 100644 --- a/utils/dateTimeView.ts +++ b/utils/dateTimeView.ts @@ -1,5 +1,6 @@ import dayjs from "dayjs"; +export const today = new Date(); export const dateTimeView = ({ date, withoutTime = false,