Voting
Fix: Semua tampilan sudah terintegrasi API ### No Issue
This commit is contained in:
@@ -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<any>([]);
|
||||
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 (
|
||||
<ViewWrapper hideFooter>
|
||||
{Array.from({ length: 5 }).map((_, index) => (
|
||||
{loadingGetData ? (
|
||||
<LoaderCustom />
|
||||
) : _.isEmpty(listData) ? (
|
||||
<TextCustom align="center">Tidak ada kontribusi</TextCustom>
|
||||
) : listData.map((item: any, index: number) => (
|
||||
<Voting_BoxPublishSection
|
||||
data={item}
|
||||
key={index}
|
||||
href={`/voting/${index}/contribution`}
|
||||
href={`/voting/${item.id}/contribution`}
|
||||
/>
|
||||
))}
|
||||
</ViewWrapper>
|
||||
|
||||
@@ -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<string | null>("all");
|
||||
|
||||
const [listData, setListData] = useState<any>([]);
|
||||
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) => (
|
||||
<Voting_BoxPublishSection
|
||||
key={index}
|
||||
id={activeCategory as any}
|
||||
href={`/voting/${index}/history`}
|
||||
/>
|
||||
))}
|
||||
{loadingGetData ? (
|
||||
<LoaderCustom />
|
||||
) : _.isEmpty(listData) ? (
|
||||
<TextCustom align="center">Tidak ada riwayat</TextCustom>
|
||||
) : (
|
||||
listData.map((item: any, index: number) => (
|
||||
<Voting_BoxPublishSection
|
||||
key={index}
|
||||
id={item.id}
|
||||
data={item}
|
||||
href={`/voting/${item.id}/history`}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
</ViewWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<any>([]);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<any>(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() {
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: `Detail ${status}`,
|
||||
title: `Detail`,
|
||||
headerLeft: () => <BackButton />,
|
||||
headerRight: () =>
|
||||
status === "draft" ? (
|
||||
@@ -84,14 +112,37 @@ export default function VotingDetailStatus() {
|
||||
}}
|
||||
/>
|
||||
<ViewWrapper>
|
||||
<Voting_BoxDetailSection data={data as any} />
|
||||
<Voting_ButtonStatusSection
|
||||
isLoading={isLoading}
|
||||
onSetLoading={setIsLoading}
|
||||
id={id as string}
|
||||
status={status as string}
|
||||
/>
|
||||
<Spacing />
|
||||
{loadingGetData ? (
|
||||
<LoaderCustom />
|
||||
) : (
|
||||
<>
|
||||
{status === "publish" && (
|
||||
<BaseBox>
|
||||
<TextCustom bold>
|
||||
Status:{" "}
|
||||
<TextCustom color={data?.isArsip ? "red" : "green"}>
|
||||
{data?.isArsip ? "Arsip" : "Publish"}
|
||||
</TextCustom>
|
||||
</TextCustom>
|
||||
</BaseBox>
|
||||
)}
|
||||
<Spacing height={0} />
|
||||
<Voting_BoxDetailSection data={data as any} />
|
||||
{status === "publish" ? (
|
||||
<Voting_BoxDetailHasilVotingSection
|
||||
listData={data?.Voting_DaftarNamaVote}
|
||||
/>
|
||||
) : (
|
||||
<Voting_ButtonStatusSection
|
||||
isLoading={isLoading}
|
||||
onSetLoading={setIsLoading}
|
||||
id={id as string}
|
||||
status={status as string}
|
||||
/>
|
||||
)}
|
||||
<Spacing />
|
||||
</>
|
||||
)}
|
||||
</ViewWrapper>
|
||||
|
||||
{/* ========= Draft Drawer ========= */}
|
||||
|
||||
@@ -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<any>(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() {
|
||||
/>
|
||||
|
||||
<ViewWrapper>
|
||||
<Voting_BoxDetailContributionSection
|
||||
headerAvatar={<AvatarUsernameAndOtherComponent />}
|
||||
/>
|
||||
<Voting_BoxDetailHasilVotingSection />
|
||||
<Spacing />
|
||||
{loadingGetData ? (
|
||||
<LoaderCustom />
|
||||
) : (
|
||||
<>
|
||||
<Voting_BoxDetailContributionSection
|
||||
data={data}
|
||||
nameChoice={nameChoice}
|
||||
headerAvatar={
|
||||
<AvatarUsernameAndOtherComponent
|
||||
avatar={data?.Author?.Profile?.imageId || ""}
|
||||
name={data?.Author?.username || "Username"}
|
||||
avatarHref={`/profile/${data?.Author?.Profile?.id}`}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Voting_BoxDetailHasilVotingSection
|
||||
listData={data?.Voting_DaftarNamaVote}
|
||||
/>
|
||||
<Spacing />
|
||||
</>
|
||||
)}
|
||||
</ViewWrapper>
|
||||
|
||||
{/* ========= Publish Drawer ========= */}
|
||||
|
||||
@@ -150,6 +150,7 @@ export default function VotingEdit() {
|
||||
const response = await apiVotingUpdateData({
|
||||
id: id as string,
|
||||
data: newData,
|
||||
category: "edit",
|
||||
});
|
||||
|
||||
if (response.success) {
|
||||
|
||||
@@ -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<any>(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() {
|
||||
}}
|
||||
/>
|
||||
<ViewWrapper>
|
||||
<Voting_BoxDetailHistorySection
|
||||
headerAvatar={<AvatarUsernameAndOtherComponent />}
|
||||
/>
|
||||
<Voting_BoxDetailHasilVotingSection />
|
||||
<Spacing />
|
||||
{loadingGetData ? (
|
||||
<LoaderCustom />
|
||||
) : (
|
||||
<>
|
||||
<Voting_BoxDetailHistorySection
|
||||
data={data}
|
||||
nameChoice={nameChoice}
|
||||
headerAvatar={
|
||||
<AvatarUsernameAndOtherComponent
|
||||
avatar={data?.Author?.Profile?.imageId || ""}
|
||||
name={data?.Author?.username || "Username"}
|
||||
avatarHref={`/profile/${data?.Author?.Profile?.id}`}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Voting_BoxDetailHasilVotingSection
|
||||
listData={data?.Voting_DaftarNamaVote}
|
||||
/>
|
||||
<Spacing />
|
||||
</>
|
||||
)}
|
||||
</ViewWrapper>
|
||||
|
||||
{/* ========= Publish Drawer ========= */}
|
||||
|
||||
@@ -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<any>(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() {
|
||||
<LoaderCustom />
|
||||
) : (
|
||||
<StackCustom gap={"xs"}>
|
||||
{dateNow < new Date(data?.awalVote) && (
|
||||
<InformationBox text="Untuk sementara voting ini belum di buka. Voting akan dimulai sesuai dengan tanggal awal pemilihan, dan akan ditutup sesuai dengan tanggal akhir pemilihan." />
|
||||
{today.getDate() < new Date(data?.awalVote).getDate() && (
|
||||
<InformationBox text="Untuk sementara voting tidak dapat dilakukan. Voting dapat dimulai sesuai dengan tanggal awal pemilihan, dan akan ditutup sesuai dengan tanggal akhir pemilihan." />
|
||||
)}
|
||||
<Voting_BoxDetailPublishSection
|
||||
data={data}
|
||||
@@ -155,18 +167,28 @@ export default function VotingDetail() {
|
||||
height={"auto"}
|
||||
>
|
||||
<MenuDrawerDynamicGrid
|
||||
data={[
|
||||
{
|
||||
icon: <IconContribution />,
|
||||
label: "Daftar Kontributor",
|
||||
path: `/voting/${id}/list-of-contributor`,
|
||||
},
|
||||
{
|
||||
icon: <IconArchive />,
|
||||
label: "Update Arsip",
|
||||
path: "" as any,
|
||||
},
|
||||
]}
|
||||
data={
|
||||
user?.id === data?.Author?.id
|
||||
? [
|
||||
{
|
||||
icon: <IconContribution />,
|
||||
label: "Daftar Kontributor",
|
||||
path: `/voting/${id}/list-of-contributor`,
|
||||
},
|
||||
{
|
||||
icon: <IconArchive />,
|
||||
label: "Update Arsip",
|
||||
path: "" as any,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
icon: <IconContribution />,
|
||||
label: "Daftar Kontributor",
|
||||
path: `/voting/${id}/list-of-contributor`,
|
||||
},
|
||||
]
|
||||
}
|
||||
onPressItem={handlePressPublish as any}
|
||||
/>
|
||||
</DrawerCustom>
|
||||
|
||||
@@ -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<any>([]);
|
||||
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 (
|
||||
<ViewWrapper>
|
||||
{Array.from({ length: 10 }).map((_, index) => (
|
||||
<BaseBox paddingTop={5} paddingBottom={5} key={index.toString()}>
|
||||
<AvatarUsernameAndOtherComponent
|
||||
rightComponent={
|
||||
<BadgeCustom
|
||||
style={{alignSelf: "flex-end" }}
|
||||
>
|
||||
Pilihan {index + 1}
|
||||
</BadgeCustom>
|
||||
}
|
||||
/>
|
||||
</BaseBox>
|
||||
))}
|
||||
{isLoadData ? (
|
||||
<LoaderCustom />
|
||||
) : _.isEmpty(listData) ? (
|
||||
<TextCustom align="center">Tidak ada kontributor</TextCustom>
|
||||
) : (
|
||||
listData.map((item: any, index: number) => (
|
||||
<BaseBox paddingTop={5} paddingBottom={5} key={index.toString()}>
|
||||
<AvatarUsernameAndOtherComponent
|
||||
avatar={item?.Author?.Profile?.imageId || ""}
|
||||
name={item?.Author?.username || "Username"}
|
||||
avatarHref={`/profile/${item?.Author?.Profile?.id}`}
|
||||
rightComponent={
|
||||
<BadgeCustom style={{ alignSelf: "flex-end" }}>
|
||||
{item?.Voting_DaftarNamaVote?.value}
|
||||
</BadgeCustom>
|
||||
}
|
||||
/>
|
||||
</BaseBox>
|
||||
))
|
||||
)}
|
||||
</ViewWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<>
|
||||
<BoxWithHeaderSection>
|
||||
{headerAvatar ? headerAvatar : <Spacing />}
|
||||
{headerAvatar && (
|
||||
<>
|
||||
{headerAvatar}
|
||||
<Spacing />
|
||||
</>
|
||||
)}
|
||||
<StackCustom gap={"lg"}>
|
||||
<Voting_ComponentDetailDataSection />
|
||||
<Voting_ComponentDetailDataSection data={data} />
|
||||
|
||||
<StackCustom gap={"xs"}>
|
||||
<StackCustom gap={"sm"}>
|
||||
<TextCustom bold size="small" align="center">
|
||||
Pilihan Anda
|
||||
</TextCustom>
|
||||
<BadgeCustom style={[GStyles.alignSelfCenter]}>
|
||||
Pilihan 1
|
||||
<BadgeCustom variant="light" size="lg" style={[GStyles.alignSelfCenter]}>
|
||||
{nameChoice || "-"}
|
||||
</BadgeCustom>
|
||||
</StackCustom>
|
||||
</StackCustom>
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
export default function Voting_BoxDetailHasilVotingSection({
|
||||
listData,
|
||||
}: {
|
||||
listData?: any[];
|
||||
listData: any[];
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -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 (
|
||||
<>
|
||||
<BoxWithHeaderSection>
|
||||
{headerAvatar ? headerAvatar : <Spacing />}
|
||||
<StackCustom>
|
||||
<Voting_ComponentDetailDataSection />
|
||||
<Voting_ComponentDetailDataSection data={data} />
|
||||
<StackCustom gap={"sm"}>
|
||||
<TextCustom bold size="small" align="center">
|
||||
Pilihan Anda
|
||||
</TextCustom>
|
||||
<BadgeCustom variant="light" size="lg" style={[GStyles.alignSelfCenter]}>
|
||||
{nameChoice || "-"}
|
||||
</BadgeCustom>
|
||||
</StackCustom>
|
||||
</StackCustom>
|
||||
</BoxWithHeaderSection>
|
||||
</>
|
||||
|
||||
@@ -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({
|
||||
<RadioGroup value={value} onChange={setValue}>
|
||||
{data?.Voting_DaftarNamaVote?.map((item: any, i: number) => (
|
||||
<View key={i}>
|
||||
<RadioCustom label={item?.value} value={item?.id} />
|
||||
<RadioCustom
|
||||
disabled={
|
||||
today.getDate() < new Date(data?.awalVote).getDate()
|
||||
}
|
||||
label={item?.value}
|
||||
value={item?.id}
|
||||
/>
|
||||
</View>
|
||||
))}
|
||||
</RadioGroup>
|
||||
</StackCustom>
|
||||
|
||||
<ButtonCustom disabled={value === ""} onPress={handlerSubmitVote}>
|
||||
<ButtonCustom
|
||||
disabled={value === ""}
|
||||
onPress={() => {
|
||||
AlertDefaultSystem({
|
||||
title: "Anda melaukan voting",
|
||||
message: "Yakin dengan pilihan anda ini ?",
|
||||
textLeft: "Batal",
|
||||
textRight: "Ya",
|
||||
onPressRight: () => handlerSubmitVote(),
|
||||
});
|
||||
}}
|
||||
>
|
||||
Vote
|
||||
</ButtonCustom>
|
||||
</>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export const today = new Date();
|
||||
export const dateTimeView = ({
|
||||
date,
|
||||
withoutTime = false,
|
||||
|
||||
Reference in New Issue
Block a user