UI – Voting (User) - app/(application)/(user)/voting/(tabs)/index.tsx - app/(application)/(user)/voting/(tabs)/history.tsx - app/(application)/(user)/voting/(tabs)/contribution.tsx - app/(application)/(user)/voting/create.tsx - app/(application)/(user)/voting/[id]/edit.tsx - app/(application)/(user)/voting/[id]/[status]/detail.tsx - app/(application)/(user)/voting/[id]/list-of-contributor.tsx UI – Event - app/(application)/(user)/event/[id]/edit.tsx - screens/Event/ScreenStatus.tsx UI – Voting Screens (New) - screens/Voting/ScreenBeranda.tsx - screens/Voting/ScreenContribution.tsx - screens/Voting/ScreenHistory.tsx - screens/Voting/ScreenListOfContributor.tsx - screens/Voting/ScreenStatus.tsx - screens/Voting/ButtonStatusSection.tsx UI – Job - screens/Job/ButtonStatusSection.tsx - screens/Job/MainViewStatus2.tsx API Client - service/api-client/api-voting.ts Docs - docs/prompt-for-qwen-code.md ### No Issue
233 lines
5.7 KiB
TypeScript
233 lines
5.7 KiB
TypeScript
import { AlertDefaultSystem, ButtonCustom, Grid } from "@/components";
|
|
import {
|
|
apiVotingDelete,
|
|
apiVotingUpdateStatus,
|
|
} from "@/service/api-client/api-voting";
|
|
import { RelativePathString, router } from "expo-router";
|
|
import Toast from "react-native-toast-message";
|
|
|
|
export default function Voting_ButtonStatusSection({
|
|
id,
|
|
status,
|
|
isLoading,
|
|
onSetLoading,
|
|
}: {
|
|
id: string;
|
|
status: string;
|
|
isLoading: boolean;
|
|
onSetLoading: (value: boolean) => void;
|
|
}) {
|
|
const path: any = (status: string) => {
|
|
return `/voting/(tabs)/status?status=${status}`;
|
|
};
|
|
|
|
const handleBatalkanReview = () => {
|
|
AlertDefaultSystem({
|
|
title: "Batalkan Review",
|
|
message: "Apakah Anda yakin ingin batalkan review ini?",
|
|
textLeft: "Batal",
|
|
textRight: "Ya",
|
|
onPressRight: async () => {
|
|
try {
|
|
onSetLoading(true);
|
|
const response = await apiVotingUpdateStatus({
|
|
id: id as string,
|
|
status: "draft",
|
|
});
|
|
|
|
if (response?.success) {
|
|
Toast.show({
|
|
type: "success",
|
|
text1: "Berhasil batalkan review",
|
|
});
|
|
router.replace(path("draft"));
|
|
} else {
|
|
Toast.show({
|
|
type: "info",
|
|
text1: "Info",
|
|
text2: response.message,
|
|
});
|
|
router.back();
|
|
}
|
|
} catch (error) {
|
|
console.log("[ERROR]", error);
|
|
} finally {
|
|
onSetLoading(false);
|
|
}
|
|
},
|
|
});
|
|
};
|
|
|
|
const handleAjukanReview = () => {
|
|
AlertDefaultSystem({
|
|
title: "Ajukan Review",
|
|
message: "Apakah Anda yakin ingin ajukan review ini?",
|
|
textLeft: "Batal",
|
|
textRight: "Ya",
|
|
onPressRight: async () => {
|
|
try {
|
|
onSetLoading(true);
|
|
const response = await apiVotingUpdateStatus({
|
|
id: id as string,
|
|
status: "review",
|
|
});
|
|
|
|
if (response?.success) {
|
|
Toast.show({
|
|
type: "success",
|
|
text1: "Berhasil ajukan review",
|
|
});
|
|
router.replace(path("review"));
|
|
} else {
|
|
Toast.show({
|
|
type: "info",
|
|
text1: "Info",
|
|
text2: response.message,
|
|
});
|
|
router.back();
|
|
}
|
|
} catch (error) {
|
|
console.log("[ERROR]", error);
|
|
} finally {
|
|
onSetLoading(false);
|
|
}
|
|
},
|
|
});
|
|
};
|
|
|
|
const handleEditKembali = () => {
|
|
AlertDefaultSystem({
|
|
title: "Edit Kembali",
|
|
message: "Apakah Anda yakin ingin edit kembali ini?",
|
|
textLeft: "Batal",
|
|
textRight: "Ya",
|
|
onPressRight: async () => {
|
|
try {
|
|
onSetLoading(true);
|
|
const response = await apiVotingUpdateStatus({
|
|
id: id as string,
|
|
status: "draft",
|
|
});
|
|
|
|
if (response?.success) {
|
|
Toast.show({
|
|
type: "success",
|
|
text1: "Berhasil edit kembali",
|
|
});
|
|
router.replace(path("draft"));
|
|
} else {
|
|
Toast.show({
|
|
type: "info",
|
|
text1: "Info",
|
|
text2: response.message,
|
|
});
|
|
router.back();
|
|
}
|
|
} catch (error) {
|
|
console.log("[ERROR]", error);
|
|
} finally {
|
|
onSetLoading(false);
|
|
}
|
|
},
|
|
});
|
|
};
|
|
|
|
const handleOpenDeleteAlert = () => {
|
|
AlertDefaultSystem({
|
|
title: "Hapus",
|
|
message: "Apakah Anda yakin ingin menghapus data ini?",
|
|
textLeft: "Batal",
|
|
textRight: "Hapus",
|
|
onPressRight: async () => {
|
|
try {
|
|
onSetLoading(true);
|
|
const response = await apiVotingDelete({
|
|
id: id as string,
|
|
});
|
|
|
|
if (response?.success) {
|
|
Toast.show({
|
|
type: "success",
|
|
text1: "Berhasil hapus data",
|
|
});
|
|
router.back();
|
|
} else {
|
|
Toast.show({
|
|
type: "info",
|
|
text1: "Info",
|
|
text2: response.message,
|
|
});
|
|
router.back();
|
|
}
|
|
} catch (error) {
|
|
console.log("[ERROR]", error);
|
|
} finally {
|
|
onSetLoading(false);
|
|
}
|
|
},
|
|
});
|
|
};
|
|
|
|
const DeleteButton = () => {
|
|
return (
|
|
<>
|
|
<ButtonCustom
|
|
isLoading={isLoading}
|
|
backgroundColor="red"
|
|
textColor="white"
|
|
onPress={handleOpenDeleteAlert}
|
|
>
|
|
Hapus
|
|
</ButtonCustom>
|
|
</>
|
|
);
|
|
};
|
|
|
|
switch (status) {
|
|
case "publish":
|
|
return <></>;
|
|
|
|
case "review":
|
|
return (
|
|
<ButtonCustom isLoading={isLoading} onPress={handleBatalkanReview}>
|
|
Batalkan Review
|
|
</ButtonCustom>
|
|
);
|
|
|
|
case "draft":
|
|
return (
|
|
<>
|
|
<Grid>
|
|
<Grid.Col span={6} style={{ paddingRight: 10 }}>
|
|
<ButtonCustom isLoading={isLoading} onPress={handleAjukanReview}>
|
|
Ajukan Review
|
|
</ButtonCustom>
|
|
</Grid.Col>
|
|
<Grid.Col span={6} style={{ paddingRight: 10 }}>
|
|
{DeleteButton()}
|
|
</Grid.Col>
|
|
</Grid>
|
|
</>
|
|
);
|
|
|
|
case "reject":
|
|
return (
|
|
<>
|
|
<Grid>
|
|
<Grid.Col span={6} style={{ paddingRight: 10 }}>
|
|
<ButtonCustom isLoading={isLoading} onPress={handleEditKembali}>
|
|
Edit Kembali
|
|
</ButtonCustom>
|
|
</Grid.Col>
|
|
<Grid.Col span={6} style={{ paddingLeft: 10 }}>
|
|
{DeleteButton()}
|
|
</Grid.Col>
|
|
</Grid>
|
|
</>
|
|
);
|
|
|
|
default:
|
|
return <ButtonCustom disabled>Status Undifined</ButtonCustom>;
|
|
}
|
|
}
|