fix: collaboration
deskripsi: - fix: use server pada create dan edit menjadi API
This commit is contained in:
@@ -1,21 +1,9 @@
|
|||||||
import { Colab_Edit } from "@/app_modules/colab";
|
import { Colab_Edit } from "@/app_modules/colab";
|
||||||
import colab_getOneCollaborationById from "@/app_modules/colab/fun/get/get_one_by_id";
|
|
||||||
import colab_funGetMasterIndustri from "@/app_modules/colab/fun/master/fun_get_master_industri";
|
|
||||||
import _ from "lodash";
|
|
||||||
|
|
||||||
export default async function Page({ params }: { params: { id: string } }) {
|
|
||||||
const colabId = params.id;
|
|
||||||
const dataColab = await colab_getOneCollaborationById(colabId);
|
|
||||||
const selectedData = _.omit(dataColab, [
|
|
||||||
"ProjectCollaboration_Partisipasi",
|
|
||||||
"Author",
|
|
||||||
]);
|
|
||||||
// console.log(selectedData);
|
|
||||||
const listIndustri = await colab_funGetMasterIndustri()
|
|
||||||
|
|
||||||
|
export default async function Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Colab_Edit selectedData={selectedData as any} listIndustri={listIndustri as any} />
|
<Colab_Edit />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
|
||||||
import { Colab_Beranda } from "@/app_modules/colab";
|
import { Colab_Beranda } from "@/app_modules/colab";
|
||||||
|
|
||||||
export default async function Page() {
|
export default function Page() {
|
||||||
const userLoginId = await funGetUserIdByToken();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Colab_Beranda userLoginId={userLoginId as string} />
|
<Colab_Beranda />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import Colab_GrupDiskus from "@/app_modules/colab/main/grup";
|
import Colab_GrupDiskus from "@/app_modules/colab/main/grup";
|
||||||
|
|
||||||
export default async function Page() {
|
export default function Page() {
|
||||||
// const listRoom = await colab_getListRoomChatByAuthorId({page: 1});
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Colab_GrupDiskus />
|
<Colab_GrupDiskus />
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { Colab_Proyek } from "@/app_modules/colab";
|
import { Colab_Proyek } from "@/app_modules/colab";
|
||||||
|
|
||||||
export default async function Page() {
|
export default function Page() {
|
||||||
// const listPartisipasiProyek = await colab_getListPartisipasiProyekByAuthorId({page: 1})
|
|
||||||
// const listProyekSaya = await colab_getListAllProyekSayaByAuthorId({page: 1})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Colab_Proyek />
|
<Colab_Proyek />
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export {
|
|||||||
apiGetMasterStatusTransaksi,
|
apiGetMasterStatusTransaksi,
|
||||||
apiGetAdminContact,
|
apiGetAdminContact,
|
||||||
apiGetMasterEmotions,
|
apiGetMasterEmotions,
|
||||||
|
apiGetMasterIndustri,
|
||||||
};
|
};
|
||||||
|
|
||||||
const apiGetMasterBank = async () => {
|
const apiGetMasterBank = async () => {
|
||||||
@@ -108,3 +109,37 @@ const apiGetMasterEmotions = async () => {
|
|||||||
|
|
||||||
return await response.json().catch(() => null);
|
return await response.json().catch(() => null);
|
||||||
};
|
};
|
||||||
|
const apiGetMasterIndustri = async () => {
|
||||||
|
try {
|
||||||
|
// Fetch token from cookie
|
||||||
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
|
if (!token) {
|
||||||
|
console.error("No token found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`/api/master/industri`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => null);
|
||||||
|
console.error(
|
||||||
|
"Error get master industri:",
|
||||||
|
errorData?.message || "Unknown error"
|
||||||
|
);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error get master industri:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -20,10 +20,44 @@ export const apiGetOneCollaborationById = async ({
|
|||||||
kategori: "detail" | "list_partisipan" | "cek_partisipasi";
|
kategori: "detail" | "list_partisipan" | "cek_partisipasi";
|
||||||
page?: string;
|
page?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const respone = await fetch(
|
try {
|
||||||
`/api/collaboration/${id}?kategori=${kategori}&page=${page}`
|
// Fetch token from cookie
|
||||||
);
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
return await respone.json().catch(() => null);
|
if (!token) {
|
||||||
|
console.error("No token found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const respone = await fetch(
|
||||||
|
`/api/collaboration/${id}?kategori=${kategori}&page=${page}`,
|
||||||
|
{
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!respone.ok) {
|
||||||
|
const errorData = await respone.json().catch(() => null);
|
||||||
|
console.error(
|
||||||
|
"Failed to get one collaboration by id",
|
||||||
|
respone.statusText,
|
||||||
|
errorData
|
||||||
|
);
|
||||||
|
throw new Error(
|
||||||
|
errorData?.message || "Failed to get one collaboration by id"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await respone.json();
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error get one collaboration by id", error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const apiGetDataGroupById = async ({
|
export const apiGetDataGroupById = async ({
|
||||||
@@ -32,12 +66,47 @@ export const apiGetDataGroupById = async ({
|
|||||||
page,
|
page,
|
||||||
}: {
|
}: {
|
||||||
id: string;
|
id: string;
|
||||||
kategori: "detail" | "info_group"
|
kategori: "detail" | "info_group";
|
||||||
page?: string;
|
page?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const respone = await fetch(
|
const respone = await fetch(
|
||||||
`/api/collaboration/group/${id}?kategori=${kategori}&page=${page}`
|
`/api/collaboration/group/${id}?kategori=${kategori}&page=${page}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await respone.json().catch(() => null)
|
return await respone.json().catch(() => null);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export const apiGetMasterIndustri = async () => {
|
||||||
|
try {
|
||||||
|
// Fetch token from cookie
|
||||||
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
|
if (!token) {
|
||||||
|
console.error("No token found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`/api/collaboration/master`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => null);
|
||||||
|
console.error(
|
||||||
|
"Error get master industri:",
|
||||||
|
errorData?.message || "Unknown error"
|
||||||
|
);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error get master industri:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
export async function apiGetMasterCollaboration() {
|
|
||||||
const data = await fetch(`/api/collaboration/master`);
|
|
||||||
return await data.json().catch(() => null);
|
|
||||||
}
|
|
||||||
@@ -16,9 +16,9 @@ import { useShallowEffect } from "@mantine/hooks";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Collaboration_SkeletonCreate } from "../component";
|
import { Collaboration_SkeletonCreate } from "../component";
|
||||||
import { apiGetMasterCollaboration } from "../component/lib/api_collaboration";
|
|
||||||
import colab_funCreateProyek from "../fun/create/fun_create_proyek";
|
import colab_funCreateProyek from "../fun/create/fun_create_proyek";
|
||||||
import { MODEL_COLLABORATION_MASTER } from "../model/interface";
|
import { MODEL_COLLABORATION_MASTER } from "../model/interface";
|
||||||
|
import { apiGetMasterIndustri } from "../_lib/api_collaboration";
|
||||||
|
|
||||||
interface IValue {
|
interface IValue {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -42,17 +42,18 @@ export default function Colab_Create() {
|
|||||||
>(null);
|
>(null);
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
onLoadMaster();
|
onLoadIndustri();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
async function onLoadMaster() {
|
async function onLoadIndustri() {
|
||||||
try {
|
try {
|
||||||
const respone = await apiGetMasterCollaboration();
|
const response = await apiGetMasterIndustri();
|
||||||
if (respone.success) {
|
|
||||||
setListIndustri(respone.data);
|
if (response.success) {
|
||||||
|
setListIndustri(response.data);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
clientLogger.error("Error get master collaboration", error);
|
clientLogger.error("Error get master industri", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_
|
|||||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||||
import { Button, Select, Stack, Textarea, TextInput } from "@mantine/core";
|
import { Button, Select, Stack, Textarea, TextInput } from "@mantine/core";
|
||||||
import { useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import colab_funEditById from "../fun/edit/fun_edit_by_id";
|
import colab_funEditById from "../fun/edit/fun_edit_by_id";
|
||||||
import {
|
import {
|
||||||
@@ -18,15 +18,62 @@ import Component_V3_Label_TextInput from "@/app_modules/_global/component/new/co
|
|||||||
import { Component_V3_TextEditor } from "@/app_modules/_global/component/new/comp_V3_text_editor";
|
import { Component_V3_TextEditor } from "@/app_modules/_global/component/new/comp_V3_text_editor";
|
||||||
import { funReplaceHtml } from "@/app_modules/_global/fun/fun_replace_html";
|
import { funReplaceHtml } from "@/app_modules/_global/fun/fun_replace_html";
|
||||||
import { maxInputLength } from "@/app_modules/_global/lib/maximal_setting";
|
import { maxInputLength } from "@/app_modules/_global/lib/maximal_setting";
|
||||||
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
|
import {
|
||||||
|
apiGetMasterIndustri,
|
||||||
|
apiGetOneCollaborationById,
|
||||||
|
} from "../_lib/api_collaboration";
|
||||||
|
import _ from "lodash";
|
||||||
|
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||||
|
|
||||||
|
export default function Colab_Edit() {
|
||||||
|
const { id } = useParams();
|
||||||
|
const [data, setData] = useState<MODEL_COLLABORATION | any | null>();
|
||||||
|
const [listIndustri, setListIndustri] = useState<
|
||||||
|
MODEL_COLLABORATION_MASTER[] | null
|
||||||
|
>(null);
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
onLoadIndustri();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
onLoadData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function onLoadData() {
|
||||||
|
try {
|
||||||
|
const response = await apiGetOneCollaborationById({
|
||||||
|
id: id as string,
|
||||||
|
kategori: "detail",
|
||||||
|
});
|
||||||
|
if (response.success) {
|
||||||
|
const fixData = _.omit(response.data, [
|
||||||
|
"ProjectCollaboration_Partisipasi",
|
||||||
|
"Author",
|
||||||
|
]);
|
||||||
|
setData(fixData as MODEL_COLLABORATION);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
clientLogger.error("Error get one collaboration by id", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onLoadIndustri() {
|
||||||
|
try {
|
||||||
|
const response = await apiGetMasterIndustri();
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
|
setListIndustri(response.data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
clientLogger.error("Error get master industri", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data === undefined || listIndustri === null)
|
||||||
|
return <CustomSkeleton height={400} />;
|
||||||
|
|
||||||
export default function Colab_Edit({
|
|
||||||
selectedData,
|
|
||||||
listIndustri,
|
|
||||||
}: {
|
|
||||||
selectedData: MODEL_COLLABORATION;
|
|
||||||
listIndustri: MODEL_COLLABORATION_MASTER[];
|
|
||||||
}) {
|
|
||||||
const [value, setValue] = useState(selectedData);
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack px={"xs"} py={"md"}>
|
<Stack px={"xs"} py={"md"}>
|
||||||
@@ -46,10 +93,10 @@ export default function Colab_Edit({
|
|||||||
label="Judul"
|
label="Judul"
|
||||||
withAsterisk
|
withAsterisk
|
||||||
placeholder="Masukan judul proyek"
|
placeholder="Masukan judul proyek"
|
||||||
value={value.title}
|
value={data?.title}
|
||||||
onChange={(val) =>
|
onChange={(val) =>
|
||||||
setValue({
|
setData({
|
||||||
...value,
|
...data,
|
||||||
title: val.currentTarget.value,
|
title: val.currentTarget.value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -71,10 +118,10 @@ export default function Colab_Edit({
|
|||||||
label="Lokasi"
|
label="Lokasi"
|
||||||
withAsterisk
|
withAsterisk
|
||||||
placeholder="Masukan lokasi proyek"
|
placeholder="Masukan lokasi proyek"
|
||||||
value={value.lokasi}
|
value={data?.lokasi}
|
||||||
onChange={(val) =>
|
onChange={(val) =>
|
||||||
setValue({
|
setData({
|
||||||
...value,
|
...data,
|
||||||
lokasi: val.currentTarget.value,
|
lokasi: val.currentTarget.value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -98,15 +145,19 @@ export default function Colab_Edit({
|
|||||||
placeholder="Pilih kategori industri"
|
placeholder="Pilih kategori industri"
|
||||||
label="Pilih Industri"
|
label="Pilih Industri"
|
||||||
withAsterisk
|
withAsterisk
|
||||||
value={value?.ProjectCollaborationMaster_Industri.id}
|
value={data?.ProjectCollaborationMaster_Industri.id}
|
||||||
data={listIndustri.map((e) => ({
|
data={
|
||||||
value: e.id,
|
_.isEmpty(listIndustri)
|
||||||
label: e.name,
|
? []
|
||||||
}))}
|
: listIndustri.map((e) => ({
|
||||||
|
value: e.id,
|
||||||
|
label: e.name,
|
||||||
|
}))
|
||||||
|
}
|
||||||
onChange={
|
onChange={
|
||||||
(val) =>
|
(val) =>
|
||||||
setValue({
|
setData({
|
||||||
...(value as any),
|
...(data as any),
|
||||||
ProjectCollaborationMaster_Industri: {
|
ProjectCollaborationMaster_Industri: {
|
||||||
id: val as any,
|
id: val as any,
|
||||||
},
|
},
|
||||||
@@ -119,17 +170,17 @@ export default function Colab_Edit({
|
|||||||
<Component_V3_Label_TextInput text="Tujuan Proyek" />
|
<Component_V3_Label_TextInput text="Tujuan Proyek" />
|
||||||
|
|
||||||
<Component_V3_TextEditor
|
<Component_V3_TextEditor
|
||||||
data={value.purpose}
|
data={data?.purpose}
|
||||||
onSetData={(val) => {
|
onSetData={(val) => {
|
||||||
setValue({
|
setData({
|
||||||
...value,
|
...data,
|
||||||
purpose: val,
|
purpose: val,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ComponentGlobal_InputCountDown
|
<ComponentGlobal_InputCountDown
|
||||||
lengthInput={funReplaceHtml({ html: value.purpose }).length}
|
lengthInput={funReplaceHtml({ html: data?.purpose }).length}
|
||||||
maxInput={maxInputLength}
|
maxInput={maxInputLength}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -138,80 +189,22 @@ export default function Colab_Edit({
|
|||||||
<Component_V3_Label_TextInput text="Keuntungan" />
|
<Component_V3_Label_TextInput text="Keuntungan" />
|
||||||
|
|
||||||
<Component_V3_TextEditor
|
<Component_V3_TextEditor
|
||||||
data={value.benefit}
|
data={data?.benefit}
|
||||||
onSetData={(val) => {
|
onSetData={(val) => {
|
||||||
setValue({
|
setData({
|
||||||
...value,
|
...data,
|
||||||
benefit: val,
|
benefit: val,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ComponentGlobal_InputCountDown
|
<ComponentGlobal_InputCountDown
|
||||||
lengthInput={funReplaceHtml({ html: value.benefit }).length}
|
lengthInput={funReplaceHtml({ html: data?.benefit }).length}
|
||||||
maxInput={maxInputLength}
|
maxInput={maxInputLength}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
{/* <Stack spacing={5}>
|
<ButtonAction value={data as any} />
|
||||||
<Textarea
|
|
||||||
styles={{
|
|
||||||
label: {
|
|
||||||
color: MainColor.white,
|
|
||||||
},
|
|
||||||
input: {
|
|
||||||
backgroundColor: MainColor.white,
|
|
||||||
},
|
|
||||||
required: {
|
|
||||||
color: MainColor.red,
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
label="Tujuan Proyek"
|
|
||||||
placeholder="Masukan tujuan proyek"
|
|
||||||
withAsterisk
|
|
||||||
minRows={5}
|
|
||||||
value={value.purpose}
|
|
||||||
onChange={(val) =>
|
|
||||||
setValue({
|
|
||||||
...value,
|
|
||||||
purpose: val.currentTarget.value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<ComponentGlobal_InputCountDown
|
|
||||||
lengthInput={value.purpose.length}
|
|
||||||
maxInput={500}
|
|
||||||
/>
|
|
||||||
</Stack> */}
|
|
||||||
|
|
||||||
{/* <Stack spacing={5}>
|
|
||||||
<Textarea
|
|
||||||
styles={{
|
|
||||||
label: {
|
|
||||||
color: MainColor.white,
|
|
||||||
},
|
|
||||||
input: {
|
|
||||||
backgroundColor: MainColor.white,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
label="Keuntungan "
|
|
||||||
placeholder="Masukan keuntungan dalam proyek"
|
|
||||||
minRows={5}
|
|
||||||
value={value.benefit}
|
|
||||||
onChange={(val) =>
|
|
||||||
setValue({
|
|
||||||
...value,
|
|
||||||
benefit: val.currentTarget.value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<ComponentGlobal_InputCountDown
|
|
||||||
lengthInput={value.benefit.length}
|
|
||||||
maxInput={500}
|
|
||||||
/>
|
|
||||||
</Stack> */}
|
|
||||||
|
|
||||||
<ButtonAction value={value as any} />
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { RouterColab } from "@/lib/router_hipmi/router_colab";
|
|
||||||
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
|
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
|
||||||
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
||||||
|
import { apiNewGetUserIdByToken } from "@/app_modules/_global/lib/api_fetch_global";
|
||||||
|
import { RouterColab } from "@/lib/router_hipmi/router_colab";
|
||||||
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
import mqtt_client from "@/util/mqtt_client";
|
import mqtt_client from "@/util/mqtt_client";
|
||||||
import { Box, Center, Loader } from "@mantine/core";
|
import { Box, Center, Loader } from "@mantine/core";
|
||||||
import { useShallowEffect } from "@mantine/hooks";
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
@@ -12,18 +14,14 @@ import { useState } from "react";
|
|||||||
import { apiGetAllCollaboration } from "../_lib/api_collaboration";
|
import { apiGetAllCollaboration } from "../_lib/api_collaboration";
|
||||||
import { ComponentColab_ButtonUpdateBeranda } from "../component/button/button_update_beranda";
|
import { ComponentColab_ButtonUpdateBeranda } from "../component/button/button_update_beranda";
|
||||||
import { ComponentColab_CardBeranda } from "../component/card_view/card_beranda";
|
import { ComponentColab_CardBeranda } from "../component/card_view/card_beranda";
|
||||||
import { MODEL_COLLABORATION } from "../model/interface";
|
|
||||||
import { Collaboration_SkeletonBeranda } from "../component/skeleton_view";
|
import { Collaboration_SkeletonBeranda } from "../component/skeleton_view";
|
||||||
import { clientLogger } from "@/util/clientLogger";
|
import { MODEL_COLLABORATION } from "../model/interface";
|
||||||
|
|
||||||
export default function Colab_Beranda({
|
export default function Colab_Beranda() {
|
||||||
userLoginId,
|
|
||||||
}: {
|
|
||||||
userLoginId: string;
|
|
||||||
}) {
|
|
||||||
const [data, setData] = useState<MODEL_COLLABORATION[] | null>(null);
|
const [data, setData] = useState<MODEL_COLLABORATION[] | null>(null);
|
||||||
const [activePage, setActivePage] = useState(1);
|
const [activePage, setActivePage] = useState(1);
|
||||||
const [isNewPost, setIsNewPost] = useState(false);
|
const [isNewPost, setIsNewPost] = useState(false);
|
||||||
|
const [userLoginId, setUserLoginId] = useState<string | null>(null);
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
onLoadData();
|
onLoadData();
|
||||||
@@ -44,6 +42,23 @@ export default function Colab_Beranda({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
handleGetUserLoginId();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function handleGetUserLoginId() {
|
||||||
|
try {
|
||||||
|
const response = await apiNewGetUserIdByToken();
|
||||||
|
if (response.success) {
|
||||||
|
setUserLoginId(response.userId);
|
||||||
|
} else {
|
||||||
|
setUserLoginId(null);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setUserLoginId(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
mqtt_client.subscribe("Colab_create");
|
mqtt_client.subscribe("Colab_create");
|
||||||
|
|
||||||
@@ -99,7 +114,7 @@ export default function Colab_Beranda({
|
|||||||
{(item) => (
|
{(item) => (
|
||||||
<ComponentColab_CardBeranda
|
<ComponentColab_CardBeranda
|
||||||
data={item}
|
data={item}
|
||||||
userLoginId={userLoginId}
|
userLoginId={userLoginId as string}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</ScrollOnly>
|
</ScrollOnly>
|
||||||
|
|||||||
Reference in New Issue
Block a user