fix: nested layout
deskripsi: - fix use server pada nested layout - penambahan pemanggilan api pada realtime provider - fix tampilan table admin event pada username
This commit is contained in:
@@ -8,12 +8,12 @@ export default async function Layout({
|
|||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const userId = await funGetUserIdByToken();
|
// const userId = await funGetUserIdByToken();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<RealtimeProvider
|
<RealtimeProvider
|
||||||
userId={userId}
|
// userId={userId}
|
||||||
WIBU_REALTIME_TOKEN={
|
WIBU_REALTIME_TOKEN={
|
||||||
ServerEnv.value?.NEXT_PUBLIC_WIBU_REALTIME_TOKEN as string
|
ServerEnv.value?.NEXT_PUBLIC_WIBU_REALTIME_TOKEN as string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,3 +112,33 @@ const apiGetSeasonUserId = async () => {
|
|||||||
throw error; // Re-throw the error to handle it in the calling function
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ export default function AdminEvent_ComponentTableReview() {
|
|||||||
<td>
|
<td>
|
||||||
<Center c={AdminColor.white}>
|
<Center c={AdminColor.white}>
|
||||||
<Box w={100}>
|
<Box w={100}>
|
||||||
<Text>{e?.Author?.username}</Text>
|
<Text lineClamp={1}>{e?.Author?.username}</Text>
|
||||||
</Box>
|
</Box>
|
||||||
</Center>
|
</Center>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ export function ComponentNotifiaksi_CardView({
|
|||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
try {
|
try {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
console.log("data", data);
|
|
||||||
|
|
||||||
// JOB
|
// JOB
|
||||||
if (data?.kategoriApp === "JOB") {
|
if (data?.kategoriApp === "JOB") {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
gs_votingTiggerBeranda,
|
gs_votingTiggerBeranda,
|
||||||
IRealtimeData,
|
IRealtimeData,
|
||||||
} from "./global_state";
|
} from "./global_state";
|
||||||
|
import { apiNewGetUserIdByToken } from "@/app_modules/_global/lib/api_fetch_global";
|
||||||
|
|
||||||
// const WIBU_REALTIME_TOKEN: string | undefined =
|
// const WIBU_REALTIME_TOKEN: string | undefined =
|
||||||
// process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
|
// process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
|
||||||
@@ -32,14 +33,19 @@ export type TypeNotification = {
|
|||||||
userId?: string;
|
userId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type IResponseAPIGetUser = {
|
||||||
|
success: boolean;
|
||||||
|
userId: string;
|
||||||
|
};
|
||||||
|
|
||||||
// Tambahkan flag global untuk mencegah inisialisasi ulang
|
// Tambahkan flag global untuk mencegah inisialisasi ulang
|
||||||
let isWibuRealtimeInitialized = false;
|
let isWibuRealtimeInitialized = false;
|
||||||
|
|
||||||
export default function RealtimeProvider({
|
export default function RealtimeProvider({
|
||||||
userId,
|
// userId,
|
||||||
WIBU_REALTIME_TOKEN,
|
WIBU_REALTIME_TOKEN,
|
||||||
}: {
|
}: {
|
||||||
userId: string;
|
// userId: string;
|
||||||
WIBU_REALTIME_TOKEN: string;
|
WIBU_REALTIME_TOKEN: string;
|
||||||
}) {
|
}) {
|
||||||
const [dataRealtime, setDataRealtime] = useAtom(gs_realtimeData);
|
const [dataRealtime, setDataRealtime] = useAtom(gs_realtimeData);
|
||||||
@@ -88,9 +94,14 @@ export default function RealtimeProvider({
|
|||||||
gs_investasiTriggerBeranda
|
gs_investasiTriggerBeranda
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Client-side only
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
try {
|
const initRealtime = async () => {
|
||||||
if (!isWibuRealtimeInitialized) {
|
if (typeof window === "undefined") return;
|
||||||
|
|
||||||
|
const response: IResponseAPIGetUser = await apiNewGetUserIdByToken();
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
WibuRealtime.init({
|
WibuRealtime.init({
|
||||||
project: "hipmi",
|
project: "hipmi",
|
||||||
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
|
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
|
||||||
@@ -108,7 +119,7 @@ export default function RealtimeProvider({
|
|||||||
data.type == "trigger" &&
|
data.type == "trigger" &&
|
||||||
data.pushNotificationTo == "USER" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.dataMessage?.kategoriApp == "ACCESS" &&
|
data.dataMessage?.kategoriApp == "ACCESS" &&
|
||||||
data.dataMessage?.userId == userId
|
data.dataMessage?.userId == response.userId
|
||||||
) {
|
) {
|
||||||
setIsAccessUser(data.dataMessage.status as any);
|
setIsAccessUser(data.dataMessage.status as any);
|
||||||
}
|
}
|
||||||
@@ -117,7 +128,7 @@ export default function RealtimeProvider({
|
|||||||
if (
|
if (
|
||||||
data.type == "notification" &&
|
data.type == "notification" &&
|
||||||
data.pushNotificationTo == "USER" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.dataMessage?.userId == userId
|
data.dataMessage?.userId == response.userId
|
||||||
) {
|
) {
|
||||||
setNewUserNtf((e) => e + 1);
|
setNewUserNtf((e) => e + 1);
|
||||||
setDataRealtime(data.dataMessage as any);
|
setDataRealtime(data.dataMessage as any);
|
||||||
@@ -164,7 +175,7 @@ export default function RealtimeProvider({
|
|||||||
data.type == "notification" &&
|
data.type == "notification" &&
|
||||||
data.pushNotificationTo == "USER" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.dataMessage?.status == "Peserta Event" &&
|
data.dataMessage?.status == "Peserta Event" &&
|
||||||
userId !== data.dataMessage?.userId
|
response.userId !== data.dataMessage?.userId
|
||||||
) {
|
) {
|
||||||
setNewUserNtf((e) => e + 1);
|
setNewUserNtf((e) => e + 1);
|
||||||
}
|
}
|
||||||
@@ -192,7 +203,7 @@ export default function RealtimeProvider({
|
|||||||
data.type == "notification" &&
|
data.type == "notification" &&
|
||||||
data.pushNotificationTo == "USER" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.dataMessage?.status == "Voting Masuk" &&
|
data.dataMessage?.status == "Voting Masuk" &&
|
||||||
userId !== data.dataMessage?.userId
|
response.userId !== data.dataMessage?.userId
|
||||||
) {
|
) {
|
||||||
setNewUserNtf((e) => e + 1);
|
setNewUserNtf((e) => e + 1);
|
||||||
}
|
}
|
||||||
@@ -260,11 +271,12 @@ export default function RealtimeProvider({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tandai bahwa WibuRealtime telah diinisialisasi
|
|
||||||
isWibuRealtimeInitialized = true;
|
isWibuRealtimeInitialized = true;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
};
|
||||||
console.log("Error Realtime:", error);
|
|
||||||
|
if (!isWibuRealtimeInitialized) {
|
||||||
|
initRealtime();
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user