Voting
Add: - api-client/api-voting: kumpulan fetching api voting Fix: - UI create dan (tabs) status udah terintegrasi ke API ### No Isuue
This commit is contained in:
@@ -1,20 +1,55 @@
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
import {
|
||||
BadgeCustom,
|
||||
BaseBox,
|
||||
LoaderCustom,
|
||||
ScrollableCustom,
|
||||
StackCustom,
|
||||
TextCustom,
|
||||
ViewWrapper,
|
||||
} from "@/components";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { dummyMasterStatus } from "@/lib/dummy-data/_master/status";
|
||||
import { apiVotingGetByStatus } from "@/service/api-client/api-voting";
|
||||
import { dateTimeView } from "@/utils/dateTimeView";
|
||||
import dayjs from "dayjs";
|
||||
import { useState } from "react";
|
||||
import { useFocusEffect } from "expo-router";
|
||||
import _ from "lodash";
|
||||
import { useCallback, useState } from "react";
|
||||
|
||||
export default function VotingStatus() {
|
||||
const { user } = useAuth();
|
||||
const id = user?.id || "";
|
||||
console.log("ID >> ", id);
|
||||
const [activeCategory, setActiveCategory] = useState<string | null>(
|
||||
"publish"
|
||||
);
|
||||
|
||||
const [listData, setListData] = useState([]);
|
||||
const [loadingGetData, setLoadingGetData] = useState(false);
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
onLoadData();
|
||||
}, [activeCategory, id])
|
||||
);
|
||||
|
||||
async function onLoadData() {
|
||||
try {
|
||||
setLoadingGetData(true);
|
||||
const response = await apiVotingGetByStatus({
|
||||
id: id as string,
|
||||
status: activeCategory!,
|
||||
});
|
||||
console.log("[RES LIST STATUS]", JSON.stringify(response.data, null, 2));
|
||||
setListData(response.data);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
} finally {
|
||||
setLoadingGetData(false);
|
||||
}
|
||||
}
|
||||
|
||||
const handlePress = (item: any) => {
|
||||
setActiveCategory(item.value);
|
||||
// tambahkan logika lain seperti filter dsb.
|
||||
@@ -34,27 +69,33 @@ export default function VotingStatus() {
|
||||
|
||||
return (
|
||||
<ViewWrapper headerComponent={scrollComponent} hideFooter>
|
||||
{Array.from({ length: 10 }).map((_, i) => (
|
||||
<BaseBox
|
||||
key={i}
|
||||
paddingTop={20}
|
||||
paddingBottom={20}
|
||||
href={`/voting/${i}/${activeCategory}/detail`}
|
||||
>
|
||||
<StackCustom>
|
||||
<TextCustom align="center" bold truncate size="large">
|
||||
Lorem ipsum dolor sit {activeCategory}
|
||||
</TextCustom>
|
||||
<BadgeCustom
|
||||
style={{ width: "70%", alignSelf: "center" }}
|
||||
variant="light"
|
||||
>
|
||||
{dayjs().format("DD/MM/YYYY")} -{" "}
|
||||
{dayjs().add(1, "day").format("DD/MM/YYYY")}
|
||||
</BadgeCustom>
|
||||
</StackCustom>
|
||||
</BaseBox>
|
||||
))}
|
||||
{loadingGetData ? (
|
||||
<LoaderCustom />
|
||||
) : _.isEmpty(listData) ? (
|
||||
<TextCustom align="center">Tidak ada data {activeCategory}</TextCustom>
|
||||
) : (
|
||||
listData.map((item: any, i: number) => (
|
||||
<BaseBox
|
||||
key={i}
|
||||
paddingTop={20}
|
||||
paddingBottom={20}
|
||||
href={`/voting/${item.id}/${activeCategory}/detail`}
|
||||
>
|
||||
<StackCustom>
|
||||
<TextCustom align="center" bold truncate={2} size="large">
|
||||
{item?.title || ""}
|
||||
</TextCustom>
|
||||
<BadgeCustom
|
||||
style={{ width: "70%", alignSelf: "center" }}
|
||||
variant="light"
|
||||
>
|
||||
{item?.awalVote && dateTimeView({date: item?.awalVote, withoutTime: true})} -{" "}
|
||||
{item?.akhirVote && dateTimeView({date: item?.akhirVote, withoutTime: true})}
|
||||
</BadgeCustom>
|
||||
</StackCustom>
|
||||
</BaseBox>
|
||||
))
|
||||
)}
|
||||
</ViewWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
import {
|
||||
AlertDefaultSystem,
|
||||
BackButton,
|
||||
@@ -11,14 +12,42 @@ import { IconArchive, IconContribution, IconEdit } from "@/components/_Icon";
|
||||
import { IMenuDrawerItem } from "@/components/_Interface/types";
|
||||
import { Voting_BoxDetailSection } from "@/screens/Voting/BoxDetailSection";
|
||||
import Voting_ButtonStatusSection from "@/screens/Voting/ButtonStatusSection";
|
||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||
import { useState } from "react";
|
||||
import { apiVotingGetOne } from "@/service/api-client/api-voting";
|
||||
import {
|
||||
router,
|
||||
Stack,
|
||||
useFocusEffect,
|
||||
useLocalSearchParams,
|
||||
} from "expo-router";
|
||||
import { useCallback, useState } from "react";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
|
||||
export default function VotingDetailStatus() {
|
||||
const {user} = useAuth()
|
||||
const { id, status } = useLocalSearchParams();
|
||||
console.log("ID >> ", id);
|
||||
console.log("STATUS >> ", status);
|
||||
const [openDrawerDraft, setOpenDrawerDraft] = useState(false);
|
||||
const [openDrawerPublish, setOpenDrawerPublish] = useState(false);
|
||||
|
||||
const [data, setData] = useState<any>(null);
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
onLoadData();
|
||||
}, [id])
|
||||
);
|
||||
|
||||
const onLoadData = async () => {
|
||||
try {
|
||||
const response = await apiVotingGetOne({ id: id as string });
|
||||
console.log("Response", JSON.stringify(response.data, null, 2));
|
||||
setData(response.data);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
const handlePressDraft = (item: IMenuDrawerItem) => {
|
||||
console.log("PATH >> ", item.path);
|
||||
router.navigate(item.path as any);
|
||||
@@ -57,8 +86,8 @@ export default function VotingDetailStatus() {
|
||||
}}
|
||||
/>
|
||||
<ViewWrapper>
|
||||
<Voting_BoxDetailSection />
|
||||
<Voting_ButtonStatusSection status={status as string} />
|
||||
<Voting_BoxDetailSection data={data as any}/>
|
||||
<Voting_ButtonStatusSection id={id as string} status={status as string} />
|
||||
<Spacing />
|
||||
</ViewWrapper>
|
||||
|
||||
|
||||
@@ -1,30 +1,103 @@
|
||||
import {
|
||||
ActionIcon,
|
||||
BoxButtonOnFooter,
|
||||
ButtonCenteredOnly,
|
||||
ButtonCustom,
|
||||
Grid,
|
||||
CenterCustom,
|
||||
Spacing,
|
||||
StackCustom,
|
||||
TextAreaCustom,
|
||||
TextInputCustom,
|
||||
ViewWrapper,
|
||||
ViewWrapper
|
||||
} from "@/components";
|
||||
import DateTimePickerCustom from "@/components/DateInput/DateTimePickerCustom";
|
||||
import { MainColor } from "@/constants/color-palet";
|
||||
import { ICON_SIZE_XLARGE } from "@/constants/constans-value";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { apiVotingCreate } from "@/service/api-client/api-voting";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { router } from "expo-router";
|
||||
import { TouchableOpacity } from "react-native";
|
||||
import _ from "lodash";
|
||||
import { useState } from "react";
|
||||
import { View } from "react-native";
|
||||
import Toast from "react-native-toast-message";
|
||||
|
||||
export default function VotingCreate() {
|
||||
const { user } = useAuth();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [data, setData] = useState({
|
||||
authorId: "",
|
||||
title: "",
|
||||
deskripsi: "",
|
||||
awalVote: "",
|
||||
akhirVote: "",
|
||||
listVote: [],
|
||||
});
|
||||
|
||||
const [listVote, setListVote] = useState([
|
||||
{
|
||||
name: "Nama Pilihan",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
name: "Nama Pilihan",
|
||||
value: "",
|
||||
},
|
||||
]);
|
||||
|
||||
const handlerSubmit = async () => {
|
||||
if (!data.title || !data.deskripsi || !data.awalVote || !data.akhirVote) {
|
||||
Toast.show({
|
||||
type: "info",
|
||||
text1: "Lengkapi semua data",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (listVote.some((item: any) => item.value === "")) {
|
||||
Toast.show({
|
||||
type: "info",
|
||||
text1: "Lengkapi semua data pilihan",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const newData = {
|
||||
...data,
|
||||
authorId: user?.id,
|
||||
awalVote: new Date(data.awalVote as any).toISOString(),
|
||||
akhirVote: new Date(data.akhirVote as any).toISOString(),
|
||||
listVote: listVote,
|
||||
};
|
||||
|
||||
const response = await apiVotingCreate(newData);
|
||||
// console.log("[RESPONSE]", JSON.stringify(response, null, 2));
|
||||
|
||||
if (response.success) {
|
||||
Toast.show({
|
||||
type: "success",
|
||||
text1: "Data berhasil disimpan",
|
||||
});
|
||||
router.replace("/(application)/(user)/voting/(tabs)/status");
|
||||
} else {
|
||||
Toast.show({
|
||||
type: "error",
|
||||
text1: "Data gagal disimpan",
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("[ERROR]", error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const buttonSubmit = () => {
|
||||
return (
|
||||
<>
|
||||
<BoxButtonOnFooter>
|
||||
<ButtonCustom
|
||||
onPress={() =>
|
||||
router.replace("/(application)/(user)/voting/(tabs)/status")
|
||||
}
|
||||
>
|
||||
<ButtonCustom isLoading={isLoading} onPress={() => handlerSubmit()}>
|
||||
Simpan
|
||||
</ButtonCustom>
|
||||
</BoxButtonOnFooter>
|
||||
@@ -39,6 +112,8 @@ export default function VotingCreate() {
|
||||
label="Judul Voting"
|
||||
placeholder="MasukanJudul Voting"
|
||||
required
|
||||
value={data.title}
|
||||
onChangeText={(value: any) => setData({ ...data, title: value })}
|
||||
/>
|
||||
<TextAreaCustom
|
||||
label="Deskripsi"
|
||||
@@ -46,11 +121,28 @@ export default function VotingCreate() {
|
||||
required
|
||||
showCount
|
||||
maxLength={1000}
|
||||
value={data.deskripsi}
|
||||
onChangeText={(value: any) => setData({ ...data, deskripsi: value })}
|
||||
/>
|
||||
<DateTimePickerCustom
|
||||
label="Mulai Voting"
|
||||
required
|
||||
// value={data.awalVote ? new Date(data.awalVote) : null}
|
||||
onChange={(value: any) => setData({ ...data, awalVote: value })}
|
||||
minimumDate={new Date(Date.now())}
|
||||
/>
|
||||
<DateTimePickerCustom
|
||||
disabled={!data.awalVote}
|
||||
label="Voting Berakhir"
|
||||
required
|
||||
// value={data.akhirVote ? new Date(data.akhirVote) : null}
|
||||
onChange={(value: any) => setData({ ...data, akhirVote: value })}
|
||||
minimumDate={
|
||||
data.awalVote ? new Date(data.awalVote) : new Date(Date.now())
|
||||
}
|
||||
/>
|
||||
<DateTimePickerCustom label="Mulai Voting" required />
|
||||
<DateTimePickerCustom label="Voting Berakhir" required />
|
||||
|
||||
<Grid>
|
||||
{/* <Grid>
|
||||
<Grid.Col span={10}>
|
||||
<TextInputCustom
|
||||
label="Pilihan"
|
||||
@@ -66,11 +158,64 @@ export default function VotingCreate() {
|
||||
<Ionicons name="trash" size={24} color={MainColor.red} />
|
||||
</TouchableOpacity>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
|
||||
<ButtonCenteredOnly onPress={() => console.log("add")}>
|
||||
</Grid> */}
|
||||
{/* <ButtonCenteredOnly onPress={() => console.log("add")}>
|
||||
Tambah Pilihan
|
||||
</ButtonCenteredOnly>
|
||||
</ButtonCenteredOnly> */}
|
||||
|
||||
{listVote.map((item, index) => (
|
||||
<TextInputCustom
|
||||
key={index}
|
||||
label="Pilihan"
|
||||
placeholder="Masukan Pilihan"
|
||||
required
|
||||
value={item.value}
|
||||
onChangeText={(value: any) =>
|
||||
setListVote(
|
||||
listVote.map((item, i) =>
|
||||
i === index ? { ...item, value } : item
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
|
||||
<CenterCustom>
|
||||
<View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
|
||||
<ActionIcon
|
||||
disabled={listVote.length >= 4}
|
||||
onPress={() => {
|
||||
setListVote([...listVote, { name: "Nama Pilihan", value: "" }]);
|
||||
}}
|
||||
icon={
|
||||
<Ionicons
|
||||
name="add-circle-outline"
|
||||
size={ICON_SIZE_XLARGE}
|
||||
color={MainColor.black}
|
||||
/>
|
||||
}
|
||||
size="xl"
|
||||
/>
|
||||
<ActionIcon
|
||||
disabled={listVote.length <= 2}
|
||||
onPress={() => {
|
||||
const list = _.clone(listVote);
|
||||
list.pop();
|
||||
setListVote(list);
|
||||
}}
|
||||
icon={
|
||||
<Ionicons
|
||||
name="remove-circle-outline"
|
||||
size={ICON_SIZE_XLARGE}
|
||||
color={MainColor.black}
|
||||
/>
|
||||
}
|
||||
size="xl"
|
||||
/>
|
||||
</View>
|
||||
</CenterCustom>
|
||||
<Spacing />
|
||||
|
||||
<Spacing />
|
||||
</StackCustom>
|
||||
</ViewWrapper>
|
||||
|
||||
Reference in New Issue
Block a user