Fix: Voting
Deskripsi: - Fix notifikasi admin to user - Fix notifikasi user to admin ## No Issue
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import { atomWithStorage } from "jotai/utils";
|
||||
import { IAdmin_ActiveChildId, IAdmin_ActivePage } from "../notifikasi/route_setting/type_of_select_page";
|
||||
|
||||
export const gs_admin_navbar_menu = atomWithStorage<string>(
|
||||
export const gs_admin_navbar_menu = atomWithStorage<IAdmin_ActivePage | null>(
|
||||
"gs_admin_navbar_menu",
|
||||
"Main"
|
||||
);
|
||||
|
||||
export const gs_admin_navbar_subMenu = atomWithStorage<string | null>(
|
||||
export const gs_admin_navbar_subMenu = atomWithStorage<IAdmin_ActiveChildId | string>(
|
||||
"gs_admin_navbar_submenu",
|
||||
null
|
||||
""
|
||||
);
|
||||
|
||||
export const gs_admin_navbar_isActive_dropdown = atomWithStorage<boolean>(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
gs_adminEventTriggerReview,
|
||||
gs_adminEvent_triggerReview,
|
||||
IRealtimeData,
|
||||
} from "@/app/lib/global_state";
|
||||
import { AccentColor } from "@/app_modules/_global/color";
|
||||
@@ -63,7 +63,7 @@ export default function AdminEvent_ComponentTableReview({
|
||||
|
||||
// Realtime state
|
||||
const [isAdminTriggerReview, setIsAdminTriggerReview] = useAtom(
|
||||
gs_adminEventTriggerReview
|
||||
gs_adminEvent_triggerReview
|
||||
);
|
||||
const [isShowReload, setIsShowReload] = useState(false);
|
||||
|
||||
@@ -289,27 +289,25 @@ export default function AdminEvent_ComponentTableReview({
|
||||
|
||||
<Paper p={"md"} withBorder shadow="lg" h={"80vh"}>
|
||||
{isShowReload && (
|
||||
<Paper bg={"red"} w={"50%"}>
|
||||
<Affix position={{ top: rem(200) }} w={"100%"}>
|
||||
<Center>
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
border: `1px solid ${AccentColor.skyblue}`,
|
||||
}}
|
||||
bg={AccentColor.blue}
|
||||
loaderPosition="center"
|
||||
loading={isLoading}
|
||||
radius={"xl"}
|
||||
opacity={0.8}
|
||||
onClick={() => onLoadData()}
|
||||
leftIcon={<IconRefresh />}
|
||||
>
|
||||
Update Data
|
||||
</Button>
|
||||
</Center>
|
||||
</Affix>
|
||||
</Paper>
|
||||
<Affix position={{ top: rem(200) }} w={"100%"}>
|
||||
<Center>
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
border: `1px solid ${AccentColor.skyblue}`,
|
||||
}}
|
||||
bg={AccentColor.blue}
|
||||
loaderPosition="center"
|
||||
loading={isLoading}
|
||||
radius={"xl"}
|
||||
opacity={0.8}
|
||||
onClick={() => onLoadData()}
|
||||
leftIcon={<IconRefresh />}
|
||||
>
|
||||
Update Data
|
||||
</Button>
|
||||
</Center>
|
||||
</Affix>
|
||||
)}
|
||||
|
||||
<ScrollArea w={"100%"} h={"90%"}>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { RouterAdminGlobal } from "@/app/lib";
|
||||
import {
|
||||
gs_adminJobTriggerReview,
|
||||
gs_adminJob_triggerReview,
|
||||
IRealtimeData,
|
||||
} from "@/app/lib/global_state";
|
||||
import { ComponentGlobal_InputCountDown } from "@/app_modules/_global/component";
|
||||
@@ -63,7 +63,7 @@ export default function AdminJob_ViewTavleReview({
|
||||
|
||||
// Realtime
|
||||
const [isAdminJob_TriggerReview, setIsAdminJob_TriggerReview] = useAtom(
|
||||
gs_adminJobTriggerReview
|
||||
gs_adminJob_triggerReview
|
||||
);
|
||||
const [isShowReload, setIsShowReload] = useState(false);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export const listAdminPage = [
|
||||
// Main Dashboard
|
||||
{
|
||||
id: 1,
|
||||
name: "Main Dashboard",
|
||||
name: "Dashboard",
|
||||
path: RouterAdminDashboard.main_admin,
|
||||
icon: <IconHome />,
|
||||
child: [],
|
||||
|
||||
@@ -139,7 +139,7 @@ export function Admin_NewLayout({
|
||||
<Stack style={{ color: "white" }}>
|
||||
<Admin_UiNavbar
|
||||
userRoleId={userRoleId}
|
||||
activeId={activeId}
|
||||
activeId={activeId as any}
|
||||
activeChildId={activeChildId as any}
|
||||
setActiveId={setActiveId}
|
||||
setActiveChildId={setActiveChildId}
|
||||
@@ -186,13 +186,13 @@ export function Admin_NewLayout({
|
||||
opened={isDrawerNotifikasi}
|
||||
onClose={() => setDrawerNotifikasi(false)}
|
||||
position="right"
|
||||
size={"xs"}
|
||||
size={"sm"}
|
||||
>
|
||||
<ComponentAdmin_UIDrawerNotifikasi
|
||||
newAdminNtf={newAdminNtf}
|
||||
listNotifikasi={dataNotifikasi}
|
||||
onChangeNavbar={(val: { id: string; childId: string }) => {
|
||||
setActiveId(val.id);
|
||||
setActiveId(val.id as any);
|
||||
setActiveChildId(val.childId);
|
||||
}}
|
||||
onToggleNavbar={(val: any) => {
|
||||
|
||||
@@ -29,7 +29,7 @@ export const newListAdminPage = [
|
||||
// Main Dashboard
|
||||
{
|
||||
id: "Main",
|
||||
name: "Main Dashboard",
|
||||
name: "Dashboard",
|
||||
path: RouterAdminDashboard.main_admin,
|
||||
icon: <IconHome />,
|
||||
child: [],
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import _ from "lodash";
|
||||
|
||||
export async function admin_funVotingCheckStatus({ id }: { id: string }) {
|
||||
const data = await prisma.voting.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
Voting_Status: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!data)
|
||||
return { status: 400, message: "Id tidak ditemukan", statusName: "" };
|
||||
return {
|
||||
status: 200,
|
||||
message: "Id ditemukan",
|
||||
statusName: _.lowerCase(data.Voting_Status?.name),
|
||||
};
|
||||
}
|
||||
@@ -1,37 +1,82 @@
|
||||
import { RouterAdminEvent } from "@/app/lib/router_admin/router_admin_event";
|
||||
import { RouterAdminVote } from "@/app/lib/router_admin/router_admin_vote";
|
||||
import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
import { admin_funEventCheckStatus } from "../fun/get";
|
||||
import adminNotifikasi_funUpdateIsReadById from "../fun/update/fun_update_is_read_by_id";
|
||||
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../../_admin_global/admin_notifikasi/notifikasi_peringatan";
|
||||
import adminNotifikasi_countNotifikasi from "../fun/count/count_is_read";
|
||||
import { admin_funEventCheckStatus } from "../fun/get";
|
||||
import adminNotifikasi_getByUserId from "../fun/get/get_notifikasi_by_user_id";
|
||||
import adminNotifikasi_funUpdateIsReadById from "../fun/update/fun_update_is_read_by_id";
|
||||
import { IAdmin_ActiveChildId, IAdmin_ActivePage } from "./type_of_select_page";
|
||||
|
||||
export async function adminNotifikasi_findRouterEvent({
|
||||
data,
|
||||
|
||||
appId,
|
||||
notifikasiId,
|
||||
router,
|
||||
activePage,
|
||||
onLoadCountNotif,
|
||||
onLoadDataNotifikasi,
|
||||
onChangeNavbar,
|
||||
}: {
|
||||
data: MODEL_NOTIFIKASI;
|
||||
|
||||
appId: string;
|
||||
notifikasiId: string;
|
||||
router: AppRouterInstance;
|
||||
activePage: number;
|
||||
onLoadCountNotif: (val: any) => void;
|
||||
onLoadDataNotifikasi: (val: any) => void;
|
||||
onChangeNavbar: (val: {
|
||||
id: IAdmin_ActivePage;
|
||||
childId: IAdmin_ActiveChildId;
|
||||
}) => void;
|
||||
}) {
|
||||
const check = await admin_funEventCheckStatus({id: data.appId})
|
||||
const check = await admin_funEventCheckStatus({ id: appId });
|
||||
|
||||
if (check.status == 200) {
|
||||
const udpateReadNotifikasi = await adminNotifikasi_funUpdateIsReadById({
|
||||
notifId: data?.id,
|
||||
notifId: notifikasiId,
|
||||
});
|
||||
|
||||
if (udpateReadNotifikasi.status == 200) {
|
||||
return {
|
||||
success: true,
|
||||
statusName: check.statusName,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
statusName: "",
|
||||
};
|
||||
const loadCountNotif = await adminNotifikasi_countNotifikasi();
|
||||
onLoadCountNotif(loadCountNotif);
|
||||
|
||||
const loadListNotifikasi = await adminNotifikasi_getByUserId({
|
||||
page: 1,
|
||||
});
|
||||
onLoadDataNotifikasi(loadListNotifikasi);
|
||||
|
||||
const path = `/dev/admin/event/table/${check.statusName}`;
|
||||
|
||||
if (check.statusName == "draft") {
|
||||
ComponentAdminGlobal_NotifikasiPeringatan(
|
||||
"Status telah dirubah oleh user"
|
||||
);
|
||||
} else {
|
||||
if (check.statusName == "publish") {
|
||||
onChangeNavbar({
|
||||
id: "Event",
|
||||
childId: "Event_2",
|
||||
});
|
||||
}
|
||||
|
||||
if (check.statusName == "review") {
|
||||
onChangeNavbar({
|
||||
id: "Event",
|
||||
childId: "Event_3",
|
||||
});
|
||||
}
|
||||
|
||||
if (check.statusName == "reject") {
|
||||
onChangeNavbar({
|
||||
id: "Event",
|
||||
childId: "Event_4",
|
||||
});
|
||||
}
|
||||
|
||||
router.push(path, { scroll: false });
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
ComponentAdminGlobal_NotifikasiPeringatan("Status telah dirubah oleh user");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,31 +2,82 @@ import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
|
||||
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../../_admin_global/admin_notifikasi/notifikasi_peringatan";
|
||||
import { admin_funCheckStatusJob } from "../fun/get/fun_check_status_job";
|
||||
import adminNotifikasi_funUpdateIsReadById from "../fun/update/fun_update_is_read_by_id";
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
import adminNotifikasi_countNotifikasi from "../fun/count/count_is_read";
|
||||
import adminNotifikasi_getByUserId from "../fun/get/get_notifikasi_by_user_id";
|
||||
import { IAdmin_ActivePage, IAdmin_ActiveChildId } from "./type_of_select_page";
|
||||
|
||||
export async function adminNotifikasi_findRouterJob({
|
||||
data,
|
||||
appId,
|
||||
notifikasiId,
|
||||
router,
|
||||
activePage,
|
||||
onLoadCountNotif,
|
||||
onLoadDataNotifikasi,
|
||||
onChangeNavbar,
|
||||
}: {
|
||||
data: MODEL_NOTIFIKASI;
|
||||
appId: string;
|
||||
notifikasiId: string;
|
||||
router: AppRouterInstance;
|
||||
activePage: number;
|
||||
onLoadCountNotif: (val: any) => void;
|
||||
onLoadDataNotifikasi: (val: any) => void;
|
||||
onChangeNavbar: (val: {
|
||||
id: IAdmin_ActivePage;
|
||||
childId: IAdmin_ActiveChildId;
|
||||
}) => void;
|
||||
}) {
|
||||
const check = await admin_funCheckStatusJob({ id: data.appId });
|
||||
const check = await admin_funCheckStatusJob({ id: appId });
|
||||
|
||||
if (check.status == 200) {
|
||||
const udpateReadNotifikasi = await adminNotifikasi_funUpdateIsReadById({
|
||||
notifId: data?.id,
|
||||
notifId: notifikasiId,
|
||||
});
|
||||
|
||||
if (udpateReadNotifikasi.status == 200) {
|
||||
return {
|
||||
success: true,
|
||||
statusName: check.statusName,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
statusName: ""
|
||||
};
|
||||
const loadCountNotif = await adminNotifikasi_countNotifikasi();
|
||||
onLoadCountNotif(loadCountNotif);
|
||||
|
||||
const loadListNotifikasi = await adminNotifikasi_getByUserId({
|
||||
page: 1,
|
||||
});
|
||||
onLoadDataNotifikasi(loadListNotifikasi);
|
||||
|
||||
const path = `/dev/admin/job/child/${check.statusName}`;
|
||||
|
||||
if (check.statusName == "draft") {
|
||||
ComponentAdminGlobal_NotifikasiPeringatan(
|
||||
"Status telah dirubah oleh user"
|
||||
);
|
||||
} else {
|
||||
if (check.statusName == "publish") {
|
||||
onChangeNavbar({
|
||||
id: "Job",
|
||||
childId: "Job_2",
|
||||
});
|
||||
}
|
||||
|
||||
if (check.statusName == "review") {
|
||||
onChangeNavbar({
|
||||
id: "Job",
|
||||
childId: "Job_3",
|
||||
});
|
||||
}
|
||||
|
||||
if (check.statusName == "reject") {
|
||||
onChangeNavbar({
|
||||
id: "Job",
|
||||
childId: "Job_4",
|
||||
});
|
||||
}
|
||||
|
||||
router.push(path, { scroll: false });
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
ComponentAdminGlobal_NotifikasiPeringatan("Status telah dirubah oleh user");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export type IAdmin_ActivePage = "Investasi" | "Donasi" | "Event" | "Vote" | "Job" | "Forum" | "Collaboration"
|
||||
export type IAdmin_ActivePage = "Main" | "Investasi" | "Donasi" | "Event" | "Voting" | "Job" | "Forum" | "Collaboration"
|
||||
export type IAdmin_ActiveChildId =
|
||||
| "Investasi_1"
|
||||
| "Investasi_2"
|
||||
|
||||
@@ -1,27 +1,84 @@
|
||||
import { RouterAdminVote } from "@/app/lib/router_admin/router_admin_vote";
|
||||
import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
import { admin_funVotingCheckStatus } from "../fun/get/fun_voting_check_status";
|
||||
import adminNotifikasi_countNotifikasi from "../fun/count/count_is_read";
|
||||
import adminNotifikasi_getByUserId from "../fun/get/get_notifikasi_by_user_id";
|
||||
import adminNotifikasi_funUpdateIsReadById from "../fun/update/fun_update_is_read_by_id";
|
||||
import { IAdmin_ActiveChildId, IAdmin_ActivePage } from "./type_of_select_page";
|
||||
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../../_admin_global/admin_notifikasi/notifikasi_peringatan";
|
||||
|
||||
export async function adminNotifikasi_findRouterVoting({
|
||||
data,
|
||||
appId,
|
||||
notifikasiId,
|
||||
router,
|
||||
activePage,
|
||||
onLoadCountNotif,
|
||||
onLoadDataNotifikasi,
|
||||
onChangeNavbar,
|
||||
onToggleNavbar,
|
||||
}: {
|
||||
data: MODEL_NOTIFIKASI;
|
||||
appId: string;
|
||||
notifikasiId: string;
|
||||
router: AppRouterInstance;
|
||||
onChangeNavbar: (val: any) => void;
|
||||
onToggleNavbar: (val: any) => void;
|
||||
activePage: number;
|
||||
onLoadCountNotif: (val: any) => void;
|
||||
onLoadDataNotifikasi: (val: any) => void;
|
||||
onChangeNavbar: (val: {
|
||||
id: IAdmin_ActivePage;
|
||||
childId: IAdmin_ActiveChildId;
|
||||
}) => void;
|
||||
}) {
|
||||
const path = RouterAdminVote.table_review;
|
||||
const check = await admin_funVotingCheckStatus({ id: appId });
|
||||
|
||||
if (data.status === "Review") {
|
||||
router.push(path, { scroll: false });
|
||||
onChangeNavbar({
|
||||
id: 5,
|
||||
childId: 53,
|
||||
if (check.status == 200) {
|
||||
const updateReadNotifikasi = await adminNotifikasi_funUpdateIsReadById({
|
||||
notifId: notifikasiId,
|
||||
});
|
||||
}
|
||||
|
||||
onToggleNavbar(true);
|
||||
if (updateReadNotifikasi.status == 200) {
|
||||
const loadCountNotif = await adminNotifikasi_countNotifikasi();
|
||||
onLoadCountNotif(loadCountNotif);
|
||||
|
||||
const loadListNotifikasi = await adminNotifikasi_getByUserId({
|
||||
page: 1,
|
||||
});
|
||||
onLoadDataNotifikasi(loadListNotifikasi);
|
||||
|
||||
const path = `/dev/admin/vote/child/table_${check.statusName}`;
|
||||
|
||||
if (check.statusName == "draft") {
|
||||
ComponentAdminGlobal_NotifikasiPeringatan(
|
||||
"Status telah dirubah oleh user"
|
||||
);
|
||||
} else {
|
||||
if (check.statusName == "publish") {
|
||||
onChangeNavbar({
|
||||
id: "Voting",
|
||||
childId: "Voting_2",
|
||||
});
|
||||
}
|
||||
|
||||
if (check.statusName == "review") {
|
||||
onChangeNavbar({
|
||||
id: "Voting",
|
||||
childId: "Voting_3",
|
||||
});
|
||||
}
|
||||
|
||||
if (check.statusName == "reject") {
|
||||
onChangeNavbar({
|
||||
id: "Voting",
|
||||
childId: "Voting_4",
|
||||
});
|
||||
}
|
||||
|
||||
router.push(path, { scroll: false });
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
ComponentAdminGlobal_NotifikasiPeringatan("Status tidak ditemukan");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
import {
|
||||
gs_adminEventTriggerReview,
|
||||
gs_adminJobTriggerReview,
|
||||
} from "@/app/lib/global_state";
|
||||
import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
|
||||
import { Center, Loader, Paper, Text } from "@mantine/core";
|
||||
import { Box, Center, Loader, Paper, Stack, Text } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useAtom } from "jotai";
|
||||
import _ from "lodash";
|
||||
import { ScrollOnly } from "next-scroll-loader";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import adminNotifikasi_countNotifikasi from "./fun/count/count_is_read";
|
||||
import adminNotifikasi_getByUserId from "./fun/get/get_notifikasi_by_user_id";
|
||||
import { adminNotifikasi_findRouterEvent } from "./route_setting/event";
|
||||
import { adminNotifikasi_findRouterJob } from "./route_setting/job";
|
||||
import {
|
||||
IAdmin_ActiveChildId,
|
||||
IAdmin_ActivePage,
|
||||
@@ -67,42 +58,39 @@ export function ComponentAdmin_UIDrawerNotifikasi({
|
||||
return (
|
||||
<>
|
||||
<Paper h={"100%"}>
|
||||
<ScrollOnly
|
||||
height="90vh"
|
||||
renderLoading={() => (
|
||||
<Center mt={"lg"}>
|
||||
<Loader color={"yellow"} />
|
||||
</Center>
|
||||
)}
|
||||
data={data}
|
||||
setData={setData}
|
||||
moreData={async () => {
|
||||
const loadData = await adminNotifikasi_getByUserId({
|
||||
page: activePage + 1,
|
||||
});
|
||||
<Stack>
|
||||
{/* <Box bg={"red"}>apa ini</Box> */}
|
||||
<ScrollOnly
|
||||
height="90vh"
|
||||
renderLoading={() => (
|
||||
<Center mt={"lg"}>
|
||||
<Loader color={"yellow"} />
|
||||
</Center>
|
||||
)}
|
||||
data={data}
|
||||
setData={setData}
|
||||
moreData={async () => {
|
||||
const loadData = await adminNotifikasi_getByUserId({
|
||||
page: activePage + 1,
|
||||
});
|
||||
|
||||
setActivePage((val) => val + 1);
|
||||
setActivePage((val) => val + 1);
|
||||
|
||||
return loadData;
|
||||
}}
|
||||
>
|
||||
{(item) => (
|
||||
<AdminNotifikasi_ViewCardDrawer
|
||||
data={item}
|
||||
activePage={activePage}
|
||||
onChangeNavbar={(val) => onChangeNavbar(val)}
|
||||
onLoadCountNotif={(val) => onLoadCountNotif(val)}
|
||||
onToggleNavbar={(val) => onToggleNavbar(val)}
|
||||
onLoadDataNotifikasi={(val) => setData(val)}
|
||||
/>
|
||||
)}
|
||||
</ScrollOnly>
|
||||
|
||||
{/* <Stack>
|
||||
{data.map((e, i) => (
|
||||
|
||||
))}
|
||||
</Stack> */}
|
||||
return loadData;
|
||||
}}
|
||||
>
|
||||
{(item) => (
|
||||
<AdminNotifikasi_ViewCardDrawer
|
||||
data={item}
|
||||
activePage={activePage}
|
||||
onChangeNavbar={(val) => onChangeNavbar(val)}
|
||||
onLoadCountNotif={(val) => onLoadCountNotif(val)}
|
||||
onToggleNavbar={(val) => onToggleNavbar(val)}
|
||||
onLoadDataNotifikasi={(val) => setData(val)}
|
||||
/>
|
||||
)}
|
||||
</ScrollOnly>
|
||||
</Stack>
|
||||
</Paper>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
import {
|
||||
gs_adminJobTriggerReview,
|
||||
gs_adminEventTriggerReview,
|
||||
gs_adminEvent_triggerReview,
|
||||
gs_adminJob_triggerReview,
|
||||
gs_adminVoting_triggerReview,
|
||||
} from "@/app/lib/global_state";
|
||||
import { AccentColor } from "@/app_modules/_global/color";
|
||||
import { ComponentGlobal_CardLoadingOverlay } from "@/app_modules/_global/component";
|
||||
import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
|
||||
import { Card, Stack, Group, Badge, Divider, Text } from "@mantine/core";
|
||||
import { IconChecks, IconCheck } from "@tabler/icons-react";
|
||||
import { Badge, Card, Divider, Group, Stack, Text } from "@mantine/core";
|
||||
import { IconCheck, IconChecks } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../_admin_global/admin_notifikasi/notifikasi_peringatan";
|
||||
import adminNotifikasi_countNotifikasi from "./fun/count/count_is_read";
|
||||
import adminNotifikasi_getByUserId from "./fun/get/get_notifikasi_by_user_id";
|
||||
import { adminNotifikasi_findRouterEvent } from "./route_setting/event";
|
||||
import { adminNotifikasi_findRouterJob } from "./route_setting/job";
|
||||
import {
|
||||
IAdmin_ActivePage,
|
||||
IAdmin_ActiveChildId,
|
||||
IAdmin_ActivePage,
|
||||
} from "./route_setting/type_of_select_page";
|
||||
import { adminNotifikasi_findRouterVoting } from "./route_setting/voting";
|
||||
|
||||
export default function AdminNotifikasi_ViewCardDrawer({
|
||||
data,
|
||||
@@ -43,112 +46,113 @@ export default function AdminNotifikasi_ViewCardDrawer({
|
||||
|
||||
// Realtime
|
||||
const [isAdminJob_TriggerReview, setIsAdminJob_TriggerReview] = useAtom(
|
||||
gs_adminJobTriggerReview
|
||||
gs_adminJob_triggerReview
|
||||
);
|
||||
const [isAdminEvent_TriggerReview, setIsAdminEvent_TriggerReview] = useAtom(
|
||||
gs_adminEventTriggerReview
|
||||
gs_adminEvent_triggerReview
|
||||
);
|
||||
const [isAdminVoting_TriggerReview, setIsAdminVoting_TriggerReview] = useAtom(
|
||||
gs_adminVoting_triggerReview
|
||||
);
|
||||
|
||||
async function onRead({ data }: { data: MODEL_NOTIFIKASI }) {
|
||||
// JOB
|
||||
async function onRead() {
|
||||
// ========================== JOB ========================== //
|
||||
if (data?.kategoriApp === "JOB") {
|
||||
setVisible(true);
|
||||
setDataId(data.id);
|
||||
|
||||
const checkJob = await adminNotifikasi_findRouterJob({
|
||||
data: data,
|
||||
appId: data.appId,
|
||||
notifikasiId: data.id,
|
||||
router: router,
|
||||
activePage: activePage,
|
||||
onLoadCountNotif(val) {
|
||||
onLoadCountNotif(val);
|
||||
},
|
||||
onLoadDataNotifikasi(val) {
|
||||
onLoadDataNotifikasi(val);
|
||||
},
|
||||
onChangeNavbar(val) {
|
||||
onChangeNavbar({
|
||||
id: val.id,
|
||||
childId: val.childId,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
if (checkJob?.success) {
|
||||
setVisible(true);
|
||||
setDataId(data.id);
|
||||
|
||||
const loadCountNotif = await adminNotifikasi_countNotifikasi();
|
||||
onLoadCountNotif(loadCountNotif);
|
||||
|
||||
const loadListNotifikasi = await adminNotifikasi_getByUserId({
|
||||
page: activePage,
|
||||
});
|
||||
onLoadDataNotifikasi(loadListNotifikasi as any);
|
||||
|
||||
if (loadCountNotif && loadListNotifikasi) {
|
||||
const path = `/dev/admin/job/child/${checkJob.statusName}`;
|
||||
|
||||
if (checkJob.statusName == "publish") {
|
||||
onChangeNavbar({
|
||||
id: "Job",
|
||||
childId: "Job_2",
|
||||
});
|
||||
}
|
||||
|
||||
if (checkJob.statusName == "review") {
|
||||
onChangeNavbar({
|
||||
id: "Job",
|
||||
childId: "Job_3",
|
||||
});
|
||||
}
|
||||
|
||||
if (checkJob.statusName == "reject") {
|
||||
onChangeNavbar({
|
||||
id: "Job",
|
||||
childId: "Job_4",
|
||||
});
|
||||
}
|
||||
|
||||
setIsAdminJob_TriggerReview(false);
|
||||
router.push(path);
|
||||
setVisible(false);
|
||||
setDataId("");
|
||||
}
|
||||
if (checkJob) {
|
||||
setIsAdminJob_TriggerReview(false);
|
||||
setVisible(false);
|
||||
setDataId("");
|
||||
}
|
||||
}
|
||||
// ========================== JOB ========================== //
|
||||
|
||||
// ========================== EVENT ========================== //
|
||||
|
||||
// EVENT
|
||||
if (data.kategoriApp == "EVENT") {
|
||||
setVisible(true);
|
||||
setDataId(data.id);
|
||||
|
||||
const checkEvent = await adminNotifikasi_findRouterEvent({
|
||||
data: data,
|
||||
appId: data.appId,
|
||||
notifikasiId: data.id,
|
||||
router: router,
|
||||
activePage: activePage,
|
||||
onLoadCountNotif(val) {
|
||||
onLoadCountNotif(val);
|
||||
},
|
||||
onLoadDataNotifikasi(val) {
|
||||
onLoadDataNotifikasi(val);
|
||||
},
|
||||
onChangeNavbar(val) {
|
||||
onChangeNavbar({
|
||||
id: val.id,
|
||||
childId: val.childId,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
if (checkEvent?.success) {
|
||||
setVisible(true);
|
||||
setDataId(data.id);
|
||||
|
||||
const loadCountNotif = await adminNotifikasi_countNotifikasi();
|
||||
onLoadCountNotif(loadCountNotif);
|
||||
|
||||
const loadListNotifikasi = await adminNotifikasi_getByUserId({
|
||||
page: activePage,
|
||||
});
|
||||
onLoadDataNotifikasi(loadListNotifikasi as any);
|
||||
|
||||
if (loadCountNotif && loadListNotifikasi) {
|
||||
const path = `/dev/admin/event/table/${checkEvent.statusName}`;
|
||||
|
||||
if (checkEvent.statusName == "publish") {
|
||||
onChangeNavbar({
|
||||
id: "Event",
|
||||
childId: "Event_2",
|
||||
});
|
||||
}
|
||||
|
||||
if (checkEvent.statusName == "review") {
|
||||
onChangeNavbar({
|
||||
id: "Event",
|
||||
childId: "Event_3",
|
||||
});
|
||||
}
|
||||
|
||||
if (checkEvent.statusName == "reject") {
|
||||
onChangeNavbar({
|
||||
id: "Event",
|
||||
childId: "Event_4",
|
||||
});
|
||||
}
|
||||
|
||||
setIsAdminEvent_TriggerReview(false);
|
||||
router.push(path);
|
||||
setVisible(false);
|
||||
setDataId("");
|
||||
}
|
||||
if (checkEvent) {
|
||||
setIsAdminEvent_TriggerReview(false);
|
||||
setVisible(false);
|
||||
setDataId("");
|
||||
}
|
||||
}
|
||||
// ========================== EVENT ========================== //
|
||||
|
||||
// ========================== VOTING ========================== //
|
||||
|
||||
if (data.kategoriApp == "VOTING") {
|
||||
setVisible(true);
|
||||
setDataId(data.id);
|
||||
|
||||
const checkVoting = await adminNotifikasi_findRouterVoting({
|
||||
router: router,
|
||||
appId: data.appId,
|
||||
notifikasiId: data.id,
|
||||
activePage: activePage,
|
||||
onLoadCountNotif(val) {
|
||||
onLoadCountNotif(val);
|
||||
},
|
||||
onLoadDataNotifikasi(val) {
|
||||
onLoadDataNotifikasi(val);
|
||||
},
|
||||
onChangeNavbar(val) {
|
||||
onChangeNavbar({
|
||||
id: val.id,
|
||||
childId: val.childId,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
if (checkVoting) {
|
||||
setIsAdminVoting_TriggerReview(false);
|
||||
setVisible(false);
|
||||
setDataId("");
|
||||
}
|
||||
}
|
||||
// ========================== VOTING ========================== //
|
||||
|
||||
// // FORUM
|
||||
// e?.kategoriApp === "FORUM" &&
|
||||
@@ -213,7 +217,7 @@ export default function AdminNotifikasi_ViewCardDrawer({
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
}}
|
||||
mb={"md"}
|
||||
mb={"15px"}
|
||||
c={"white"}
|
||||
key={data.id}
|
||||
bg={data.isRead ? "gray" : AccentColor.darkblue}
|
||||
@@ -228,9 +232,8 @@ export default function AdminNotifikasi_ViewCardDrawer({
|
||||
borderWidth: "2px",
|
||||
},
|
||||
}}
|
||||
onClick={async () => {
|
||||
onRead({ data: data });
|
||||
// callBackIsNotifikasi(false);
|
||||
onClick={() => {
|
||||
onRead();
|
||||
}}
|
||||
>
|
||||
<Card.Section p={"sm"}>
|
||||
|
||||
@@ -6,28 +6,35 @@ import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useAtom } from "jotai";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { gs_admin_hotMenu } from "../global_state";
|
||||
import {
|
||||
gs_admin_navbar_menu,
|
||||
gs_admin_navbar_subMenu,
|
||||
} from "../_admin_global/new_global_state";
|
||||
import { IAdmin_ActivePage } from "../notifikasi/route_setting/type_of_select_page";
|
||||
|
||||
export default function SplashDashboardAdmin() {
|
||||
const router = useRouter();
|
||||
const [active, setActive] = useAtom(gs_admin_hotMenu);
|
||||
const [activeId, setActiveId] = useAtom(gs_admin_navbar_menu);
|
||||
const [activeChildId, setActiveChildId] = useAtom(gs_admin_navbar_subMenu);
|
||||
|
||||
useShallowEffect(() => {
|
||||
setTimeout(() => {
|
||||
router.push(RouterAdminDashboard.main_admin);
|
||||
setActive(1);
|
||||
setActiveId("Main");
|
||||
setActiveChildId("");
|
||||
}, 2000);
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<Center h={"100vh"}>
|
||||
<Stack spacing={0} >
|
||||
<Title>Welcome Admin</Title>
|
||||
<Center h={"100vh"}>
|
||||
<Stack spacing={0}>
|
||||
<Title>Welcome Admin</Title>
|
||||
|
||||
<AspectRatio ratio={1 / 1} mah={700} maw={700}>
|
||||
<Image src={"/aset/logo/logo-hipmi.png"} alt="Logo" />
|
||||
</AspectRatio>
|
||||
</Stack>
|
||||
</Center>
|
||||
<AspectRatio ratio={1 / 1} mah={700} maw={700}>
|
||||
<Image src={"/aset/logo/logo-hipmi.png"} alt="Logo" />
|
||||
</AspectRatio>
|
||||
</Stack>
|
||||
</Center>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate";
|
||||
import { MODEL_VOTING } from "@/app_modules/vote/model/interface";
|
||||
import {
|
||||
Affix,
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
@@ -10,6 +11,7 @@ import {
|
||||
Modal,
|
||||
Pagination,
|
||||
Paper,
|
||||
rem,
|
||||
ScrollArea,
|
||||
Spoiler,
|
||||
Stack,
|
||||
@@ -19,21 +21,31 @@ import {
|
||||
TextInput,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { IconBan, IconCircleCheck, IconSearch } from "@tabler/icons-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
|
||||
import {
|
||||
IconBan,
|
||||
IconCircleCheck,
|
||||
IconRefresh,
|
||||
IconSearch,
|
||||
} from "@tabler/icons-react";
|
||||
|
||||
import {
|
||||
gs_adminVoting_triggerReview,
|
||||
IRealtimeData,
|
||||
} from "@/app/lib/global_state";
|
||||
import { AccentColor } from "@/app_modules/_global/color";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
import adminNotifikasi_funCreateToUser from "@/app_modules/admin/notifikasi/fun/create/fun_create_notif_user";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import { useAtom } from "jotai";
|
||||
import moment from "moment";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import { adminVote_funGetListReview } from "../../fun";
|
||||
import { AdminVote_funEditStatusPublishById } from "../../fun/edit/fun_edit_status_publish_by_id";
|
||||
import { AdminEvent_funEditCatatanById } from "../../fun/edit/fun_edit_status_reject_by_id";
|
||||
import { AdminVote_getListTableByStatusId } from "../../fun/get/get_list_table_by_status_id";
|
||||
|
||||
export default function AdminVote_TableReview({
|
||||
listVote,
|
||||
@@ -51,18 +63,40 @@ export default function AdminVote_TableReview({
|
||||
}
|
||||
|
||||
function TableStatus({ listData }: { listData: any }) {
|
||||
const router = useRouter();
|
||||
const [opened, { open, close }] = useDisclosure(false);
|
||||
const [data, setData] = useState<MODEL_VOTING[]>(listData.data);
|
||||
const [isNPage, setNPage] = useState(listData.nPage);
|
||||
const [votingId, setVotingId] = useState("");
|
||||
const [catatan, setCatatan] = useState("");
|
||||
const [isLoadingPublish, setLoadingPublish] = useState(false);
|
||||
const [isSaveLoading, setSaveLoading] = useState(false);
|
||||
|
||||
const [isNPage, setNPage] = useState(listData.nPage);
|
||||
const [isActivePage, setActivePage] = useState(1);
|
||||
const [isSearch, setSearch] = useState("");
|
||||
|
||||
// Realtine
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isAdminVoting_TriggerReview, setIsAdminVoting_TriggerReview] = useAtom(
|
||||
gs_adminVoting_triggerReview
|
||||
);
|
||||
const [isShowReload, setIsShowReload] = useState(false);
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (isAdminVoting_TriggerReview) {
|
||||
setIsShowReload(true);
|
||||
}
|
||||
}, [isAdminVoting_TriggerReview, setIsShowReload]);
|
||||
|
||||
async function onLoadData() {
|
||||
const loadData = await adminVote_funGetListReview({ page: 1 });
|
||||
|
||||
setData(loadData.data as any);
|
||||
setNPage(loadData.nPage);
|
||||
setIsLoading(false);
|
||||
setIsShowReload(false);
|
||||
setIsAdminVoting_TriggerReview(false);
|
||||
}
|
||||
|
||||
async function onSearch(s: string) {
|
||||
setSearch(s);
|
||||
const loadData = await adminVote_funGetListReview({
|
||||
@@ -135,13 +169,16 @@ function TableStatus({ listData }: { listData: any }) {
|
||||
leftIcon={<IconCircleCheck />}
|
||||
radius={"xl"}
|
||||
onClick={() =>
|
||||
onPublish(
|
||||
e.id,
|
||||
setData,
|
||||
e.awalVote,
|
||||
setLoadingPublish,
|
||||
setVotingId
|
||||
)
|
||||
onPublish({
|
||||
voteId: e.id,
|
||||
awalVote: e.awalVote,
|
||||
setLoadingPublish: setLoadingPublish,
|
||||
setVotingId: setVotingId,
|
||||
setData(val) {
|
||||
setData(val.data);
|
||||
setNPage(val.nPage);
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
Publish
|
||||
@@ -185,6 +222,28 @@ function TableStatus({ listData }: { listData: any }) {
|
||||
</Group>
|
||||
|
||||
<Paper p={"md"} withBorder shadow="lg" h={"80vh"}>
|
||||
{isShowReload && (
|
||||
<Affix position={{ top: rem(200) }} w={"100%"}>
|
||||
<Center>
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
border: `1px solid ${AccentColor.skyblue}`,
|
||||
}}
|
||||
bg={AccentColor.blue}
|
||||
loaderPosition="center"
|
||||
loading={isLoading}
|
||||
radius={"xl"}
|
||||
opacity={0.8}
|
||||
onClick={() => onLoadData()}
|
||||
leftIcon={<IconRefresh />}
|
||||
>
|
||||
Update Data
|
||||
</Button>
|
||||
</Center>
|
||||
</Affix>
|
||||
)}
|
||||
|
||||
<ScrollArea w={"100%"} h={"90%"}>
|
||||
<Table
|
||||
verticalSpacing={"md"}
|
||||
@@ -264,7 +323,20 @@ function TableStatus({ listData }: { listData: any }) {
|
||||
loading={isSaveLoading ? true : false}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
onReject(votingId, setData, catatan, close, setSaveLoading);
|
||||
onReject({
|
||||
catatan: catatan,
|
||||
voteId: votingId,
|
||||
setData(val) {
|
||||
setData(val.data);
|
||||
setNPage(val.nPage);
|
||||
},
|
||||
close: () => {
|
||||
close();
|
||||
},
|
||||
setSaveLoading(val) {
|
||||
setSaveLoading(val);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
@@ -276,13 +348,19 @@ function TableStatus({ listData }: { listData: any }) {
|
||||
);
|
||||
}
|
||||
|
||||
async function onPublish(
|
||||
voteId: string,
|
||||
setData: any,
|
||||
awalVote: Date,
|
||||
setLoadingPublish: any,
|
||||
setVotingId: any
|
||||
) {
|
||||
async function onPublish({
|
||||
voteId,
|
||||
setData,
|
||||
awalVote,
|
||||
setLoadingPublish,
|
||||
setVotingId,
|
||||
}: {
|
||||
voteId: string;
|
||||
setData: (val: { data: any[]; nPage: number }) => void;
|
||||
awalVote: Date;
|
||||
setLoadingPublish: (val: boolean) => void;
|
||||
setVotingId: (val: string) => void;
|
||||
}) {
|
||||
const hariIni = new Date();
|
||||
const cekHari = moment(awalVote).diff(hariIni, "days");
|
||||
|
||||
@@ -292,8 +370,10 @@ async function onPublish(
|
||||
setVotingId(voteId);
|
||||
const res = await AdminVote_funEditStatusPublishById(voteId);
|
||||
if (res.status === 200) {
|
||||
const dataNotif = {
|
||||
appId: res.data?.id,
|
||||
setLoadingPublish(true);
|
||||
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as string,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
@@ -302,33 +382,48 @@ async function onPublish(
|
||||
};
|
||||
|
||||
const notif = await adminNotifikasi_funCreateToUser({
|
||||
data: dataNotif as any,
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"USER",
|
||||
JSON.stringify({ userId: res?.data?.authorId, count: 1 })
|
||||
);
|
||||
}
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
|
||||
await AdminVote_getListTableByStatusId("2").then((val) => {
|
||||
setData(val);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setLoadingPublish(true);
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
}
|
||||
const loadData = await adminVote_funGetListReview({ page: 1 });
|
||||
setData({
|
||||
data: loadData.data,
|
||||
nPage: loadData.nPage,
|
||||
});
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setLoadingPublish(false);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function onReject(
|
||||
voteId: string,
|
||||
setData: any,
|
||||
catatan: string,
|
||||
close: any,
|
||||
setSaveLoading: any
|
||||
) {
|
||||
async function onReject({
|
||||
voteId,
|
||||
catatan,
|
||||
close,
|
||||
setSaveLoading,
|
||||
setData,
|
||||
}: {
|
||||
voteId: string;
|
||||
catatan: string;
|
||||
close: any;
|
||||
setSaveLoading: (val: boolean) => void;
|
||||
setData: (val: { data: any[]; nPage: number }) => void;
|
||||
}) {
|
||||
const data = {
|
||||
id: voteId,
|
||||
catatan: catatan,
|
||||
@@ -337,8 +432,17 @@ async function onReject(
|
||||
const res = await AdminEvent_funEditCatatanById(data as any);
|
||||
if (res.status === 200) {
|
||||
setSaveLoading(true);
|
||||
const dataNotif = {
|
||||
appId: res.data?.id,
|
||||
// const dataNotif = {
|
||||
// appId: res.data?.id,
|
||||
// status: res.data?.Voting_Status?.name as any,
|
||||
// userId: res.data?.authorId as any,
|
||||
// pesan: res.data?.title as any,
|
||||
// kategoriApp: "VOTING",
|
||||
// title: "Voting anda di tolak !",
|
||||
// };
|
||||
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as string,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
@@ -347,22 +451,25 @@ async function onReject(
|
||||
};
|
||||
|
||||
const notif = await adminNotifikasi_funCreateToUser({
|
||||
data: dataNotif as any,
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"USER",
|
||||
JSON.stringify({ userId: res?.data?.authorId, count: 1 })
|
||||
);
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
}
|
||||
|
||||
await AdminVote_getListTableByStatusId("2").then((val) => {
|
||||
setData(val);
|
||||
setSaveLoading(false);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
close();
|
||||
const loadData = await adminVote_funGetListReview({ page: 1 });
|
||||
setData({
|
||||
data: loadData.data,
|
||||
nPage: loadData.nPage,
|
||||
});
|
||||
setSaveLoading(false);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
close();
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
"use client";
|
||||
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import notifikasiToUser_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_user";
|
||||
import { Button, Stack } from "@mantine/core";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import ComponentEvent_DetailMainData from "../../component/detail/detail_main";
|
||||
import ComponentEvent_ListPeserta from "../../component/detail/list_peserta";
|
||||
import { Event_countTotalPesertaById } from "../../fun/count/count_total_peserta_by_id";
|
||||
import { Event_funJoinEvent } from "../../fun/create/fun_join_event";
|
||||
import { Event_getListPesertaById } from "../../fun/get/get_list_peserta_by_id";
|
||||
import { MODEL_EVENT, MODEL_EVENT_PESERTA } from "../../model/interface";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import notifikasiToUser_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_user";
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
|
||||
export default function Event_DetailMain({
|
||||
dataEvent,
|
||||
@@ -84,42 +83,35 @@ async function onJoin(
|
||||
|
||||
const res = await Event_funJoinEvent(body as any);
|
||||
if (res.status === 200) {
|
||||
// const dataNotif = {
|
||||
// appId: res?.data?.Event?.id,
|
||||
// userId: res?.data?.Event?.authorId,
|
||||
// pesan: res?.data?.Event?.title,
|
||||
// status: "Peserta Event",
|
||||
// kategoriApp: "EVENT",
|
||||
// title: "Peserta baru telah masuk !",
|
||||
// };
|
||||
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res?.data?.Event?.id as any,
|
||||
status: "Peserta Event" as any,
|
||||
userId: res.data?.Event?.authorId as any,
|
||||
pesan: res.data?.Event?.title as any,
|
||||
kategoriApp: "EVENT",
|
||||
title: "Peserta baru event anda !",
|
||||
};
|
||||
|
||||
const createNotifikasi = await notifikasiToUser_funCreate({
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (createNotifikasi.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
const resPeserta = await Event_getListPesertaById(eventId);
|
||||
setPeserta(resPeserta);
|
||||
|
||||
const resTotal = await Event_countTotalPesertaById(eventId);
|
||||
setTotal(resTotal);
|
||||
|
||||
if (userLoginId !== res.data?.Event?.authorId) {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res?.data?.Event?.id as any,
|
||||
status: "Peserta Event" as any,
|
||||
userId: res.data?.Event?.authorId as any,
|
||||
pesan: res.data?.Event?.title as any,
|
||||
kategoriApp: "EVENT",
|
||||
title: "Peserta baru event anda !",
|
||||
};
|
||||
|
||||
const createNotifikasi = await notifikasiToUser_funCreate({
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (createNotifikasi.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
} else {
|
||||
|
||||
@@ -16,6 +16,8 @@ import { useState } from "react";
|
||||
import { MODEL_NOTIFIKASI } from "../model/interface";
|
||||
import { notifikasi_eventCheckStatus } from "./path/event";
|
||||
import { notifikasi_jobCheckStatus } from "./path/job";
|
||||
import { gs_vote_hotMenu } from "@/app_modules/vote/global_state";
|
||||
import { notifikasi_votingCheckStatus } from "./path/voting";
|
||||
|
||||
export function ComponentNotifiaksi_CardView({
|
||||
data,
|
||||
@@ -32,6 +34,7 @@ export function ComponentNotifiaksi_CardView({
|
||||
|
||||
const [jobMenuId, setJobMenuId] = useAtom(gs_job_hot_menu);
|
||||
const [eventMenuId, setEventMenuId] = useAtom(gs_event_hotMenu);
|
||||
const [votingMenu, setVotingMenu] = useAtom(gs_vote_hotMenu);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -92,6 +95,27 @@ export function ComponentNotifiaksi_CardView({
|
||||
});
|
||||
}
|
||||
|
||||
if (data?.kategoriApp === "VOTING") {
|
||||
await notifikasi_votingCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetEventMenuId(val) {
|
||||
setVotingMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// data?.kategoriApp === "FORUM" &&
|
||||
// redirectDetailForumPage({
|
||||
// data: data,
|
||||
|
||||
@@ -1,36 +1,57 @@
|
||||
import { RouterVote } from "@/app/lib/router_hipmi/router_vote";
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
import { MODEL_NOTIFIKASI } from "../../model/interface";
|
||||
import { notifikasi_funVotingCheckStatus } from "../../fun/check/fun_check_voting_status";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
import notifikasi_countUserNotifikasi from "../../fun/count/fun_count_by_id";
|
||||
import notifikasi_getByUserId from "../../fun/get/get_notifiaksi_by_id";
|
||||
import notifikasi_funUpdateIsReadById from "../../fun/update/fun_update_is_read_by_user_id";
|
||||
|
||||
export function redirectVotingPage({
|
||||
data,
|
||||
export async function notifikasi_votingCheckStatus({
|
||||
appId,
|
||||
dataId,
|
||||
categoryPage,
|
||||
router,
|
||||
onSetPage,
|
||||
onLoadDataEvent,
|
||||
onSetEventMenuId,
|
||||
onSetVisible,
|
||||
onLoadCountNtf,
|
||||
}: {
|
||||
data: MODEL_NOTIFIKASI;
|
||||
appId: string;
|
||||
dataId: string;
|
||||
categoryPage: string;
|
||||
router: AppRouterInstance;
|
||||
onSetPage: (val: any) => void;
|
||||
onLoadDataEvent: (val: any) => void;
|
||||
onSetEventMenuId(val: number): void;
|
||||
onSetVisible(val: boolean): void;
|
||||
onLoadCountNtf(val: number): void;
|
||||
}) {
|
||||
const path = RouterVote.status({ id: "" });
|
||||
const check = await notifikasi_funVotingCheckStatus({ id: appId });
|
||||
|
||||
if (data.status === "Publish") {
|
||||
onSetPage({
|
||||
menuId: 2,
|
||||
status: data.status,
|
||||
if (check.status == 200) {
|
||||
const loadListNotifikasi = await notifikasi_getByUserId({
|
||||
page: 1,
|
||||
kategoriApp: categoryPage as any,
|
||||
});
|
||||
router.push(path, { scroll: false });
|
||||
}
|
||||
// console.log(data)
|
||||
onLoadDataEvent(loadListNotifikasi);
|
||||
|
||||
if (data.status === "Reject") {
|
||||
onSetPage({
|
||||
menuId: 2,
|
||||
status: data.status,
|
||||
const loadCountNotifikasi = await notifikasi_countUserNotifikasi();
|
||||
onLoadCountNtf(loadCountNotifikasi);
|
||||
|
||||
const updateReadNotifikasi = await notifikasi_funUpdateIsReadById({
|
||||
notifId: dataId,
|
||||
});
|
||||
router.push(path, { scroll: false });
|
||||
|
||||
if (updateReadNotifikasi.status == 200) {
|
||||
onSetVisible(true);
|
||||
|
||||
const path = `/dev/vote/detail/${check.statusName}/${appId}`;
|
||||
onSetEventMenuId(1);
|
||||
router.push(path, { scroll: false });
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan("Status tidak ditemukan");
|
||||
}
|
||||
|
||||
if (data.status === "Voting Masuk") {
|
||||
router.push(RouterVote.main_detail + data.appId, { scroll: false });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import _ from "lodash";
|
||||
|
||||
export async function notifikasi_funVotingCheckStatus({ id }: { id: string }) {
|
||||
const data = await prisma.voting.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
Voting_Status: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!data)
|
||||
return { status: 400, message: "Job tidak ditemukan", statusName: "" };
|
||||
return {
|
||||
status: 200,
|
||||
message: "Berhasil di cek",
|
||||
statusName: _.lowerCase(data.Voting_Status?.name),
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { RouterVote } from "@/app/lib/router_hipmi/router_vote";
|
||||
import { MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown";
|
||||
@@ -7,7 +8,6 @@ import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -23,12 +23,11 @@ import { IconMinus, IconPlus } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import { Vote_funCreate } from "../fun/create/create_vote";
|
||||
import { gs_vote_hotMenu } from "../global_state";
|
||||
import { MODEL_VOTING } from "../model/interface";
|
||||
|
||||
export default function Vote_Create() {
|
||||
const router = useRouter();
|
||||
@@ -53,6 +52,60 @@ export default function Vote_Create() {
|
||||
},
|
||||
]);
|
||||
|
||||
async function onSave() {
|
||||
if (_.values(data).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||
|
||||
const cekAwalVote = moment(data.awalVote).format();
|
||||
if (cekAwalVote === "Invalid date")
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Tanggal");
|
||||
|
||||
const cekAkhirVote = moment(data.akhirVote).format();
|
||||
if (cekAkhirVote === "Invalid date")
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Tanggal");
|
||||
|
||||
if (_.values(listVote.map((e) => e.value)).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Pilihan Voting");
|
||||
|
||||
// console.log("berhasil");
|
||||
|
||||
const res = await Vote_funCreate(data as any, listVote);
|
||||
if (res.status === 201) {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "VOTING",
|
||||
title: "Voting baru",
|
||||
};
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "ADMIN",
|
||||
});
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "ADMIN",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
|
||||
setHotMenu(2);
|
||||
router.replace(RouterVote.status({ id: "2" }));
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setIsLoading(true);
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack px={"sm"} spacing={"xl"} mb={"xl"}>
|
||||
@@ -208,7 +261,7 @@ export default function Vote_Create() {
|
||||
mt={"lg"}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
onSave(router, setHotMenu, data as any, listVote, setIsLoading);
|
||||
onSave();
|
||||
}}
|
||||
c={"black"}
|
||||
bg={MainColor.yellow}
|
||||
@@ -223,59 +276,3 @@ export default function Vote_Create() {
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
async function onSave(
|
||||
router: AppRouterInstance,
|
||||
setHotMenu: any,
|
||||
data: MODEL_VOTING,
|
||||
listVote: any[],
|
||||
setIsLoading: any
|
||||
) {
|
||||
if (_.values(data).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||
|
||||
const cekAwalVote = moment(data.awalVote).format();
|
||||
if (cekAwalVote === "Invalid date")
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Tanggal");
|
||||
|
||||
const cekAkhirVote = moment(data.akhirVote).format();
|
||||
if (cekAkhirVote === "Invalid date")
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Tanggal");
|
||||
|
||||
if (_.values(listVote.map((e) => e.value)).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Pilihan Voting");
|
||||
|
||||
// console.log("berhasil");
|
||||
|
||||
const res = await Vote_funCreate(data, listVote);
|
||||
if (res.status === 201) {
|
||||
const dataNotif: any = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "VOTING",
|
||||
title: "Voting baru",
|
||||
};
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"ADMIN",
|
||||
JSON.stringify({
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
|
||||
setHotMenu(2);
|
||||
router.replace(RouterVote.status({ id: "2" }));
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setIsLoading(true);
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,11 @@ import ComponentVote_DetailDataSebelumPublish from "../../component/detail/detai
|
||||
import { Vote_funDeleteById } from "../../fun/delete/fun_delete_by_id";
|
||||
import { Vote_funEditStatusByStatusId } from "../../fun/edit/fun_edit_status_by_id";
|
||||
import { MODEL_VOTING } from "../../model/interface";
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { voting_funGetOneVotingbyId } from "../../fun/get/fun_get_one_by_id";
|
||||
import _ from "lodash";
|
||||
|
||||
export default function Vote_DetailDraft({
|
||||
dataVote,
|
||||
@@ -24,13 +29,21 @@ export default function Vote_DetailDraft({
|
||||
dataVote: MODEL_VOTING;
|
||||
}) {
|
||||
const [data, setData] = useState(dataVote);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoadData(setData);
|
||||
}, [setData]);
|
||||
|
||||
async function onLoadData(setData: any) {
|
||||
const loadData = await voting_funGetOneVotingbyId(dataVote.id);
|
||||
setData(loadData);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack spacing={"xl"}>
|
||||
{dataVote?.catatan ? (
|
||||
{dataVote?.catatan && (
|
||||
<ComponentGlobal_BoxInformation isReport informasi={data?.catatan} />
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
<ComponentVote_DetailDataSebelumPublish data={data} />
|
||||
<ButtonAction voteId={data.id} awalVote={data.awalVote} />
|
||||
@@ -60,7 +73,7 @@ function ButtonAction({
|
||||
|
||||
const res = await Vote_funEditStatusByStatusId(voteId, "2");
|
||||
if (res.status === 200) {
|
||||
const dataNotif: any = {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
@@ -70,16 +83,20 @@ function ButtonAction({
|
||||
};
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"ADMIN",
|
||||
JSON.stringify({
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "ADMIN",
|
||||
});
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "ADMIN",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil("Berhasil Ajukan Review", 2000);
|
||||
setIsLoading(true);
|
||||
|
||||
@@ -4,7 +4,10 @@ import {
|
||||
AccentColor,
|
||||
MainColor,
|
||||
} from "@/app_modules/_global/color/color_pallet";
|
||||
import { ComponentGlobal_AvatarAndUsername, ComponentGlobal_CardStyles } from "@/app_modules/_global/component";
|
||||
import {
|
||||
ComponentGlobal_AvatarAndUsername,
|
||||
ComponentGlobal_CardStyles,
|
||||
} from "@/app_modules/_global/component";
|
||||
import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
@@ -19,7 +22,7 @@ import {
|
||||
Radio,
|
||||
Stack,
|
||||
Text,
|
||||
Title
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
@@ -28,6 +31,8 @@ import ComponentVote_HasilVoting from "../../component/detail/detail_hasil_votin
|
||||
import { Vote_funCreateHasil } from "../../fun/create/create_hasil";
|
||||
import { voting_funGetOneVotingbyId } from "../../fun/get/fun_get_one_by_id";
|
||||
import { MODEL_VOTING } from "../../model/interface";
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
|
||||
export default function Vote_MainDetail({
|
||||
dataVote,
|
||||
@@ -88,7 +93,9 @@ function TampilanDataVoting({
|
||||
<>
|
||||
<ComponentGlobal_CardStyles>
|
||||
<Stack>
|
||||
<ComponentGlobal_AvatarAndUsername profile={dataVote?.Author?.Profile as any}/>
|
||||
<ComponentGlobal_AvatarAndUsername
|
||||
profile={dataVote?.Author?.Profile as any}
|
||||
/>
|
||||
{/* <ComponentGlobal_AuthorNameOnHeader
|
||||
authorName={dataVote?.Author.Profile.name}
|
||||
imagesId={dataVote?.Author.Profile.imagesId}
|
||||
@@ -218,7 +225,6 @@ function TampilanDataVoting({
|
||||
</Stack>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
</ComponentGlobal_CardStyles>
|
||||
</>
|
||||
);
|
||||
@@ -238,27 +244,25 @@ async function onVote(
|
||||
});
|
||||
|
||||
if (userLoginId !== res?.data?.Voting?.authorId) {
|
||||
const dataNotif = {
|
||||
appId: res?.data?.Voting?.id,
|
||||
userId: res?.data?.Voting?.authorId,
|
||||
pesan: res?.pilihan,
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res?.data?.Voting?.id as string,
|
||||
userId: res?.data?.Voting?.authorId as string,
|
||||
pesan: res?.pilihan as string,
|
||||
status: "Voting Masuk",
|
||||
kategoriApp: "VOTING",
|
||||
title: "User lain telah melakukan voting !",
|
||||
};
|
||||
|
||||
const createNotifikasi = await notifikasiToUser_funCreate({
|
||||
data: dataNotif as any,
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (createNotifikasi.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"USER",
|
||||
JSON.stringify({
|
||||
userId: dataNotif.userId,
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { RouterVote } from "@/app/lib/router_hipmi/router_vote";
|
||||
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/ui_modal";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import { Button, Stack } from "@mantine/core";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import ComponentVote_DetailDataSebelumPublish from "../../component/detail/detail_data_sebelum_publish";
|
||||
import { Vote_funEditStatusByStatusId } from "../../fun/edit/fun_edit_status_by_id";
|
||||
import { MODEL_VOTING } from "../../model/interface";
|
||||
import { voting_checkStatus } from "../../fun";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
|
||||
export default function Vote_DetailReview({
|
||||
dataVote,
|
||||
@@ -22,47 +25,65 @@ export default function Vote_DetailReview({
|
||||
<>
|
||||
<Stack spacing={"xl"}>
|
||||
<ComponentVote_DetailDataSebelumPublish data={dataVote as any} />
|
||||
<ButtonAction voteId={dataVote.id} />
|
||||
<ButtonAction
|
||||
voteId={dataVote.id}
|
||||
statusId={dataVote.voting_StatusId}
|
||||
/>
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ButtonAction({ voteId }: { voteId: string }) {
|
||||
function ButtonAction({
|
||||
voteId,
|
||||
statusId,
|
||||
}: {
|
||||
voteId: string;
|
||||
statusId: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
|
||||
async function onUpdate() {
|
||||
const res = await Vote_funEditStatusByStatusId(voteId, "3");
|
||||
if (res.status === 200) {
|
||||
const dataNotif: any = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "VOTING",
|
||||
title: "Membatalkan review",
|
||||
};
|
||||
const check = await voting_checkStatus({ id: voteId });
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
if (check) {
|
||||
const res = await Vote_funEditStatusByStatusId(voteId, "3");
|
||||
if (res.status === 200) {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "VOTING",
|
||||
title: "Membatalkan review",
|
||||
};
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"ADMIN",
|
||||
JSON.stringify({
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "ADMIN",
|
||||
});
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "ADMIN",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
}
|
||||
ComponentGlobal_NotifikasiBerhasil("Berhasil Batalkan Review", 2000);
|
||||
router.replace(RouterVote.status({ id: "3" }));
|
||||
setIsLoading(true);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
ComponentGlobal_NotifikasiPeringatan("Voting telah di terima admin");
|
||||
}
|
||||
}
|
||||
return (
|
||||
@@ -92,7 +113,10 @@ function ButtonAction({ voteId }: { voteId: string }) {
|
||||
loading={isLoading ? true : false}
|
||||
radius={"xl"}
|
||||
color="green"
|
||||
onClick={() => onUpdate()}
|
||||
onClick={() => {
|
||||
onUpdate();
|
||||
console.log(statusId);
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import ComponentGlobal_ErrorInput from "@/app_modules/_global/component/error_input";
|
||||
import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
@@ -9,14 +10,14 @@ import {
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
Grid,
|
||||
Group,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
Textarea,
|
||||
Textarea
|
||||
} from "@mantine/core";
|
||||
import { DatePickerInput } from "@mantine/dates";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { IconPlus, IconTrash } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
import _ from "lodash";
|
||||
@@ -24,14 +25,12 @@ import moment from "moment";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { Vote_funEditById } from "../fun/edit/fun_edit_by_id";
|
||||
import { Vote_getListDaftarNamaById } from "../fun/get/get_list_daftar_vote_by_id";
|
||||
import { gs_vote_hotMenu, gs_vote_status } from "../global_state";
|
||||
import {
|
||||
MODEL_VOTING,
|
||||
MODEL_VOTING_DAFTAR_NAMA_VOTE,
|
||||
} from "../model/interface";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { Vote_getListDaftarNamaById } from "../fun/get/get_list_daftar_vote_by_id";
|
||||
import { MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||
|
||||
export default function Vote_Edit({
|
||||
dataVote,
|
||||
|
||||
@@ -7,6 +7,17 @@ export async function Vote_funEditStatusByStatusId(
|
||||
voteId: string,
|
||||
statusId: string
|
||||
) {
|
||||
// if (statusId !== "2") {
|
||||
// const checkStatus = await prisma.voting.findFirst({
|
||||
// where: {
|
||||
// id: voteId,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (checkStatus?.voting_StatusId != "2")
|
||||
// return { status: 400, message: "Status sudah diubah admin" };
|
||||
// }
|
||||
|
||||
const updt = await prisma.voting.update({
|
||||
where: {
|
||||
id: voteId,
|
||||
|
||||
21
src/app_modules/vote/fun/get/fun_check_status.ts
Normal file
21
src/app_modules/vote/fun/get/fun_check_status.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
|
||||
export async function voting_checkStatus({
|
||||
id,
|
||||
}: {
|
||||
id: string;
|
||||
}) {
|
||||
const checkStatus = await prisma.voting.findFirst({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
if(checkStatus?.voting_StatusId == "2") return true
|
||||
return false
|
||||
|
||||
// if (checkStatus?.voting_StatusId == "2") return true;
|
||||
// return false;
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { voting_funUpdateIsArsipById } from "./edit/fun_update_is_arsip_by_id";
|
||||
import { voting_checkStatus } from "./get/fun_check_status";
|
||||
import { voting_getMasterStatus } from "./get/get_list_status_voting";
|
||||
import { vote_funGetAllByStatusId } from "./get/status/get_all_by_status_id";
|
||||
|
||||
export { voting_funUpdateIsArsipById };
|
||||
export { vote_funGetAllByStatusId };
|
||||
export { voting_getMasterStatus };
|
||||
export { voting_checkStatus };
|
||||
|
||||
@@ -3,7 +3,16 @@
|
||||
import { RouterVote } from "@/app/lib/router_hipmi/router_vote";
|
||||
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
|
||||
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
||||
import { Box, Center, Loader, Stack, TextInput } from "@mantine/core";
|
||||
import {
|
||||
Affix,
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
Loader,
|
||||
rem,
|
||||
Stack,
|
||||
TextInput,
|
||||
} from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import _ from "lodash";
|
||||
import { ScrollOnly } from "next-scroll-loader";
|
||||
@@ -11,6 +20,9 @@ import { useState } from "react";
|
||||
import ComponentVote_CardViewPublish from "../component/card_view_publish";
|
||||
import { vote_getAllListPublish } from "../fun/get/get_all_list_publish";
|
||||
import { MODEL_VOTING } from "../model/interface";
|
||||
import { gs_votingTiggerBeranda } from "@/app/lib/global_state";
|
||||
import { useAtom } from "jotai";
|
||||
import { AccentColor } from "@/app_modules/_global/color";
|
||||
|
||||
export default function Vote_Beranda({
|
||||
dataVote,
|
||||
@@ -20,13 +32,27 @@ export default function Vote_Beranda({
|
||||
const [data, setData] = useState(dataVote);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
|
||||
// Realtime
|
||||
const [isTriggerVotingBeranda, setIsTriggerVotingBeranda] = useAtom(
|
||||
gs_votingTiggerBeranda
|
||||
);
|
||||
const [isShowUpdate, setIsShowUpdate] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (isTriggerVotingBeranda) {
|
||||
setIsShowUpdate(true);
|
||||
}
|
||||
}, [isTriggerVotingBeranda, setIsShowUpdate]);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoad({
|
||||
newData(val) {
|
||||
setData(val);
|
||||
},
|
||||
});
|
||||
}, [setData]);
|
||||
setIsTriggerVotingBeranda(false);
|
||||
}, [setData, setIsTriggerVotingBeranda]);
|
||||
|
||||
async function onLoad({ newData }: { newData: (val: any) => void }) {
|
||||
const loadData = await vote_getAllListPublish({ page: 1 });
|
||||
@@ -38,8 +64,45 @@ export default function Vote_Beranda({
|
||||
setData(loadSearch as any);
|
||||
}
|
||||
|
||||
async function onLoadData({ onPublish }: { onPublish: (val: any) => void }) {
|
||||
setIsLoading(true);
|
||||
const loadData = await vote_getAllListPublish({ page: 1 });
|
||||
onPublish(loadData);
|
||||
|
||||
setIsShowUpdate(false);
|
||||
setIsTriggerVotingBeranda(false);
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<Stack mt={"1vh"}>
|
||||
{isShowUpdate && (
|
||||
<Affix position={{ top: rem(100) }} w={"100%"}>
|
||||
<Center>
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
border: `1px solid ${AccentColor.skyblue}`,
|
||||
}}
|
||||
bg={AccentColor.blue}
|
||||
loaderPosition="center"
|
||||
loading={isLoading}
|
||||
radius={"xl"}
|
||||
opacity={0.8}
|
||||
onClick={() => {
|
||||
onLoadData({
|
||||
onPublish(val) {
|
||||
setData(val);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
Update beranda
|
||||
</Button>
|
||||
</Center>
|
||||
</Affix>
|
||||
)}
|
||||
|
||||
<TextInput
|
||||
radius={"xl"}
|
||||
placeholder="Masukan judul voting"
|
||||
|
||||
@@ -14,6 +14,7 @@ export interface MODEL_VOTING {
|
||||
Author: MODEL_USER;
|
||||
Voting_DaftarNamaVote: MODEL_VOTING_DAFTAR_NAMA_VOTE[];
|
||||
isArsip: boolean;
|
||||
voting_StatusId: string
|
||||
}
|
||||
|
||||
export interface MODEL_VOTING_DAFTAR_NAMA_VOTE {
|
||||
|
||||
@@ -16,16 +16,16 @@ export function CobaRealtime({ userLoginId }: { userLoginId: string }) {
|
||||
// });
|
||||
|
||||
|
||||
useShallowEffect(() => {
|
||||
WibuRealtime.init({
|
||||
onData: (data) => {
|
||||
// useShallowEffect(() => {
|
||||
// WibuRealtime.init({
|
||||
// onData: (data) => {
|
||||
|
||||
console.log(data)
|
||||
},
|
||||
project: "hipmi",
|
||||
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
|
||||
});
|
||||
}, []);
|
||||
// console.log(data)
|
||||
// },
|
||||
// project: "hipmi",
|
||||
// WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
|
||||
// });
|
||||
// }, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -4,11 +4,12 @@ import { ActionIcon, Box, Button, Stack, Title } from "@mantine/core";
|
||||
import { useState } from "react";
|
||||
|
||||
import { IconPencilPlus } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import _, { random } from "lodash";
|
||||
import UIGlobal_LayoutTamplate from "../_global/ui/ui_layout_tamplate";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { WibuRealtime } from "wibu";
|
||||
import { v4 } from "uuid";
|
||||
import { UIGlobal_LayoutHeaderTamplate } from "../_global/ui";
|
||||
|
||||
const newData = Array(20)
|
||||
.fill(0)
|
||||
@@ -37,46 +38,46 @@ export default function Coba_TestLoading({
|
||||
}: {
|
||||
userLoginId: string;
|
||||
}) {
|
||||
// const [data, setData] = useState(data2);
|
||||
const [data, setData] = useState(data2);
|
||||
const [openDrawer, setOpenDrawer] = useState(false);
|
||||
const [newData, setNewData] = useState({});
|
||||
|
||||
useShallowEffect(() => {
|
||||
WibuRealtime.init({
|
||||
WIBU_REALTIME_TOKEN: process.env.WIBU_REALTIME_KEY as any,
|
||||
project: "hipmi",
|
||||
onData(data) {
|
||||
console.log(data);
|
||||
},
|
||||
});
|
||||
// useShallowEffect(() => {
|
||||
// WibuRealtime.init({
|
||||
// WIBU_REALTIME_TOKEN: process.env.WIBU_REALTIME_KEY as any,
|
||||
// project: "hipmi",
|
||||
// onData(data) {
|
||||
// console.log(data);
|
||||
// },
|
||||
// });
|
||||
|
||||
return () => {
|
||||
WibuRealtime.cleanup();
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack w={200} p={"lg"}>
|
||||
<Title>User {userLoginId}</Title>
|
||||
<Button
|
||||
onClick={() => {
|
||||
WibuRealtime.setData({
|
||||
id: v4(),
|
||||
userId: userLoginId,
|
||||
data: `Ini dari user ${userLoginId}`,
|
||||
});
|
||||
}}
|
||||
>
|
||||
Cek
|
||||
</Button>
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
// return () => {
|
||||
// WibuRealtime.cleanup();
|
||||
// };
|
||||
// }, []);
|
||||
|
||||
// return (
|
||||
// <>
|
||||
// <UIGlobal_LayoutTamplate>
|
||||
// <Stack w={200} p={"lg"}>
|
||||
// <Title>User {userLoginId}</Title>
|
||||
// <Button
|
||||
// onClick={() => {
|
||||
// WibuRealtime.setData({
|
||||
// id: v4(),
|
||||
// userId: userLoginId,
|
||||
// data: `Ini dari user ${userLoginId}`,
|
||||
// });
|
||||
// }}
|
||||
// >
|
||||
// Cek
|
||||
// </Button>
|
||||
// </Stack>
|
||||
// </>
|
||||
// );
|
||||
|
||||
// return (
|
||||
// <>
|
||||
// <UIGlobal_LayoutTamplate header={<UIGlobal_LayoutHeaderTamplate title="Coba" />}>
|
||||
// {/* <CreateButton /> */}
|
||||
// <Button onClick={() => setOpenDrawer(true)}>Click</Button>
|
||||
// </UIGlobal_LayoutTamplate>
|
||||
@@ -84,32 +85,32 @@ export default function Coba_TestLoading({
|
||||
// );
|
||||
|
||||
// Clone data
|
||||
// return (
|
||||
// <>
|
||||
// <Box mt={"lg"}>
|
||||
// <Stack>
|
||||
// <Button
|
||||
// onClick={() => {
|
||||
// const clone = _.clone(data);
|
||||
// const dataBaru = clone.map(
|
||||
// (e) => (
|
||||
// e.id === 1,
|
||||
// {
|
||||
// ...e,
|
||||
// name: e.id === 1 ? "firman" : e.name,
|
||||
// age: e.id === 1 ? 30 : e.age,
|
||||
// }
|
||||
// )
|
||||
// );
|
||||
// setData(dataBaru);
|
||||
// }}
|
||||
// >
|
||||
// Update
|
||||
// </Button>
|
||||
// </Stack>
|
||||
return (
|
||||
<>
|
||||
<Box mt={"lg"}>
|
||||
<Stack>
|
||||
<Button
|
||||
onClick={() => {
|
||||
const clone = _.clone(data);
|
||||
const dataBaru = clone.map(
|
||||
(e) => (
|
||||
e.id === 1,
|
||||
{
|
||||
...e,
|
||||
name: e.id === 1 ? random(50, 100).toString() : e.name,
|
||||
age: e.id === 1 ? random(1, 25) : e.age,
|
||||
}
|
||||
)
|
||||
);
|
||||
setData(dataBaru);
|
||||
}}
|
||||
>
|
||||
Update
|
||||
</Button>
|
||||
</Stack>
|
||||
|
||||
// <pre>{JSON.stringify(data, null, 2)}</pre>
|
||||
// </Box>
|
||||
// </>
|
||||
// );
|
||||
<pre>{JSON.stringify(data, null, 2)}</pre>
|
||||
</Box>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user