Fix: Middlerawe/6

This commit is contained in:
2024-11-21 17:36:35 +08:00
parent c9d5791761
commit b9e4b97b31
2 changed files with 97 additions and 87 deletions

View File

@@ -44,11 +44,12 @@ export default async function RootLayout({
// if (!token) return <>Require Token Storage</>; // if (!token) return <>Require Token Storage</>;
const userLoginId = await funGetUserIdByToken(); const userLoginId = await funGetUserIdByToken();
return ( return (
<RootStyleRegistry> <RootStyleRegistry>
{/* <MqttLoader /> {/* <MqttLoader />
<TokenProvider token={token} envObject={envObject} /> */} <TokenProvider token={token} envObject={envObject} /> */}
{/* <RealtimeProvider userLoginId={userLoginId as string} /> */} <RealtimeProvider userLoginId={userLoginId as string} />
{children} {children}
</RootStyleRegistry> </RootStyleRegistry>
); );

View File

@@ -23,7 +23,8 @@ export type TypeNotification = {
userLoginId?: string; userLoginId?: string;
}; };
const WIBU_REALTIME_TOKEN: any = process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN; const WIBU_REALTIME_TOKEN: string | undefined =
process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
export default function RealtimeProvider({ export default function RealtimeProvider({
userLoginId, userLoginId,
}: { }: {
@@ -57,101 +58,109 @@ export default function RealtimeProvider({
); );
useShallowEffect(() => { useShallowEffect(() => {
WibuRealtime.init({ if (WIBU_REALTIME_TOKEN === undefined) return alert("gak dapet key");
onData(data: TypeNotification) { try {
if (data.type == "notification" && data.pushNotificationTo == "ADMIN") { WibuRealtime.init({
setNewAdminNtf((e) => e + 1); onData(data: TypeNotification) {
} if (
data.type == "notification" &&
data.pushNotificationTo == "ADMIN"
) {
setNewAdminNtf((e) => e + 1);
}
// Notifikasi ke semua user , yang datanya di acc admin // Notifikasi ke semua user , yang datanya di acc admin
if ( if (
data.type == "notification" && data.type == "notification" &&
data.pushNotificationTo == "USER" && data.pushNotificationTo == "USER" &&
data.dataMessage?.userId == userLoginId data.dataMessage?.userId == userLoginId
) { ) {
setNewUserNtf((e) => e + 1); setNewUserNtf((e) => e + 1);
setDataRealtime(data.dataMessage as any); setDataRealtime(data.dataMessage as any);
} }
// ---------------------- JOB ------------------------- // // ---------------------- JOB ------------------------- //
if ( if (
data.type == "trigger" && data.type == "trigger" &&
data.pushNotificationTo == "ADMIN" && data.pushNotificationTo == "ADMIN" &&
data.dataMessage?.kategoriApp == "JOB" data.dataMessage?.kategoriApp == "JOB"
) { ) {
setIsAdminJob_TriggerReview(true); setIsAdminJob_TriggerReview(true);
} }
if ( if (
data.type == "trigger" && data.type == "trigger" &&
data.pushNotificationTo == "USER" && data.pushNotificationTo == "USER" &&
data.dataMessage?.kategoriApp == "JOB" && data.dataMessage?.kategoriApp == "JOB" &&
data.dataMessage.status == "Publish" data.dataMessage.status == "Publish"
) { ) {
setIsTriggerJobBeranda(true); setIsTriggerJobBeranda(true);
} }
// ---------------------- JOB ------------------------- // // ---------------------- JOB ------------------------- //
// ---------------------- EVENT ------------------------- // // ---------------------- EVENT ------------------------- //
if ( if (
data.type == "trigger" && data.type == "trigger" &&
data.pushNotificationTo == "ADMIN" && data.pushNotificationTo == "ADMIN" &&
data.dataMessage?.kategoriApp == "EVENT" data.dataMessage?.kategoriApp == "EVENT"
) { ) {
setIsAdminEvent_TriggerReview(true); setIsAdminEvent_TriggerReview(true);
} }
if ( if (
data.type == "trigger" && data.type == "trigger" &&
data.pushNotificationTo == "USER" && data.pushNotificationTo == "USER" &&
data.dataMessage?.kategoriApp == "EVENT" && data.dataMessage?.kategoriApp == "EVENT" &&
data.dataMessage.status == "Publish" data.dataMessage.status == "Publish"
) { ) {
setIsTriggerEventBeranda(true); setIsTriggerEventBeranda(true);
} }
if ( if (
data.type == "notification" && data.type == "notification" &&
data.pushNotificationTo == "USER" && data.pushNotificationTo == "USER" &&
data.dataMessage?.status == "Peserta Event" && data.dataMessage?.status == "Peserta Event" &&
userLoginId !== data.dataMessage?.userId userLoginId !== data.dataMessage?.userId
) { ) {
setNewUserNtf((e) => e + 1); setNewUserNtf((e) => e + 1);
} }
// ---------------------- EVENT ------------------------- // // ---------------------- EVENT ------------------------- //
// ---------------------- VOTING ------------------------- // // ---------------------- VOTING ------------------------- //
if ( if (
data.type == "trigger" && data.type == "trigger" &&
data.pushNotificationTo == "ADMIN" && data.pushNotificationTo == "ADMIN" &&
data.dataMessage?.kategoriApp == "VOTING" data.dataMessage?.kategoriApp == "VOTING"
) { ) {
setIsAdminVoting_TriggerReview(true); setIsAdminVoting_TriggerReview(true);
} }
if ( if (
data.type == "trigger" && data.type == "trigger" &&
data.pushNotificationTo == "USER" && data.pushNotificationTo == "USER" &&
data.dataMessage?.kategoriApp == "VOTING" && data.dataMessage?.kategoriApp == "VOTING" &&
data.dataMessage.status == "Publish" data.dataMessage.status == "Publish"
) { ) {
setIsTriggerVotingBeranda(true); setIsTriggerVotingBeranda(true);
} }
if ( if (
data.type == "notification" && data.type == "notification" &&
data.pushNotificationTo == "USER" && data.pushNotificationTo == "USER" &&
data.dataMessage?.status == "Voting Masuk" && data.dataMessage?.status == "Voting Masuk" &&
userLoginId !== data.dataMessage?.userId userLoginId !== data.dataMessage?.userId
) { ) {
setNewUserNtf((e) => e + 1); setNewUserNtf((e) => e + 1);
} }
// ---------------------- VOTING ------------------------- // // ---------------------- VOTING ------------------------- //
}, },
project: "hipmi", project: "hipmi",
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN, WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
}); });
} catch (error) {
alert("error realtime");
}
}, []); }, []);
return null; return null;