Update Versi 1.5.27 #32

Merged
bagasbanuna merged 1009 commits from staging into main 2025-12-17 12:22:28 +08:00
2025 changed files with 83497 additions and 21551 deletions
Showing only changes of commit c202cc8ea0 - Show all commits

View File

@@ -8,12 +8,12 @@ export default async function Layout({
}: {
children: React.ReactNode;
}) {
const userId = await funGetUserIdByToken();
// const userId = await funGetUserIdByToken();
return (
<>
<RealtimeProvider
userId={userId}
// userId={userId}
WIBU_REALTIME_TOKEN={
ServerEnv.value?.NEXT_PUBLIC_WIBU_REALTIME_TOKEN as string
}

View File

@@ -112,3 +112,33 @@ const apiGetSeasonUserId = async () => {
throw error; // Re-throw the error to handle it in the calling function
}
};
export const apiNewGetUserIdByToken = async () => {
try {
const response = await fetch(`/api/user/id`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});
// Check if the response is OK
if (!response.ok) {
const errorData = await response.json().catch(() => null);
console.error(
"Failed to get user id",
response.statusText,
errorData
);
throw new Error(errorData?.message || "Failed to get user id");
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error get user id", error);
throw error; // Re-throw the error to handle it in the calling function
}
}

View File

@@ -262,7 +262,7 @@ export default function AdminEvent_ComponentTableReview() {
<td>
<Center c={AdminColor.white}>
<Box w={100}>
<Text>{e?.Author?.username}</Text>
<Text lineClamp={1}>{e?.Author?.username}</Text>
</Box>
</Center>
</td>

View File

@@ -77,7 +77,6 @@ export function ComponentNotifiaksi_CardView({
onClick={async () => {
try {
setVisible(true);
console.log("data", data);
// JOB
if (data?.kategoriApp === "JOB") {

View File

@@ -20,6 +20,7 @@ import {
gs_votingTiggerBeranda,
IRealtimeData,
} from "./global_state";
import { apiNewGetUserIdByToken } from "@/app_modules/_global/lib/api_fetch_global";
// const WIBU_REALTIME_TOKEN: string | undefined =
// process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
@@ -32,14 +33,19 @@ export type TypeNotification = {
userId?: string;
};
type IResponseAPIGetUser = {
success: boolean;
userId: string;
};
// Tambahkan flag global untuk mencegah inisialisasi ulang
let isWibuRealtimeInitialized = false;
export default function RealtimeProvider({
userId,
// userId,
WIBU_REALTIME_TOKEN,
}: {
userId: string;
// userId: string;
WIBU_REALTIME_TOKEN: string;
}) {
const [dataRealtime, setDataRealtime] = useAtom(gs_realtimeData);
@@ -88,9 +94,14 @@ export default function RealtimeProvider({
gs_investasiTriggerBeranda
);
// Client-side only
useShallowEffect(() => {
try {
if (!isWibuRealtimeInitialized) {
const initRealtime = async () => {
if (typeof window === "undefined") return;
const response: IResponseAPIGetUser = await apiNewGetUserIdByToken();
if (response.success) {
WibuRealtime.init({
project: "hipmi",
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
@@ -108,7 +119,7 @@ export default function RealtimeProvider({
data.type == "trigger" &&
data.pushNotificationTo == "USER" &&
data.dataMessage?.kategoriApp == "ACCESS" &&
data.dataMessage?.userId == userId
data.dataMessage?.userId == response.userId
) {
setIsAccessUser(data.dataMessage.status as any);
}
@@ -117,7 +128,7 @@ export default function RealtimeProvider({
if (
data.type == "notification" &&
data.pushNotificationTo == "USER" &&
data.dataMessage?.userId == userId
data.dataMessage?.userId == response.userId
) {
setNewUserNtf((e) => e + 1);
setDataRealtime(data.dataMessage as any);
@@ -164,7 +175,7 @@ export default function RealtimeProvider({
data.type == "notification" &&
data.pushNotificationTo == "USER" &&
data.dataMessage?.status == "Peserta Event" &&
userId !== data.dataMessage?.userId
response.userId !== data.dataMessage?.userId
) {
setNewUserNtf((e) => e + 1);
}
@@ -192,7 +203,7 @@ export default function RealtimeProvider({
data.type == "notification" &&
data.pushNotificationTo == "USER" &&
data.dataMessage?.status == "Voting Masuk" &&
userId !== data.dataMessage?.userId
response.userId !== data.dataMessage?.userId
) {
setNewUserNtf((e) => e + 1);
}
@@ -260,11 +271,12 @@ export default function RealtimeProvider({
},
});
// Tandai bahwa WibuRealtime telah diinisialisasi
isWibuRealtimeInitialized = true;
}
} catch (error) {
console.log("Error Realtime:", error);
};
if (!isWibuRealtimeInitialized) {
initRealtime();
}
}, []);