fix voting

deskripsi:
- ubah metode pemanggilan data dari SSR menjadi metode API , pada page:
detail all

No Issue
This commit is contained in:
2025-06-02 16:15:31 +08:00
parent c057f20963
commit af903c0def
15 changed files with 144 additions and 245 deletions

View File

@@ -1,28 +1,14 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { LayoutVote_DetailKontribusi } from "@/app_modules/vote";
import { voting_funGetOneVotingbyId } from "@/app_modules/vote/fun/get/fun_get_one_by_id";
import React from "react";
export default async function Layout({
children,
params,
}: {
children: React.ReactNode;
params: { id: string };
}) {
const votingId = params.id;
const userLoginId = await funGetUserIdByToken();
const dataVoting = await voting_funGetOneVotingbyId(votingId);
return (
<>
<LayoutVote_DetailKontribusi
votingId={votingId}
userLoginId={userLoginId as string}
dataVoting={dataVoting}
>
{children}
</LayoutVote_DetailKontribusi>
<LayoutVote_DetailKontribusi>{children}</LayoutVote_DetailKontribusi>
</>
);
}

View File

@@ -1,28 +1,14 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { LayoutVote_MainDetail } from "@/app_modules/vote";
import { voting_funGetOneVotingbyId } from "@/app_modules/vote/fun/get/fun_get_one_by_id";
import React from "react";
export default async function Layout({
children,
params,
}: {
children: React.ReactNode;
params: { id: string };
}) {
const votingId = params.id;
const userLoginId = await funGetUserIdByToken();
const dataVoting = await voting_funGetOneVotingbyId(votingId);
return (
<>
<LayoutVote_MainDetail
votingId={votingId}
userLoginId={userLoginId as string}
dataVoting={dataVoting}
>
{children}
</LayoutVote_MainDetail>
<LayoutVote_MainDetail>{children}</LayoutVote_MainDetail>
</>
);
}

View File

@@ -1,13 +1,9 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { Vote_MainDetail } from "@/app_modules/vote";
export default async function Page({ params }: { params: { id: string } }) {
const userLoginId = await funGetUserIdByToken();
export default async function Page() {
return (
<>
<Vote_MainDetail
userLoginId={userLoginId as string}
/>
<Vote_MainDetail />
</>
);
}

View File

@@ -1,29 +1,14 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { LayoutVote_DetailPublish } from "@/app_modules/vote";
import { voting_funGetOneVotingbyId } from "@/app_modules/vote/fun/get/fun_get_one_by_id";
import React from "react";
export default async function Layout({
children,
params,
}: {
children: React.ReactNode;
params: { id: string };
}) {
const votingId = params.id;
const userLoginId = await funGetUserIdByToken();
const dataVoting = await voting_funGetOneVotingbyId(votingId);
return (
<>
<LayoutVote_DetailPublish
votingId={votingId}
userLoginId={userLoginId as string}
dataVoting={dataVoting}
>
{children}
</LayoutVote_DetailPublish>
<LayoutVote_DetailPublish>{children}</LayoutVote_DetailPublish>
</>
);
}

View File

@@ -1,14 +1,9 @@
import { Vote_DetailPublish } from "@/app_modules/vote";
import { Vote_getListKontributorById } from "@/app_modules/vote/fun/get/get_list_kontributor_by_id";
import { voting_funGetOneVotingbyId } from "@/app_modules/vote/fun/get/fun_get_one_by_id";
export default async function Page({ params }: { params: { id: string } }) {
let voteId = params.id;
const dataVote = await voting_funGetOneVotingbyId(voteId);
export default async function Page() {
return (
<>
<Vote_DetailPublish dataVote={dataVote as any} />
<Vote_DetailPublish />
</>
);
}

View File

@@ -1,19 +1,9 @@
import { Vote_DetailRiwayatSaya } from "@/app_modules/vote";
import { Vote_getListKontributorById } from "@/app_modules/vote/fun/get/get_list_kontributor_by_id";
import { Vote_getOnePublishbyId } from "@/app_modules/vote/fun/get/get_one_publish_by_id";
export default async function Page({params}: {params: {id: string}}) {
let voteId = params.id;
const dataVote = await Vote_getOnePublishbyId(voteId);
const listKontributor = await Vote_getListKontributorById(voteId);
export default async function Page() {
return (
<>
<Vote_DetailRiwayatSaya
dataVote={dataVote as any}
listKontributor={listKontributor}
/>
<Vote_DetailRiwayatSaya />
</>
);
}

View File

@@ -1,25 +1,14 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { LayoutVote_DetailSemuaRiwayat } from "@/app_modules/vote";
import React from "react";
export default async function Layout({
children,
params,
}: {
children: React.ReactNode;
params: { id: string };
}) {
const votingId = params.id;
const userLoginId = await funGetUserIdByToken();
return (
<>
<LayoutVote_DetailSemuaRiwayat
votingId={votingId}
userLoginId={userLoginId as string}
>
{children}
</LayoutVote_DetailSemuaRiwayat>
<LayoutVote_DetailSemuaRiwayat>{children}</LayoutVote_DetailSemuaRiwayat>
</>
);
}

View File

@@ -1,10 +1,13 @@
import { RouterVote } from "@/lib/router_hipmi/router_vote";
import { AccentColor, MainColor } from "@/app_modules/_global/color";
import ComponentGlobal_Loader from "@/app_modules/_global/component/loader";
import { Component_Header } from "@/app_modules/_global/component/new/component_header";
import { apiNewGetUserIdByToken } from "@/app_modules/_global/lib/api_fetch_global";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
import { UIGlobal_Modal } from "@/app_modules/_global/ui";
import UIGlobal_LayoutHeaderTamplate from "@/app_modules/_global/ui/ui_header_tamplate";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { RouterVote } from "@/lib/router_hipmi/router_vote";
import {
ActionIcon,
Button,
@@ -14,55 +17,84 @@ import {
Stack,
Text,
} from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import {
IconArchive,
IconDotsVertical,
IconUsersGroup,
IconX,
} from "@tabler/icons-react";
import { useRouter } from "next/navigation";
import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import { apiGetOneVotingById } from "../../_lib/api_voting";
import { voting_funUpdateIsArsipById } from "../../fun";
import { MODEL_VOTING } from "../../model/interface";
import { voting_funGetOneVotingbyId } from "../../fun/get/fun_get_one_by_id";
import { Component_Header } from "@/app_modules/_global/component/new/component_header";
export function Voting_ComponentLayoutHeaderDetailPublish({
votingId,
title,
userLoginId,
dataVoting,
}: {
votingId: string;
title: string;
userLoginId: string;
dataVoting: any;
}) {
const [data, setData] = useState<MODEL_VOTING>(dataVoting);
const router = useRouter();
const { id } = useParams();
const [openDrawer, setOpenDrawer] = useState(false);
const [openModal, setOpenModal] = useState(false);
const [isLoading, setIsLoading] = useState(false);
async function onUpdateStatusArsip({ isArsip }: { isArsip: boolean }) {
setIsLoading(true);
const res = await voting_funUpdateIsArsipById({
votingId,
isArsip: isArsip,
});
if (res.status === 200) {
try {
const loadData = await voting_funGetOneVotingbyId(votingId);
setData(loadData as any);
} catch (error) {
console.log(error);
} finally {
setOpenModal(false);
ComponentGlobal_NotifikasiBerhasil(res.message);
setIsLoading(false);
const [data, setData] = useState<MODEL_VOTING | null | any>();
const [userLoginId, setUserLoginId] = useState<string | null>(null);
useShallowEffect(() => {
handleGetUserId();
onLoadData();
}, []);
async function handleGetUserId() {
try {
const respone = await apiNewGetUserIdByToken();
if (respone) {
setUserLoginId(respone.userId);
}
} else {
ComponentGlobal_NotifikasiGagal(res.message);
} catch (error) {
console.error("Error get data detail", error);
}
}
async function onLoadData() {
try {
const response = await apiGetOneVotingById({ id: id as string });
if (response) {
setData(response.data);
} else {
setData(null);
}
} catch (error) {
console.log(error);
}
}
async function onUpdateStatusArsip({ isArsip }: { isArsip: boolean }) {
try {
setIsLoading(true);
const res = await voting_funUpdateIsArsipById({
votingId: id as string,
isArsip: isArsip,
});
if (res.status !== 200) {
setIsLoading(false);
ComponentGlobal_NotifikasiPeringatan(res.message);
return;
}
setIsLoading(false);
ComponentGlobal_NotifikasiBerhasil("Berhasil Update");
router.back();
} catch (error) {
console.log(error);
setIsLoading(false);
ComponentGlobal_NotifikasiGagal("Gagal Update");
}
}
@@ -71,14 +103,18 @@ export function Voting_ComponentLayoutHeaderDetailPublish({
<Component_Header
title={title}
customButtonRight={
<ActionIcon
variant="transparent"
onClick={() => {
setOpenDrawer(true);
}}
>
<IconDotsVertical color="white" />
</ActionIcon>
userLoginId ? (
<ActionIcon
variant="transparent"
onClick={() => {
setOpenDrawer(true);
}}
>
<IconDotsVertical color="white" />
</ActionIcon>
) : (
<CustomSkeleton circle height={24} width={24} />
)
}
/>
@@ -123,14 +159,14 @@ export function Voting_ComponentLayoutHeaderDetailPublish({
{/* Check Author */}
{data?.authorId === userLoginId ? (
<BoxIsAuthor
votingId={votingId}
votingId={id as string}
onSetDrawer={(val: any) => {
setOpenDrawer(val.drawer);
setOpenModal(val.modal);
}}
/>
) : (
<BoxNotAuthor votingId={votingId} />
<BoxNotAuthor votingId={id as string} />
)}
</Stack>
</Drawer>

View File

@@ -9,38 +9,14 @@ import { Voting_ComponentLayoutHeaderDetailPublish } from "../../component";
export default function LayoutVote_DetailKontribusi({
children,
votingId,
userLoginId,
dataVoting,
}: {
children: React.ReactNode;
votingId: string;
userLoginId: string;
dataVoting: any;
}) {
return (
<>
{/* <UIGlobal_LayoutTamplate
header={
<Voting_ComponentLayoutHeaderDetailPublish
dataVoting={dataVoting}
title="Detail Kontribusi"
userLoginId={userLoginId}
votingId={votingId}
/>
}
>
{children}
</UIGlobal_LayoutTamplate> */}
<UI_NewLayoutTamplate>
<UI_NewHeader>
<Voting_ComponentLayoutHeaderDetailPublish
dataVoting={dataVoting}
title="Detail Kontributor"
votingId={votingId}
userLoginId={userLoginId}
/>
<Voting_ComponentLayoutHeaderDetailPublish title="Detail Kontributor" />
</UI_NewHeader>
<UI_NewChildren>{children}</UI_NewChildren>
</UI_NewLayoutTamplate>

View File

@@ -9,9 +9,11 @@ import {
ComponentGlobal_CardStyles,
} from "@/app_modules/_global/component";
import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information";
import { Comp_SetInnerHTML } from "@/app_modules/_global/component/new/comp_set_inner_html";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global";
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import notifikasiToUser_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_user";
import { IRealtimeData } from "@/lib/global_state";
import { clientLogger } from "@/util/clientLogger";
@@ -41,14 +43,9 @@ import ComponentVote_HasilVoting from "../../component/detail/detail_hasil_votin
import { Voting_ComponentSkeletonDetail } from "../../component/skeleton_view";
import { Vote_funCreateHasil } from "../../fun/create/create_hasil";
import { MODEL_VOTING } from "../../model/interface";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { Comp_SetInnerHTML } from "@/app_modules/_global/component/new/comp_set_inner_html";
import { apiNewGetUserIdByToken } from "@/app_modules/_global/lib/api_fetch_global";
export default function Vote_MainDetail({
userLoginId,
}: {
userLoginId: string;
}) {
export default function Vote_MainDetail() {
const params = useParams<{ id: string }>();
const today = new Date();
const [data, setData] = useState<MODEL_VOTING | null>(null);
@@ -59,12 +56,13 @@ export default function Vote_MainDetail({
);
const [isLoading, setLoading] = useState(false);
const [isKontributor, setIsKontributor] = useState<boolean | null>(null);
const [userLoginId, setUserLoginId] = useState<string | null>(null);
useShallowEffect(() => {
onLoadData();
onLoadHasil();
handleGetUserId();
}, []);
async function onLoadData() {
@@ -100,6 +98,18 @@ export default function Vote_MainDetail({
onLoadPilihan();
}, []);
async function handleGetUserId() {
try {
const respone = await apiNewGetUserIdByToken();
if (respone) {
setUserLoginId(respone.userId);
}
} catch (error) {
clientLogger.error("Error get data detail", error);
}
}
async function onCheckKontribusi() {
try {
const respone = await apiCheckKontributorToOneVoting({

View File

@@ -9,37 +9,14 @@ import { Voting_ComponentLayoutHeaderDetailPublish } from "../../component";
export default function LayoutVote_MainDetail({
children,
votingId,
userLoginId,
dataVoting,
}: {
children: React.ReactNode;
votingId: string;
userLoginId: string;
dataVoting: any;
}) {
return (
<>
{/* <UIGlobal_LayoutTamplate
header={
<Voting_ComponentLayoutHeaderDetailPublish
title="Detail Voting"
votingId={votingId}
userLoginId={userLoginId}
dataVoting={dataVoting}
/>
}
>
{children}
</UIGlobal_LayoutTamplate> */}
<UI_NewLayoutTamplate>
<UI_NewHeader>
<Voting_ComponentLayoutHeaderDetailPublish
dataVoting={dataVoting}
title="Detail Voting"
votingId={votingId}
userLoginId={userLoginId}
/>
<Voting_ComponentLayoutHeaderDetailPublish title="Detail Voting" />
</UI_NewHeader>
<UI_NewChildren>{children}</UI_NewChildren>
</UI_NewLayoutTamplate>

View File

@@ -4,22 +4,45 @@ import { Badge, Center, Stack } from "@mantine/core";
import ComponentVote_DetailDataSetelahPublish from "../../component/detail/detail_data_setelah_publish";
import ComponentVote_HasilVoting from "../../component/detail/detail_hasil_voting";
import { MODEL_VOTING } from "../../model/interface";
import { apiGetOneVotingById } from "../../_lib/api_voting";
import { useParams } from "next/navigation";
import { useState } from "react";
import { useShallowEffect } from "@mantine/hooks";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
export default function Vote_DetailPublish() {
const { id } = useParams();
const [data, setData] = useState<MODEL_VOTING | null>();
useShallowEffect(() => {
onLoadData();
}, []);
async function onLoadData() {
try {
const response = await apiGetOneVotingById({ id: id as string });
if (response) {
setData(response.data);
} else {
setData(null);
}
} catch (error) {
console.log(error);
}
}
if (!data) return <CustomSkeleton height={400} />;
export default function Vote_DetailPublish({
dataVote,
}: {
dataVote: MODEL_VOTING;
}) {
return (
<>
<Stack py={"md"}>
<Center >
<Badge color={dataVote?.isArsip ? "gray" : "green"}>
{dataVote?.isArsip ? "Arsip" : "Publish"}
<Center>
<Badge color={data?.isArsip ? "gray" : "green"}>
{data?.isArsip ? "Arsip" : "Publish"}
</Badge>
</Center>
<ComponentVote_DetailDataSetelahPublish data={dataVote} />
<ComponentVote_HasilVoting data={dataVote.Voting_DaftarNamaVote} />
<ComponentVote_DetailDataSetelahPublish data={data as any} />
<ComponentVote_HasilVoting data={data?.Voting_DaftarNamaVote} />
</Stack>
</>
);

View File

@@ -9,38 +9,14 @@ import { Voting_ComponentLayoutHeaderDetailPublish } from "../../component";
export default function LayoutVote_DetailPublish({
children,
votingId,
userLoginId,
dataVoting,
}: {
children: React.ReactNode;
votingId: string;
userLoginId: string;
dataVoting: any;
}) {
return (
<>
{/* <UIGlobal_LayoutTamplate
header={
<Voting_ComponentLayoutHeaderDetailPublish
dataVoting={dataVoting}
title="Detail Publish"
votingId={votingId}
userLoginId={userLoginId}
/>
}
>
{children}
</UIGlobal_LayoutTamplate> */}
<UI_NewLayoutTamplate>
<UI_NewHeader>
<Voting_ComponentLayoutHeaderDetailPublish
dataVoting={dataVoting}
title="Detail Publish"
votingId={votingId}
userLoginId={userLoginId}
/>
<Voting_ComponentLayoutHeaderDetailPublish title="Detail Publish" />
</UI_NewHeader>
<UI_NewChildren>{children}</UI_NewChildren>
</UI_NewLayoutTamplate>

View File

@@ -16,13 +16,7 @@ import {
} from "../../_lib/api_voting";
import { Voting_ComponentSkeletonDetail } from "../../component/skeleton_view";
export default function Vote_DetailRiwayatSaya({
dataVote,
listKontributor,
}: {
dataVote: MODEL_VOTING;
listKontributor: any[];
}) {
export default function Vote_DetailRiwayatSaya() {
const params = useParams<{ id: string }>();
const [data, setData] = useState<MODEL_VOTING | null>(null);
const [hasil, setHasil] = useState<any[] | null>(null);

View File

@@ -11,39 +11,19 @@ import { IconDots } from "@tabler/icons-react";
import React, { useState } from "react";
import { Component_Header } from "@/app_modules/_global/component/new/component_header";
import UI_NewLayoutTamplate, { UI_NewHeader, UI_NewChildren } from "@/app_modules/_global/ui/V2_layout_tamplate";
import { useParams } from "next/navigation";
export default function LayoutVote_DetailSemuaRiwayat({
children,
votingId,
userLoginId,
}: {
children: React.ReactNode;
votingId: string;
userLoginId: string;
}) {
const params = useParams<{ id: string }>();
const votingId = params.id;
const [openDrawer, setOpenDrawer] = useState(false);
return (
<>
{/* <UIGlobal_LayoutTamplate
header={
<UIGlobal_LayoutHeaderTamplate
title="Detail Riwayat"
customButtonRight={
<ActionIcon
variant="transparent"
onClick={() => {
setOpenDrawer(true);
}}
>
<IconDotsVertical color="white" />
</ActionIcon>
}
/>
}
>
{children}
</UIGlobal_LayoutTamplate> */}
<UI_NewLayoutTamplate>
<UI_NewHeader>