From 7cbbcd037038b4522f599c3b5e9693ad9e78b8ae Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Fri, 13 Dec 2024 07:37:31 +0800 Subject: [PATCH] Fix upload image profile and portofolio --- src/app/api/job/get-all/route.ts | 100 ++++- src/app/page.tsx | 4 +- .../button/comp_button_upload_photo.tsx | 1 + .../fun/upload/fun_upload_to_storage.ts | 2 + .../_global/ui/ui_image_preview.tsx | 6 +- src/app_modules/home/component/body_home.tsx | 349 +++++++++--------- .../home/component/footer_home.tsx | 200 +++++----- src/app_modules/home/view_home_new.tsx | 202 +++++----- .../job/main/beranda/ui_beranda.tsx | 124 ------- .../job/main/beranda/view_beranda.tsx | 118 +++++- .../button/comp_button_selanjutnya.tsx | 52 ++- .../katalog/portofolio/create/view.tsx | 63 +++- .../button/comp_create_new_profile.tsx | 25 -- .../katalog/profile/create/view.tsx | 65 +++- .../button/comp_button_save_pin.tsx | 56 ++- src/app_modules/map/ui/ui_create_pin.tsx | 65 +++- 16 files changed, 824 insertions(+), 608 deletions(-) delete mode 100644 src/app_modules/job/main/beranda/ui_beranda.tsx diff --git a/src/app/api/job/get-all/route.ts b/src/app/api/job/get-all/route.ts index 21db076c..1601d2bb 100644 --- a/src/app/api/job/get-all/route.ts +++ b/src/app/api/job/get-all/route.ts @@ -1,16 +1,94 @@ -import { job_getAllListPublish } from "@/app_modules/job/fun/get/get_all_publish"; -import _ from "lodash"; +import { prisma } from "@/app/lib"; import { NextResponse } from "next/server"; +export const dynamic = "force-dynamic"; -export async function GET(params: Request) { - const { searchParams } = new URL(params.url); - const page = searchParams.get("page"); - const search = searchParams.get("search"); +export async function GET(request: Request) { + try { + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const dataTake = 10; + const dataSkip = Number(page) * dataTake - dataTake; - const data = await job_getAllListPublish({ - page: _.toNumber(page), - search: search as string, - }); + if (search != "") { + const data = await prisma.job.findMany({ + take: dataTake, + skip: dataSkip, + orderBy: { + updatedAt: "desc", + }, + where: { + masterStatusId: "1", + isActive: true, + isArsip: false, + title: { + mode: "insensitive", + contains: search as string, + }, + }, + select: { + id: true, + title: true, + Author: { + select: { + id: true, + username: true, + Profile: true, + }, + }, + }, + }); - return NextResponse.json({ data }); + return NextResponse.json( + { + success: true, + message: "Berhasil ambil data", + data: data, + }, + { status: 200 } + ); + } else { + const data = await prisma.job.findMany({ + take: dataTake, + skip: dataSkip, + orderBy: { + updatedAt: "desc", + }, + where: { + masterStatusId: "1", + isActive: true, + isArsip: false, + title: { + mode: "insensitive", + }, + }, + select: { + id: true, + title: true, + Author: { + select: { + id: true, + username: true, + Profile: true, + }, + }, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Berhasil ambil data", + data: data, + }, + { status: 200 } + ); + } + } catch (error) { + console.error(error); + return NextResponse.json({ + success: false, + message: "Gagal ambil data", + }); + } } diff --git a/src/app/page.tsx b/src/app/page.tsx index 3dc0d2d4..6fc3a06d 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -5,11 +5,11 @@ import { useShallowEffect } from "@mantine/hooks"; import { useRouter } from "next/navigation"; export default function Page() { - const router = useRouter() + const router = useRouter(); useShallowEffect(() => { setTimeout(() => { // window.location.replace("/dev/home"); - router.replace("/dev/home"); + router.replace("/dev/home", { scroll: false }); }, 1000); }, []); diff --git a/src/app_modules/_global/button/comp_button_upload_photo.tsx b/src/app_modules/_global/button/comp_button_upload_photo.tsx index 0a28c023..8e56d342 100644 --- a/src/app_modules/_global/button/comp_button_upload_photo.tsx +++ b/src/app_modules/_global/button/comp_button_upload_photo.tsx @@ -24,6 +24,7 @@ export function ComponentGlobal_ButtonUploadFileImage({ if (files.size > MAX_SIZE) { ComponentGlobal_NotifikasiPeringatan(PemberitahuanMaksimalFile); + return; } else { onSetFile(files); onSetImage(buffer); diff --git a/src/app_modules/_global/fun/upload/fun_upload_to_storage.ts b/src/app_modules/_global/fun/upload/fun_upload_to_storage.ts index 06ed38f4..df5b7377 100644 --- a/src/app_modules/_global/fun/upload/fun_upload_to_storage.ts +++ b/src/app_modules/_global/fun/upload/fun_upload_to_storage.ts @@ -54,6 +54,8 @@ export async function funGlobal_UploadToStorage({ if (res.ok) { const dataRes = await res.json(); + // const cekLog = await res.text(); + // console.log(cekLog); return { success: true, data: dataRes.data }; } else { const errorText = await res.text(); diff --git a/src/app_modules/_global/ui/ui_image_preview.tsx b/src/app_modules/_global/ui/ui_image_preview.tsx index a2057b2d..fce91d58 100644 --- a/src/app_modules/_global/ui/ui_image_preview.tsx +++ b/src/app_modules/_global/ui/ui_image_preview.tsx @@ -10,18 +10,16 @@ import { Image, rem, ScrollArea, - Skeleton, - Text, - Title, + Skeleton } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import { IconX } from "@tabler/icons-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { MainColor } from "../color"; +import ComponentGlobal_Loader from "../component/loader"; import UIGlobal_LayoutHeaderTamplate from "./ui_header_tamplate"; import { UIHeader } from "./ui_layout_tamplate"; -import ComponentGlobal_Loader from "../component/loader"; export function UIGlobal_ImagePreview({ fileId }: { fileId: string }) { const router = useRouter(); diff --git a/src/app_modules/home/component/body_home.tsx b/src/app_modules/home/component/body_home.tsx index d5984b8d..69f7dac2 100644 --- a/src/app_modules/home/component/body_home.tsx +++ b/src/app_modules/home/component/body_home.tsx @@ -1,7 +1,17 @@ import { AccentColor, MainColor } from "@/app_modules/_global/color"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global"; -import { ActionIcon, Box, Group, Image, Paper, SimpleGrid, Skeleton, Stack, Text } from "@mantine/core"; +import { + ActionIcon, + Box, + Group, + Image, + Paper, + SimpleGrid, + Skeleton, + Stack, + Text, +} from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import { IconUserSearch } from "@tabler/icons-react"; import _ from "lodash"; @@ -9,185 +19,182 @@ import { useRouter } from "next/navigation"; import { useState } from "react"; import { apiGetDataHome } from "../fun/get/api_home"; import { listMenuHomeBody, menuHomeJob } from "./list_menu_home"; +import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog"; export default function BodyHome() { - const router = useRouter() - const [dataUser, setDataUser] = useState({}) - const [dataJob, setDataJob] = useState([]) - const [loadingJob, setLoadingJob] = useState(true) + const router = useRouter(); + const [dataUser, setDataUser] = useState({}); + const [dataJob, setDataJob] = useState([]); + const [loadingJob, setLoadingJob] = useState(true); - useShallowEffect(() => { - cekUserLogin() - getHomeJob() - }, []); + useShallowEffect(() => { + cekUserLogin(); + getHomeJob(); + }, []); - - async function cekUserLogin() { - try { - const response = await apiGetDataHome("?cat=cek_profile") - if (response.success) { - setDataUser(response.data); - } - } catch (error) { - console.error(error); + async function cekUserLogin() { + try { + const response = await apiGetDataHome("?cat=cek_profile"); + if (response.success) { + setDataUser(response.data); } - } + } catch (error) { + console.error(error); + } + } - async function getHomeJob() { - try { - setLoadingJob(true) - const response = await apiGetDataHome("?cat=job") - if (response.success) { - setDataJob(response.data); - } - } catch (error) { - console.error(error); - } finally { - setLoadingJob(false) + async function getHomeJob() { + try { + setLoadingJob(true); + const response = await apiGetDataHome("?cat=job"); + if (response.success) { + setDataJob(response.data); } - } + } catch (error) { + console.error(error); + } finally { + setLoadingJob(false); + } + } - return ( - - - logo - + return ( + + + logo + - - - {listMenuHomeBody.map((e, i) => ( - { - if (dataUser.profile === undefined || dataUser?.profile === null) { - return ComponentGlobal_NotifikasiPeringatan( - "Lengkapi Profile" - ); - } else { - if (e.link === "") { - return ComponentGlobal_NotifikasiPeringatan( - "Cooming Soon !!" - ); - } else { - router.push(e.link, { scroll: false }); - } - } - }} - > - - - {e.icon} - - - {e.name} - - - - ))} - - - {/* Job View */} + + + {listMenuHomeBody.map((e, i) => ( - { - if (dataUser.profile === undefined || dataUser?.profile === null) { - return ComponentGlobal_NotifikasiPeringatan( - "Lengkapi Profile" - ); - } else { - if (menuHomeJob.link === "") { - return ComponentGlobal_NotifikasiPeringatan( - "Cooming Soon !!" - ); - } else { - return router.push(menuHomeJob.link, { scroll: false }); - } - } - }} - > - - - {menuHomeJob.icon} - - - {menuHomeJob.name} - - - { - loadingJob ? - Array(2) - .fill(null) - .map((_, i) => ( - - - - - - )) - : _.isEmpty(dataJob) ? - () - : ( - - {dataJob.map((e, i) => ( - - - - - - - - {e?.Author.username} - - - {e?.title} - - - - - ))} - - ) + key={e.id} + h={150} + bg={MainColor.darkblue} + style={{ + borderRadius: "10px 10px 10px 10px", + border: `2px solid ${AccentColor.blue}`, + }} + onClick={() => { + if ( + dataUser.profile === undefined || + dataUser?.profile === null + ) { + router.push(RouterProfile.create, { scroll: false }); + } else { + if (e.link === "") { + return ComponentGlobal_NotifikasiPeringatan( + "Cooming Soon !!" + ); + } else { + router.push(e.link, { scroll: false }); } - + } + }} + > + + + {e.icon} + + + {e.name} + + - - - ); -} \ No newline at end of file + ))} + + + {/* Job View */} + + { + if ( + dataUser.profile === undefined || + dataUser?.profile === null + ) { + router.push(RouterProfile.create, { scroll: false }); + } else { + if (menuHomeJob.link === "") { + return ComponentGlobal_NotifikasiPeringatan( + "Cooming Soon !!" + ); + } else { + return router.push(menuHomeJob.link, { scroll: false }); + } + } + }} + > + + + {menuHomeJob.icon} + + + {menuHomeJob.name} + + + {loadingJob ? ( + Array(2) + .fill(null) + .map((_, i) => ( + + + + + + )) + ) : _.isEmpty(dataJob) ? ( + + ) : ( + + {dataJob.map((e, i) => ( + + + + + + + + {e?.Author.username} + + + {e?.title} + + + + + ))} + + )} + + + + + ); +} diff --git a/src/app_modules/home/component/footer_home.tsx b/src/app_modules/home/component/footer_home.tsx index f116b19d..e1503ffa 100644 --- a/src/app_modules/home/component/footer_home.tsx +++ b/src/app_modules/home/component/footer_home.tsx @@ -1,7 +1,14 @@ import { APIs } from "@/app/lib"; import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global"; -import { ActionIcon, Box, Center, SimpleGrid, Stack, Text } from "@mantine/core"; +import { + ActionIcon, + Box, + Center, + SimpleGrid, + Stack, + Text, +} from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import { IconUserCircle } from "@tabler/icons-react"; import { useRouter } from "next/navigation"; @@ -11,103 +18,104 @@ import { Home_ComponentAvatarProfile } from "./comp_avatar_profile"; import { listMenuHomeFooter } from "./list_menu_home"; export default function FooterHome() { - const router = useRouter() - const [dataUser, setDataUser] = useState({}) + const router = useRouter(); + const [dataUser, setDataUser] = useState({}); - useShallowEffect(() => { - cekUserLogin(); - }, []); + useShallowEffect(() => { + cekUserLogin(); + }, []); - - async function cekUserLogin() { - try { - const response = await apiGetDataHome("?cat=cek_profile") - if (response.success) { - setDataUser(response.data); - } - } catch (error) { - console.error(error); + async function cekUserLogin() { + try { + const response = await apiGetDataHome("?cat=cek_profile"); + if (response.success) { + setDataUser(response.data); } - } + } catch (error) { + console.error(error); + } + } - return ( - - - {listMenuHomeFooter.map((e) => ( -
- { - if (dataUser.profile === undefined || dataUser?.profile === null) { - ComponentGlobal_NotifikasiPeringatan("Lengkapi Profile"); - } else { - if (e.link == "") { - ComponentGlobal_NotifikasiPeringatan("Cooming Soon") - } else { - router.push(e.link, { scroll: false }) - } - } - }} - > - - {e.icon} - - - {e.name} - - -
- ))} + return ( + + + {listMenuHomeFooter.map((e) => ( +
+ { + if ( + dataUser.profile === undefined || + dataUser?.profile === null + ) { + router.push(RouterProfile.create, { scroll: false }); + } else { + if (e.link == "") { + ComponentGlobal_NotifikasiPeringatan("Cooming Soon"); + } else { + router.push(e.link, { scroll: false }); + } + } + }} + > + + {e.icon} + + + {e.name} + + +
+ ))} -
- { - if (dataUser.profile === undefined || dataUser?.profile === null) { - router.push(RouterProfile.create, { scroll: false }); - } else { - router.push( - RouterProfile.katalogOLD + `${dataUser?.profile}`, - { scroll: false } - ); - } - }} - > - - {dataUser.profile === undefined || dataUser?.profile === null - ? - - : - - } - - - Profile - - -
-
-
- ); -} \ No newline at end of file +
+ { + if ( + dataUser.profile === undefined || + dataUser?.profile === null + ) { + router.push(RouterProfile.create, { scroll: false }); + } else { + router.push(RouterProfile.katalogOLD + `${dataUser?.profile}`, { + scroll: false, + }); + } + }} + > + + {dataUser.profile === undefined || dataUser?.profile === null ? ( + + ) : ( + + )} + + + Profile + + +
+
+
+ ); +} diff --git a/src/app_modules/home/view_home_new.tsx b/src/app_modules/home/view_home_new.tsx index 8fbe5441..de88ed02 100644 --- a/src/app_modules/home/view_home_new.tsx +++ b/src/app_modules/home/view_home_new.tsx @@ -16,112 +16,120 @@ import notifikasi_countUserNotifikasi from "../notifikasi/fun/count/fun_count_by import BodyHome from "./component/body_home"; import FooterHome from "./component/footer_home"; import { apiGetDataHome } from "./fun/get/api_home"; +import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog"; -export default function HomeViewNew({ countNotifikasi }: { countNotifikasi: number; }) { - const [countNtf, setCountNtf] = useState(countNotifikasi); - const [newUserNtf, setNewUserNtf] = useAtom(gs_user_ntf); - const [countLoadNtf, setCountLoadNtf] = useAtom(gs_count_ntf); - const [dataUser, setDataUser] = useState({}) - const router = useRouter(); +export default function HomeViewNew({ + countNotifikasi, +}: { + countNotifikasi: number; +}) { + const [countNtf, setCountNtf] = useState(countNotifikasi); + const [newUserNtf, setNewUserNtf] = useAtom(gs_user_ntf); + const [countLoadNtf, setCountLoadNtf] = useAtom(gs_count_ntf); + const [dataUser, setDataUser] = useState({}); + const router = useRouter(); + useShallowEffect(() => { + onLoadNotifikasi({ + onLoad(val) { + setCountNtf(val); + }, + }); - useShallowEffect(() => { - onLoadNotifikasi({ - onLoad(val) { - setCountNtf(val); - }, - }); + setCountNtf(countLoadNtf as any); + }, [countLoadNtf, setCountNtf]); - setCountNtf(countLoadNtf as any); - }, [countLoadNtf, setCountNtf]); + useShallowEffect(() => { + setCountNtf(countNtf + newUserNtf); + setNewUserNtf(0); + }, [newUserNtf, setCountNtf]); - useShallowEffect(() => { - setCountNtf(countNtf + newUserNtf); - setNewUserNtf(0); - }, [newUserNtf, setCountNtf]); + async function onLoadNotifikasi({ onLoad }: { onLoad: (val: any) => void }) { + const loadNotif = await notifikasi_countUserNotifikasi(); + onLoad(loadNotif); + } - async function onLoadNotifikasi({ onLoad }: { onLoad: (val: any) => void }) { - const loadNotif = await notifikasi_countUserNotifikasi(); - onLoad(loadNotif); - } + useShallowEffect(() => { + cekUserLogin(); + }, []); - useShallowEffect(() => { - cekUserLogin(); - }, []); - - - async function cekUserLogin() { - try { - const response = await apiGetDataHome("?cat=cek_profile") - if (response.success) { - setDataUser(response.data); - } - } catch (error) { - console.error(error); + async function cekUserLogin() { + try { + const response = await apiGetDataHome("?cat=cek_profile"); + if (response.success) { + setDataUser(response.data); } - } + } catch (error) { + console.error(error); + } + } - return ( - <> - { - if (dataUser.profile === undefined || dataUser?.profile === null) { - ComponentGlobal_NotifikasiPeringatan("Lengkapi Profile"); - } else { - router.push(RouterUserSearch.main, { scroll: false }); - } - }} - > - - + return ( + <> + { + if ( + dataUser.profile === undefined || + dataUser?.profile === null + ) { + router.push(RouterProfile.create, { scroll: false }); + } else { + router.push(RouterUserSearch.main, { scroll: false }); } - customButtonRight={ - { - if (dataUser.profile === undefined || dataUser?.profile === null) { - ComponentGlobal_NotifikasiPeringatan("Lengkapi Profile"); - } else { - router.push(RouterNotifikasi.categoryApp({ name: "semua" }), { - scroll: false, - }); - } - }} - > - { - countNotifikasi > 0 - ? - - {countNotifikasi > 99 ? "99+" : countNotifikasi} - - } - > - - - : - - } - - - } - /> + }} + > + + } - - footer={} - > - - - - ); + customButtonRight={ + { + if ( + dataUser.profile === undefined || + dataUser?.profile === null + ) { + router.push(RouterProfile.create, { scroll: false }); + } else { + router.push( + RouterNotifikasi.categoryApp({ name: "semua" }), + { + scroll: false, + } + ); + } + }} + > + {countNotifikasi > 0 ? ( + + {countNotifikasi > 99 ? "99+" : countNotifikasi} + + } + > + + + ) : ( + + )} + + } + /> + } + footer={} + > + + + + ); } diff --git a/src/app_modules/job/main/beranda/ui_beranda.tsx b/src/app_modules/job/main/beranda/ui_beranda.tsx deleted file mode 100644 index 0783e9f7..00000000 --- a/src/app_modules/job/main/beranda/ui_beranda.tsx +++ /dev/null @@ -1,124 +0,0 @@ -"use client"; - -import { gs_jobTiggerBeranda } from "@/app/lib/global_state"; -import { RouterJob } from "@/app/lib/router_hipmi/router_job"; -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 { useShallowEffect } from "@mantine/hooks"; -import { IconSearch } from "@tabler/icons-react"; -import { useAtom } from "jotai"; -import _ from "lodash"; -import { ScrollOnly } from "next-scroll-loader"; -import { useState } from "react"; -import { - Job_ComponentButtonUpdateBeranda, - Job_ComponentSkeletonBeranda, -} from "../../component"; -import ComponentJob_BerandaCardView from "../../component/beranda/card_view"; -import { job_getAllListPublish } from "../../fun/get/get_all_publish"; -import { MODEL_JOB } from "../../model/interface"; -import { API_RouteJob } from "@/app/lib/api_user_router/route_api_job"; - -export function Job_UiBeranda() { - const [data, setData] = useState(null); - const [activePage, setActivePage] = useState(1); - const [isSearch, setIsSearch] = useState(""); - - // Notifikasi - const [isShowUpdate, setIsShowUpdate] = useState(false); - const [isTriggerJob, setIsTriggerJob] = useAtom(gs_jobTiggerBeranda); - - useShallowEffect(() => { - if (isTriggerJob == true) { - setIsShowUpdate(true); - } - }, [isTriggerJob]); - - useShallowEffect(() => { - setIsTriggerJob(false); - setIsShowUpdate(false); - onLoadNewData(); - }, []); - - async function onSearch(text: string) { - setIsSearch(text); - const loadData = await job_getAllListPublish({ - page: activePage, - search: text, - }); - setData(loadData as any); - setActivePage(1); - } - - async function onLoadNewData() { - const loadData = await fetch(API_RouteJob.get_all({ page: activePage })); - const res = await loadData.json(); - - setData(res.data); - } - - return ( - <> - - {isShowUpdate && ( - { - setIsShowUpdate(val); - setIsTriggerJob(val); - }} - onSetData={(val: any[]) => { - setData(val); - }} - /> - )} - - - - } - placeholder="Pekerjaan apa yang anda cari ?" - onChange={(val) => { - onSearch(val.currentTarget.value); - }} - /> - - {_.isNull(data) ? ( - - ) : _.isEmpty(data) ? ( - - ) : ( - // --- Main component --- // - ( -
- -
- )} - data={data} - setData={setData as any} - moreData={async () => { - const loadData = await job_getAllListPublish({ - page: activePage + 1, - search: isSearch, - }); - - setActivePage((val) => val + 1); - - return loadData; - }} - > - {(item) => } -
- )} -
- - ); -} diff --git a/src/app_modules/job/main/beranda/view_beranda.tsx b/src/app_modules/job/main/beranda/view_beranda.tsx index d6004905..f9c905b5 100644 --- a/src/app_modules/job/main/beranda/view_beranda.tsx +++ b/src/app_modules/job/main/beranda/view_beranda.tsx @@ -1,10 +1,124 @@ +"use client"; + +import { API_RouteJob } from "@/app/lib/api_user_router/route_api_job"; +import { gs_jobTiggerBeranda } from "@/app/lib/global_state"; +import { RouterJob } from "@/app/lib/router_hipmi/router_job"; +import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create"; +import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; +import { Center, Loader, Stack, TextInput } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; +import { IconSearch } from "@tabler/icons-react"; +import { useAtom } from "jotai"; +import _ from "lodash"; +import { ScrollOnly } from "next-scroll-loader"; +import { useState } from "react"; +import { + Job_ComponentButtonUpdateBeranda, + Job_ComponentSkeletonBeranda, +} from "../../component"; +import ComponentJob_BerandaCardView from "../../component/beranda/card_view"; import { MODEL_JOB } from "../../model/interface"; -import { Job_UiBeranda } from "./ui_beranda"; export default function Job_ViewBeranda() { + const [data, setData] = useState(null); + const [activePage, setActivePage] = useState(1); + const [isSearch, setIsSearch] = useState(""); + + // Notifikasi + const [isShowUpdate, setIsShowUpdate] = useState(false); + const [isTriggerJob, setIsTriggerJob] = useAtom(gs_jobTiggerBeranda); + + useShallowEffect(() => { + if (isTriggerJob == true) { + setIsShowUpdate(true); + } + }, [isTriggerJob]); + + useShallowEffect(() => { + setIsTriggerJob(false); + setIsShowUpdate(false); + onLoadNewData(); + }, []); + + async function onSearch(text: string) { + setIsSearch(text); + const loadData = await fetch( + API_RouteJob.get_all({ page: activePage, search: text }) + ); + const res = await loadData.json(); + + setData(res.data as any); + setActivePage(1); + } + + async function onLoadNewData() { + const loadData = await fetch(API_RouteJob.get_all({ page: activePage })); + const res = await loadData.json(); + // console.log(res.data); + setData(res.data); + } + return ( <> - + + {isShowUpdate && ( + { + setIsShowUpdate(val); + setIsTriggerJob(val); + }} + onSetData={(val: any[]) => { + setData(val); + }} + /> + )} + + + + } + placeholder="Pekerjaan apa yang anda cari ?" + onChange={(val) => { + onSearch(val.currentTarget.value); + }} + /> + + {_.isNull(data) ? ( + + ) : _.isEmpty(data) ? ( + + ) : ( + // --- Main component --- // + ( +
+ +
+ )} + data={data} + setData={setData as any} + moreData={async () => { + const loadData = await fetch( + API_RouteJob.get_all({ page: activePage, search: isSearch }) + ); + + const res = await loadData.json(); + setActivePage((val) => val + 1); + + return res.data; + }} + > + {(item) => } +
+ )} +
); } diff --git a/src/app_modules/katalog/portofolio/component/button/comp_button_selanjutnya.tsx b/src/app_modules/katalog/portofolio/component/button/comp_button_selanjutnya.tsx index 41c037b9..6af70436 100644 --- a/src/app_modules/katalog/portofolio/component/button/comp_button_selanjutnya.tsx +++ b/src/app_modules/katalog/portofolio/component/button/comp_button_selanjutnya.tsx @@ -12,25 +12,22 @@ import _ from "lodash"; import { useRouter } from "next/navigation"; import { useState } from "react"; import funCreatePortofolio from "../../fun/fun_create_portofolio"; -import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; -import { DIRECTORY_ID } from "@/app/lib"; export function Portofolio_ComponentButtonSelanjutnya({ profileId, dataPortofolio, - file, dataMedsos, + imageId, }: { profileId: string; dataPortofolio: MODEL_PORTOFOLIO_OLD; - file: File; dataMedsos: any; + imageId: string }) { const router = useRouter(); const [loading, setLoading] = useState(false); async function onSubmit() { - setLoading(true); const porto = { namaBisnis: dataPortofolio.namaBisnis, masterBidangBisnisId: dataPortofolio.masterBidangBisnisId, @@ -39,34 +36,33 @@ export function Portofolio_ComponentButtonSelanjutnya({ deskripsi: dataPortofolio.deskripsi, }; - if (_.values(porto).includes("")) - return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data"); - - const uploadFileToStorage = await funGlobal_UploadToStorage({ - file: file, - dirId: DIRECTORY_ID.portofolio_logo, - }); - - if (!uploadFileToStorage.success) - return ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar"); - - const res = await funCreatePortofolio({ - profileId: profileId, - data: dataPortofolio as any, - medsos: dataMedsos, - fileId: uploadFileToStorage.data.id, - }); - if (res.status === 201) { - ComponentGlobal_NotifikasiBerhasil("Berhasil disimpan"); - router.replace(RouterMap.create + res.id, { scroll: false }); - } else { - ComponentGlobal_NotifikasiGagal("Gagal disimpan"); + try { + setLoading(true); + if (_.values(porto).includes("")) { + return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data"); + } + const res = await funCreatePortofolio({ + profileId: profileId, + data: dataPortofolio as any, + medsos: dataMedsos, + fileId: imageId, + }); + if (res.status === 201) { + ComponentGlobal_NotifikasiBerhasil("Berhasil disimpan"); + router.replace(RouterMap.create + res.id, { scroll: false }); + } else { + ComponentGlobal_NotifikasiGagal("Gagal disimpan"); + } + } catch (error) { + console.error(error); + } finally { + setLoading(false); } } return ( <>