diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5aa6018e..c391b394 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -114,7 +114,6 @@ model Images { Donasi_PencairanDana Donasi_PencairanDana[] Donasi_Invoice Donasi_Invoice[] Portofolio Portofolio[] - Job Job[] Image_Map BusinessMaps[] @relation("ImageMap") Image_Pin BusinessMaps[] @relation("ImagePin") Investasi_Invoice Investasi_Invoice[] @@ -684,16 +683,15 @@ model Job { updatedAt DateTime @updatedAt isArsip Boolean @default(false) catatan String? + title String + content String @db.Text + deskripsi String @db.Text - title String - content String @db.Text - deskripsi String @db.Text - Images Images? @relation(fields: [imagesId], references: [id]) - imagesId String? Author User? @relation(fields: [authorId], references: [id]) authorId String? MasterStatus MasterStatus? @relation(fields: [masterStatusId], references: [id]) masterStatusId String? @default("2") + imageId String? } // ========================================= FORUM ========================================= // diff --git a/public/donasi/image/37a3ffae-a422-4f4b-b63e-4e174a66d7ba.jpeg b/public/donasi/image/37a3ffae-a422-4f4b-b63e-4e174a66d7ba.jpeg new file mode 100644 index 00000000..d3ea1214 Binary files /dev/null and b/public/donasi/image/37a3ffae-a422-4f4b-b63e-4e174a66d7ba.jpeg differ diff --git a/public/donasi/image_cerita/91150f04-cff1-4c1a-9c4a-b1e8eed2e4ae.jpeg b/public/donasi/image_cerita/91150f04-cff1-4c1a-9c4a-b1e8eed2e4ae.jpeg new file mode 100644 index 00000000..e25549da Binary files /dev/null and b/public/donasi/image_cerita/91150f04-cff1-4c1a-9c4a-b1e8eed2e4ae.jpeg differ diff --git a/src/app/contoh/page.tsx b/src/app/contoh/page.tsx index 211c2c35..8196cbb4 100644 --- a/src/app/contoh/page.tsx +++ b/src/app/contoh/page.tsx @@ -1,13 +1,14 @@ "use client"; import { ComponentNotifikasi_CardSkeleton } from "@/app_modules/notifikasi/component"; +import Coba_UploadFile from "@/app_modules/zCoba/ui_coba_upload_file"; import { Box, Button, Flex, Paper, Stack, Title } from "@mantine/core"; export default function Page() { - - return<> - - - + return ( + <> + + + ); return ( {Array.from(new Array(10), (_, i) => ( - + Contoh ))} diff --git a/src/app/dev/admin/job/child/review/page.tsx b/src/app/dev/admin/job/child/review/page.tsx index 55838522..84fd487f 100644 --- a/src/app/dev/admin/job/child/review/page.tsx +++ b/src/app/dev/admin/job/child/review/page.tsx @@ -1,6 +1,5 @@ import { AdminJob_TableReview } from "@/app_modules/admin/job"; import adminJob_getListReview from "@/app_modules/admin/job/fun/get/get_list_review"; -import { AdminJob_getListTableByStatusId } from "@/app_modules/admin/job/fun/get/get_list_table_by_status_id"; export default async function Page() { const dataReview = await adminJob_getListReview({ page: 1 }); diff --git a/src/app/dev/auth/login/page.tsx b/src/app/dev/auth/login/page.tsx index 9ef15c54..3cefa21a 100644 --- a/src/app/dev/auth/login/page.tsx +++ b/src/app/dev/auth/login/page.tsx @@ -2,7 +2,7 @@ import { Login } from "@/app_modules/auth"; import { cookies } from "next/headers"; export default function Page() { - const c = cookies().getAll(); + const c: any = cookies().getAll(); return ( <> diff --git a/src/app/dev/auth/splash/page.tsx b/src/app/dev/auth/splash/page.tsx index 183d35c3..f542411c 100644 --- a/src/app/dev/auth/splash/page.tsx +++ b/src/app/dev/auth/splash/page.tsx @@ -7,22 +7,16 @@ import { unsealData } from "iron-session"; import { getConfig } from "@/bin/config"; import yaml from "yaml"; import fs from "fs"; +import { user_funGetOneUserId } from "@/app_modules/fun_global"; const config = yaml.parse(fs.readFileSync("config.yaml").toString()); export default async function PageSplash() { - const c = cookies().get("ssn"); - const tkn = !c - ? null - : JSON.parse( - await unsealData(c.value as string, { - password: (await getConfig()).server.password, - }) - ); + const userLoginId = await user_funGetOneUserId(); return ( <> - + ); } diff --git a/src/app/dev/event/create/page.tsx b/src/app/dev/event/create/page.tsx index a1eb4bc1..96e80d5f 100644 --- a/src/app/dev/event/create/page.tsx +++ b/src/app/dev/event/create/page.tsx @@ -4,8 +4,10 @@ import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token"; import _ from "lodash"; export default async function Page() { - const userId = await user_funGetOneUserId() + const userId = await user_funGetOneUserId(); const listTipeAcara = await Event_getMasterTipeAcara(); - return ; + return ( + + ); } diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 18f8eb90..c2c6abc7 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,16 +1,20 @@ import MqttLoader from "@/util/mqtt_loader"; import RootStyleRegistry from "./emotion"; -import { Container } from "@mantine/core"; -import './globals.css' +import "./globals.css"; +import { TokenProvider } from "./lib/token"; + +const token = process.env.WS_APIKEY; export default function RootLayout({ children, }: { children: React.ReactNode; }) { + if (!token) return <>require token; return ( + {children} ); diff --git a/src/app/lib/APIs.ts b/src/app/lib/APIs.ts new file mode 100644 index 00000000..b2443d43 --- /dev/null +++ b/src/app/lib/APIs.ts @@ -0,0 +1,7 @@ +const APIs = { + GET: "https://wibu-storage.wibudev.com/api/files/", +}; + +export default APIs + + diff --git a/src/app/lib/api.ts b/src/app/lib/api.ts deleted file mode 100644 index 48812758..00000000 --- a/src/app/lib/api.ts +++ /dev/null @@ -1,20 +0,0 @@ -export const ApiHipmi = { - // Get one token - get_token: "/api/user/get-token", - // Auth - login: "/api/auth/login", - validasi: "/api/auth/validasi", - register: "/api/auth/register", - logout: "/api/auth/logout", - - //Profile - create_profile: "/api/profile/create", - edit_profile: "/api/profile/edit", - get_foto: "/api/profile/foto/", - - //Portofolio - create_portofolio: "/api/portofolio/create", - - //Investasi - get_gambar_investasi: "/api/investasi/gambar" -}; diff --git a/src/app/lib/id-derectory.ts b/src/app/lib/id-derectory.ts new file mode 100644 index 00000000..3ee92dce --- /dev/null +++ b/src/app/lib/id-derectory.ts @@ -0,0 +1,14 @@ +const DIRECTORY_ID = { + profile_foto: "cm0x93rgo000jbp5tj8baoaus", + profile_background: "cm0x93ze8000lbp5t1a8uc9wl", + portofolio_logo: "cm0yjl6ug000310njwmk6j0tx", + map_pin: "cm0yjq8up000710njv5klra32", + map_image: "cm0yjqnxl000910njplqho07w", + investasi_image: "cm0yjs35h000b10njb35o12h1", + investasi_bukti_transfer: "cm0yjsflu000d10njrc3lnqho", + donasi_image: "cm0yk1coh000f10nj597a99kv", + donasi_bukti_transfer: "cm0yk1pmh000h10njhi6m8b8t", + job_image: "cm0ypp6zl0003kp7jf59zuvjy", +}; + +export default DIRECTORY_ID; diff --git a/src/app/lib/index.ts b/src/app/lib/index.ts new file mode 100644 index 00000000..e9c5bc8c --- /dev/null +++ b/src/app/lib/index.ts @@ -0,0 +1,7 @@ +import APIs from "./APIs"; +import DIRECTORY_ID from "./id-derectory"; +import prisma from "./prisma"; + +export { DIRECTORY_ID }; +export { prisma }; +export { APIs }; diff --git a/src/app/lib/token.ts b/src/app/lib/token.ts new file mode 100644 index 00000000..7ce27bae --- /dev/null +++ b/src/app/lib/token.ts @@ -0,0 +1,18 @@ +"use client"; + +class TokenStorage { + static value = ""; + static get() { + return TokenStorage.value; + } + static set(value: string) { + TokenStorage.value = value; + } +} + +function TokenProvider({ token }: { token: string }) { + TokenStorage.set(token); + return null; +} + +export { TokenStorage, TokenProvider }; diff --git a/src/app_modules/_global/component/box_information.tsx b/src/app_modules/_global/component/box_information.tsx index ce66af3f..71a91909 100644 --- a/src/app_modules/_global/component/box_information.tsx +++ b/src/app_modules/_global/component/box_information.tsx @@ -3,10 +3,12 @@ import { AccentColor, MainColor } from "../color/color_pallet"; export default function ComponentGlobal_BoxInformation({ informasi, - isReport, + isReport, + fonsize, }: { informasi: string; isReport?: boolean; + fonsize?: number | string; }) { return ( <> @@ -20,10 +22,15 @@ export default function ComponentGlobal_BoxInformation({ }} > - + * Report - + {informasi} @@ -38,7 +45,7 @@ export default function ComponentGlobal_BoxInformation({ }} > - + *{" "} {informasi} diff --git a/src/app_modules/_global/component/comp_card_box_and_background.tsx b/src/app_modules/_global/component/comp_card_box_and_background.tsx new file mode 100644 index 00000000..aad520e2 --- /dev/null +++ b/src/app_modules/_global/component/comp_card_box_and_background.tsx @@ -0,0 +1,43 @@ +import { AccentColor } from "@/app_modules/_global/color"; +import { Card } from "@mantine/core"; +import React from "react"; + +export function ComponentGlobal_CardStyles({ + children, + backgroundColor, + border, + marginBottom, + height, + color, + onClickHandler, +}: { + children: React.ReactNode; + backgroundColor?: string; + border?: string; + marginBottom?: string | number; + height?: string | number; + color?: string; + onClickHandler?: React.MouseEventHandler; +}) { + return ( + <> + + {children} + + + ); +} diff --git a/src/app_modules/_global/component/index.ts b/src/app_modules/_global/component/index.ts index e5e7bad5..dcd7dc74 100644 --- a/src/app_modules/_global/component/index.ts +++ b/src/app_modules/_global/component/index.ts @@ -1,9 +1,15 @@ +import ComponentGlobal_BoxInformation from "./box_information"; import ComponentGlobal_AvatarAndAuthorName from "./comp_author_name_and_avatar"; +import { ComponentGlobal_CardStyles } from "./comp_card_box_and_background"; import ComponentGlobal_CardLoadingOverlay from "./comp_loading_card"; import ComponentGlobal_TampilanAngkaRatusan from "./comp_tampilan_angka_ratusan"; import ComponentGlobal_TampilanRupiah from "./comp_tampilan_rupiah"; +import ComponentGlobal_InputCountDown from "./input_countdown"; export { ComponentGlobal_TampilanRupiah }; export { ComponentGlobal_TampilanAngkaRatusan }; export { ComponentGlobal_AvatarAndAuthorName }; export { ComponentGlobal_CardLoadingOverlay }; +export { ComponentGlobal_BoxInformation }; +export { ComponentGlobal_InputCountDown }; +export { ComponentGlobal_CardStyles }; diff --git a/src/app_modules/_global/component/loader.tsx b/src/app_modules/_global/component/loader.tsx index 8df65a5d..e3c03c23 100644 --- a/src/app_modules/_global/component/loader.tsx +++ b/src/app_modules/_global/component/loader.tsx @@ -1,10 +1,20 @@ import { Loader } from "@mantine/core"; import { MainColor } from "../color/color_pallet"; -export default function ComponentGlobal_Loader({ size }: { size?: number }) { +export default function ComponentGlobal_Loader({ + size, + variant, +}: { + size?: number; + variant?: "dots" | "bars" | "oval"; +}) { return ( <> - + ); } diff --git a/src/app_modules/_global/fun/index.ts b/src/app_modules/_global/fun/index.ts new file mode 100644 index 00000000..e85ec448 --- /dev/null +++ b/src/app_modules/_global/fun/index.ts @@ -0,0 +1,3 @@ +import { funGlobal_UploadToStorage } from "./upload/fun_upload_to_storage"; + +export { funGlobal_UploadToStorage }; 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 new file mode 100644 index 00000000..9ef9155c --- /dev/null +++ b/src/app_modules/_global/fun/upload/fun_upload_to_storage.ts @@ -0,0 +1,55 @@ +import { TokenStorage } from "@/app/lib/token"; + +export async function funGlobal_UploadToStorage({ + file, + dirId, +}: { + file: File; + dirId: string; +}) { + if (!file) console.log("Tidak ada file"); + + const allowedMimeTypes = [ + "image/png", + "image/jpeg", + "image/gif", + "text/csv", + "application/pdf", + "application/msword", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "application/vnd.ms-excel", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "text/plain", + ]; + + if (!allowedMimeTypes.includes(file.type)) console.log("File tidak sesuai"); + + if (file.size > 100 * 1024 * 1024) console.log("File terlalu besar"); + + const formData = new FormData(); + formData.append("file", file); + formData.append("dirId", dirId); + + try { + const res = await fetch("https://wibu-storage.wibudev.com/api/upload", { + method: "POST", + body: formData, + headers: { + Authorization: `Bearer ${TokenStorage.value}`, + }, + }); + + const dataRes = await res.json(); + + if (res.ok) { + return { success: true, data: dataRes.data }; + } else { + const errorText = await res.text(); + console.error("Error:", errorText); + return { success: false, data: {} }; + } + } catch (error) { + console.error("Error:", error); + return { success: false, data: {} }; + } +} diff --git a/src/app_modules/_global/notif_global/index.ts b/src/app_modules/_global/notif_global/index.ts new file mode 100644 index 00000000..355d8145 --- /dev/null +++ b/src/app_modules/_global/notif_global/index.ts @@ -0,0 +1,7 @@ +import { ComponentGlobal_NotifikasiBerhasil } from "./notifikasi_berhasil"; +import { ComponentGlobal_NotifikasiGagal } from "./notifikasi_gagal"; +import { ComponentGlobal_NotifikasiPeringatan } from "./notifikasi_peringatan"; + +export { ComponentGlobal_NotifikasiBerhasil }; +export { ComponentGlobal_NotifikasiGagal }; +export { ComponentGlobal_NotifikasiPeringatan }; diff --git a/src/app_modules/admin/_admin_global/logout.tsx b/src/app_modules/admin/_admin_global/logout.tsx index 0b2508fc..837d3423 100644 --- a/src/app_modules/admin/_admin_global/logout.tsx +++ b/src/app_modules/admin/_admin_global/logout.tsx @@ -1,6 +1,9 @@ "use client"; -import { myConsole } from "@/app/fun/my_console"; -import { ApiHipmi } from "@/app/lib/api"; +import { Warna } from "@/app/lib/warna"; +import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; +import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; +import { auth_Logout } from "@/app_modules/auth/fun/fun_logout"; +import { gs_kodeId } from "@/app_modules/auth/state/state"; import { ActionIcon, Button, @@ -10,15 +13,10 @@ import { Stack, Title, } from "@mantine/core"; -import { useRouter } from "next/navigation"; -import { useAtom } from "jotai"; -import { IconLogout } from "@tabler/icons-react"; -import { Warna } from "@/app/lib/warna"; import { useDisclosure } from "@mantine/hooks"; -import { gs_kodeId, gs_nomor, gs_otp } from "@/app_modules/auth/state/state"; -import { auth_Logout } from "@/app_modules/auth/fun/fun_logout"; -import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; -import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; +import { IconLogout } from "@tabler/icons-react"; +import { useAtom } from "jotai"; +import { useRouter } from "next/navigation"; import { useState } from "react"; export default function Admin_Logout() { diff --git a/src/app_modules/admin/job/child/arsip/index.tsx b/src/app_modules/admin/job/child/arsip/index.tsx index 37819715..bb39e9c9 100644 --- a/src/app_modules/admin/job/child/arsip/index.tsx +++ b/src/app_modules/admin/job/child/arsip/index.tsx @@ -1,40 +1,21 @@ "use client"; -import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog"; import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate"; -import { adminEvent_getListPesertaById } from "@/app_modules/admin/event/fun/get/get_list_peserta_by_id"; -import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; -import { - MODEL_EVENT, - MODEL_EVENT_PESERTA, -} from "@/app_modules/event/model/interface"; import { MODEL_JOB } from "@/app_modules/job/model/interface"; import { - MODEL_VOTE_KONTRIBUTOR, - MODEL_VOTING, - MODEL_VOTING_DAFTAR_NAMA_VOTE, -} from "@/app_modules/vote/model/interface"; -import { - Avatar, - Badge, Box, Button, - Card, Center, - Divider, - Grid, - Group, Modal, - Paper, ScrollArea, Spoiler, Stack, Table, Text, - Title, + Title } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; -import { IconEyeCheck, IconEyeShare } from "@tabler/icons-react"; +import { IconEyeCheck } from "@tabler/icons-react"; import _ from "lodash"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -74,13 +55,13 @@ function TableStatus({ listArsip }: { listArsip: MODEL_JOB[] }) {
- {e.imagesId ? ( + {e.imageId ? ( ) : ( -
+
Tidak ada poster @@ -147,28 +148,22 @@ function TableStatus({ dataPublish }: { dataPublish: any }) { return ( <> - - {/*
{JSON.stringify(listUser, null, 2)}
*/} - - - Publish - - } - radius={"xl"} - placeholder="Masukan judul" - onChange={(val) => { - onSearch(val.currentTarget.value); - }} - /> - + } + radius={"xl"} + placeholder="Masukan judul" + onChange={(val) => { + onSearch(val.currentTarget.value); + }} + /> + } + /> @@ -217,8 +212,6 @@ function TableStatus({ dataPublish }: { dataPublish: any }) {
- - ); } diff --git a/src/app_modules/admin/job/child/reject/index.tsx b/src/app_modules/admin/job/child/reject/index.tsx index 8299b4e1..476da95a 100644 --- a/src/app_modules/admin/job/child/reject/index.tsx +++ b/src/app_modules/admin/job/child/reject/index.tsx @@ -97,13 +97,13 @@ function TableStatus({ listReject }: { listReject: any }) {
- {e.imagesId ? ( + {e.imageId ? ( + + ); +} + +export default Job_ComponentButtonSaveCreate; diff --git a/src/app_modules/job/component/button/comp_button_update.tsx b/src/app_modules/job/component/button/comp_button_update.tsx new file mode 100644 index 00000000..225cb84d --- /dev/null +++ b/src/app_modules/job/component/button/comp_button_update.tsx @@ -0,0 +1,128 @@ +import { MainColor, AccentColor } from "@/app_modules/_global/color"; +import { + ComponentGlobal_NotifikasiBerhasil, + ComponentGlobal_NotifikasiGagal, + ComponentGlobal_NotifikasiPeringatan, +} from "@/app_modules/_global/notif_global"; +import { Modal, Stack, Title, Group, Button } from "@mantine/core"; +import { useDisclosure, useWindowScroll } from "@mantine/hooks"; +import { useAtom } from "jotai"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { job_EditById } from "../../fun/edit/fun_edit_by_id"; +import { gs_job_hot_menu, gs_job_status } from "../../global_state"; +import { MODEL_JOB } from "../../model/interface"; +import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; +import { DIRECTORY_ID } from "@/app/lib"; + +export function Job_ComponentButtonUpdate({ + value, + file, +}: { + value: MODEL_JOB; + file: File; +}) { + const router = useRouter(); + const [isLoading, setIsLoading] = useState(false); + + const [hotMenu, setHotMenu] = useAtom(gs_job_hot_menu); + const [status, setStatus] = useAtom(gs_job_status); + const [opened, { open, close }] = useDisclosure(false); + const [scroll, scrollTo] = useWindowScroll(); + + async function onUpdate() { + if (file === null) { + const update = await job_EditById({ + data: value, + }); + if (update.status !== 200) + return ComponentGlobal_NotifikasiGagal(update.message); + } else { + const uploadFile = await funGlobal_UploadToStorage({ + file: file, + dirId: DIRECTORY_ID.job_image, + }); + + if (!uploadFile.success) + return ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar"); + + const updateWithFile = await job_EditById({ + data: value, + }); + if (updateWithFile.status !== 200) + return ComponentGlobal_NotifikasiGagal(updateWithFile.message); + } + + setHotMenu(2); + setStatus("Draft"); + setIsLoading(true); + router.back(); + return ComponentGlobal_NotifikasiBerhasil("Berhasil Update"); + } + + return ( + <> + + + + Anda yakin menyimpan data ini ? + + + + + + + + + + + ); +} diff --git a/src/app_modules/job/component/detail/comp_box_upload_image.tsx b/src/app_modules/job/component/detail/comp_box_upload_image.tsx new file mode 100644 index 00000000..f9de93fb --- /dev/null +++ b/src/app_modules/job/component/detail/comp_box_upload_image.tsx @@ -0,0 +1,24 @@ +import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component"; +import { Box } from "@mantine/core"; + +export function Job_ComponentBoxUploadImage({ + children, +}: { + children: React.ReactNode; +}) { + return ( + <> + + + {children} + + + + ); +} diff --git a/src/app_modules/job/component/detail/detail_data.tsx b/src/app_modules/job/component/detail/detail_data.tsx index d5216eb2..9727bcd8 100644 --- a/src/app_modules/job/component/detail/detail_data.tsx +++ b/src/app_modules/job/component/detail/detail_data.tsx @@ -1,21 +1,35 @@ "use client"; -import { Card, Stack, Skeleton, Image, Text, Center } from "@mantine/core"; -import { MODEL_JOB } from "../../model/interface"; -import { RouterJob } from "@/app/lib/router_hipmi/router_job"; +import { APIs } from "@/app/lib"; import { AccentColor, MainColor, } from "@/app_modules/_global/color/color_pallet"; +import { + Card, + Center, + Image, + Loader, + Paper, + Skeleton, + Stack, + Text, +} from "@mantine/core"; +import { MODEL_JOB } from "../../model/interface"; +import { useState } from "react"; +import ComponentGlobal_Loader from "@/app_modules/_global/component/loader"; export default function ComponentJob_DetailData({ data, }: { data?: MODEL_JOB; }) { + const [isLoading, setIsLoading] = useState(true); + return ( <> {/*
{JSON.stringify(data, null, 2)}
*/} + {data ? ( - {data.imagesId ? ( + {data.imageId ? ( + {isLoading ? ( + +
+ +
+
+ ) : ( + "" + )} + { + setIsLoading(false); + }} + onError={() => { + setIsLoading(false); + }} + alt="Image" + src={APIs.GET + data?.imageId} + maw={200} />
) : ( diff --git a/src/app_modules/job/component/index.ts b/src/app_modules/job/component/index.ts new file mode 100644 index 00000000..616e108c --- /dev/null +++ b/src/app_modules/job/component/index.ts @@ -0,0 +1,7 @@ +import Job_ComponentButtonSaveCreate from "./button/comp_button_save_create"; +import { Job_ComponentButtonUpdate } from "./button/comp_button_update"; +import { Job_ComponentBoxUploadImage } from "./detail/comp_box_upload_image"; + +export { Job_ComponentButtonSaveCreate }; +export { Job_ComponentBoxUploadImage }; +export { Job_ComponentButtonUpdate }; diff --git a/src/app_modules/job/create/TextEdit.tsx b/src/app_modules/job/create/TextEdit.tsx deleted file mode 100644 index c75551cd..00000000 --- a/src/app_modules/job/create/TextEdit.tsx +++ /dev/null @@ -1,61 +0,0 @@ -"use client"; - -import { Center, Stack } from "@mantine/core"; -import { useShallowEffect } from "@mantine/hooks"; -import dynamic from "next/dynamic"; -import React, { useState } from "react"; -const ReactQuill = dynamic( - () => { - return import("react-quill"); - }, - { ssr: false } -); -import "react-quill/dist/quill.snow.css"; - -export default function Demo() { - const [value, setValue] = useState(""); - const [udah, setUdah] = useState(false); - - // useShallowEffect(() => { - // if (window && window.document) setUdah(true); - // }, []); - - // if (!udah) return <>
; - return ( - - Judul Lowongan Kerja -


-

Syarat & Ketentuan :

-
    -
  1. Minimal pendidika SMA / Sederajat
  2. -
  3. Pasif berbahasa inggris
  4. -
  5. Dll,.
  6. -
-


-

Deskripsi :

-

Jika berminat dapat menghubungi WA berikut

-

+6281 xxx xxx xx

-

Kirim CV anda melalui email berikut

-

@test-hipmi.com

-

Atau kunjungi website kami:

-

https://test-hipmi.wibudev.com/

- `} - modules={{ - toolbar: [ - [{ header: [1, 2, 3, 4, 5, 6, false] }], - ["bold", "italic", "underline", "link"], - // [{ align: [] }], - [{ list: "ordered" }, { list: "bullet" }], - - ["clean"], - ], - }} - theme="snow" - onChange={setValue} - /> - {/* {value} -
*/} - - ); -} diff --git a/src/app_modules/job/create/view.tsx b/src/app_modules/job/create/view.tsx index 57a33249..23c6bcce 100644 --- a/src/app_modules/job/create/view.tsx +++ b/src/app_modules/job/create/view.tsx @@ -1,24 +1,19 @@ "use client"; import { + AspectRatio, + Box, Button, Center, FileButton, - Group, Image, - Loader, - Paper, Stack, Text, TextInput, } from "@mantine/core"; import { IconCamera, IconUpload } from "@tabler/icons-react"; -import { useAtom } from "jotai"; -import { useRouter } from "next/navigation"; -import { useState } from "react"; -import { gs_job_hot_menu, gs_job_status } from "../global_state"; - import dynamic from "next/dynamic"; +import { useState } from "react"; import "react-quill/dist/quill.snow.css"; const ReactQuill = dynamic( () => { @@ -27,22 +22,21 @@ const ReactQuill = dynamic( { ssr: false } ); -import { RouterJob } from "@/app/lib/router_hipmi/router_job"; import { AccentColor, MainColor, } from "@/app_modules/_global/color/color_pallet"; -import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information"; -import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown"; -import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; -import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; -import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; -import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin"; -import mqtt_client from "@/util/mqtt_client"; -import { useShallowEffect } from "@mantine/hooks"; + +import { + ComponentGlobal_BoxInformation, + ComponentGlobal_CardStyles, + ComponentGlobal_InputCountDown, +} from "@/app_modules/_global/component"; +import { + Job_ComponentBoxUploadImage, + Job_ComponentButtonSaveCreate, +} from "../component"; import { defaultDeskripsi, defaultSyarat } from "../component/default_value"; -import { Job_funCreate } from "../fun/create/fun_create"; -import { MODEL_JOB } from "../model/interface"; export default function Job_Create() { const [value, setValue] = useState({ @@ -52,272 +46,172 @@ export default function Job_Create() { }); const [reload, setReload] = useState(false); const [file, setFile] = useState(null); - const [images, setImages] = useState(); + const [img, setImg] = useState(); - useShallowEffect(() => { - if (window && window.document) setReload(true); - }, []); + // useShallowEffect(() => { + // if (window && window.document) setReload(true); + // }, []); return ( - <> - {!reload ? ( -
- -
- ) : ( - - - {images ? ( - - ) : ( - - - - - Upload Gambar - - - + + + + + + {img ? ( + + Foto + + ) : ( + + + + Upload Gambar + + + )} + + +
+ { + try { + const buffer = URL.createObjectURL( + new Blob([new Uint8Array(await files.arrayBuffer())]) + ); + setImg(buffer); + setFile(files); + } catch (error) { + console.log(error); + } + }} + accept="image/png,image/jpeg" + > + {(props) => ( + )} - - { - try { - const buffer = URL.createObjectURL( - new Blob([new Uint8Array(await files.arrayBuffer())]) - ); - if (files.size > 200000) { - ComponentGlobal_NotifikasiPeringatan( - "Maaf, Ukuran file terlalu besar, maksimal 2mb", - 3000 - ); - } else { - setImages(buffer); - setFile(files); - } - } catch (error) { - console.log(error); - } - }} - accept="image/png,image/jpeg" - > - {(props) => ( - - )} - - - - - - - { - setValue({ - ...value, - title: val.currentTarget.value, - }); - }} - /> - - - - Syarat & Ketentuan - - {" "} - * - - - - - { - setValue({ - ...value, - content: val, - }); - }} - /> - - - - - - Deskripsi - - {" "} - * - - - - { - setValue({ - ...value, - deskripsi: val, - }); - }} - /> - - - - - - - - )} - - ); -} - -function ButtonAction({ value, file }: { value: MODEL_JOB; file: FormData }) { - const router = useRouter(); - const [isLoading, setIsLoading] = useState(false); - - const [hotMenu, setHotMenu] = useAtom(gs_job_hot_menu); - const [status, setStatus] = useAtom(gs_job_status); - - async function onCreate() { - const gambar = new FormData(); - gambar.append("file", file as any); - - const create = await Job_funCreate(value as any, gambar); - if (create.status === 201) { - const dataNotif: any = { - appId: create.data?.id as any, - kategoriApp: "JOB", - status: create.data?.MasterStatus?.name as any, - userId: create.data?.authorId as any, - pesan: create.data?.title as any, - title: "Job baru", - }; - - const notif = await notifikasiToAdmin_funCreate({ - data: dataNotif as any, - }); - // console.log(notif); . - - if (notif.status === 201) { - mqtt_client.publish( - "ADMIN", - JSON.stringify({ - count: 1, - }) - ); - setHotMenu(2); - setStatus("Review"); - router.replace(RouterJob.status); - setIsLoading(true); - ComponentGlobal_NotifikasiBerhasil(create.message); - } - } else { - ComponentGlobal_NotifikasiGagal(create.message); - } - } - - return ( - <> - - - - + +
- + + + + { + setValue({ + ...value, + title: val.currentTarget.value, + }); + }} + /> + + + + Syarat & Ketentuan + + {" "} + * + + + + + { + setValue({ + ...value, + content: val, + }); + }} + /> + + + + + + + Deskripsi + + {" "} + * + + + + + { + setValue({ + ...value, + deskripsi: val, + }); + }} + /> + + + + + + + +
); } diff --git a/src/app_modules/job/edit/view.tsx b/src/app_modules/job/edit/view.tsx index 180d70db..4810d7fa 100644 --- a/src/app_modules/job/edit/view.tsx +++ b/src/app_modules/job/edit/view.tsx @@ -3,6 +3,7 @@ import { RouterJob } from "@/app/lib/router_hipmi/router_job"; import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; import { + AspectRatio, Button, Center, FileButton, @@ -14,7 +15,7 @@ import { Stack, Text, TextInput, - Title + Title, } from "@mantine/core"; import { useDisclosure, @@ -36,55 +37,53 @@ import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/inpu import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; import dynamic from "next/dynamic"; -import { Job_EditById } from "../fun/edit/fun_edit_by_id"; +import { job_EditById } from "../fun/edit/fun_edit_by_id"; const ReactQuill = dynamic( () => { return import("react-quill"); }, { ssr: false } ); +import "react-quill/dist/quill.snow.css"; +import { Job_ComponentBoxUploadImage, Job_ComponentButtonUpdate } from "../component"; +import { APIs } from "@/app/lib"; +import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component"; export default function Job_Edit({ dataJob }: { dataJob: MODEL_JOB }) { const [value, setValue] = useState(dataJob); - const [reload, setReload] = useState(false); const [file, setFile] = useState(null); - const [images, setImages] = useState(); - const [maxFile, setMaxFile] = useState(false); + const [img, setImg] = useState(); - useShallowEffect(() => { - if (window && window.document) setReload(true); - }, []); + // useShallowEffect(() => { + // if (window && window.document) setReload(true); + // }, []); return ( <> - {!reload ? ( -
- -
- ) : ( - - - {images ? ( - - ) : value.imagesId ? ( - Foto + + + + {value.imageId ? ( + + Foto + ) : ( - - - - - Upload Gambar - - - + + + + Upload Gambar + + )} + +
{ try { @@ -92,19 +91,8 @@ export default function Job_Edit({ dataJob }: { dataJob: MODEL_JOB }) { new Blob([new Uint8Array(await files.arrayBuffer())]) ); - if (files.size > 200000) { - // setMaxFile(true); - ComponentGlobal_NotifikasiPeringatan( - "Maaf, Ukuran file terlalu besar, maksimal 2mb", - 3000 - ); - } else { - // console.log(buffer, "ini buffer"); - // console.log(files, " ini file"); - - setImages(buffer); - setFile(files); - } + setImg(buffer); + setFile(files); } catch (error) { console.log(error); } @@ -121,21 +109,15 @@ export default function Job_Edit({ dataJob }: { dataJob: MODEL_JOB }) { border: `1px solid ${AccentColor.yellow}`, }} > - + )} - +
+
- + + + - -
- )} + +
); } -function ButtonAction({ value, file }: { value: MODEL_JOB; file: FormData }) { - const router = useRouter(); - const [isLoading, setIsLoading] = useState(false); - const [hotMenu, setHotMenu] = useAtom(gs_job_hot_menu); - const [status, setStatus] = useAtom(gs_job_status); - const [opened, { open, close }] = useDisclosure(false); - const [scroll, scrollTo] = useWindowScroll(); - - async function onUpdate() { - const gambar = new FormData(); - gambar.append("file", file as any); - - await Job_EditById(value, gambar).then((res) => { - if (res.status === 200) { - setHotMenu(2); - setStatus("Draft"); - ComponentGlobal_NotifikasiBerhasil(res.message); - setIsLoading(true); - router.back(); - } else { - ComponentGlobal_NotifikasiGagal(res.message); - } - }); - } - - return ( - <> - - - - Anda yakin menyimpan data ini ? - - - - - - - - - - ); -} diff --git a/src/app_modules/job/fun/create/fun_create.ts b/src/app_modules/job/fun/create/fun_create.ts deleted file mode 100644 index 7f0a8fd2..00000000 --- a/src/app_modules/job/fun/create/fun_create.ts +++ /dev/null @@ -1,95 +0,0 @@ -"use server"; - -import prisma from "@/app/lib/prisma"; -import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token"; -import _ from "lodash"; -import { v4 } from "uuid"; -import fs from "fs"; -import { revalidatePath } from "next/cache"; -import { MODEL_JOB } from "../../model/interface"; -import path from "path"; -const root = process.cwd(); - -export async function Job_funCreate(req: MODEL_JOB, file: FormData) { - const authorId = await user_funGetOneUserId(); - - const dataImage: any = file.get("file"); - if (dataImage !== "null") { - const fileName = dataImage.name; - const fileExtension = _.lowerCase(dataImage.name.split(".").pop()); - const fRandomName = v4(fileName) + "." + fileExtension; - - const upload = await prisma.images.create({ - data: { - url: fRandomName, - label: "JOB", - }, - select: { - id: true, - url: true, - }, - }); - - if (!upload) return { status: 400, message: "Gagal upload gambar" }; - const uploadFolder = Buffer.from(await dataImage.arrayBuffer()); - fs.writeFileSync( - path.join(root, `public/job/${upload.url}`), - uploadFolder - ); - const createDataWithImg = await prisma.job.create({ - data: { - title: req.title, - content: req.content, - deskripsi: req.deskripsi, - authorId: authorId, - imagesId: upload.id, - }, - select: { - id: true, - authorId: true, - MasterStatus: { - select: { - name: true, - }, - }, - title: true, - }, - }); - - if (!createDataWithImg) return { status: 400, message: "Gagal Disimpan" }; - revalidatePath("/dev/job/main/status"); - return { - data: createDataWithImg, - status: 201, - message: "Berhasil Disimpan", - }; - } else { - const createDataWithoutImg = await prisma.job.create({ - data: { - title: req.title, - content: req.content, - deskripsi: req.deskripsi, - authorId: authorId, - }, - select: { - id: true, - authorId: true, - MasterStatus: { - select: { - name: true, - }, - }, - title: true, - }, - }); - - if (!createDataWithoutImg) - return { status: 400, message: "Gagal Disimpan" }; - revalidatePath("/dev/job/main/status"); - return { - data: createDataWithoutImg, - status: 201, - message: "Berhasil Disimpan", - }; - } -} diff --git a/src/app_modules/job/fun/create/fun_create_no_file.ts b/src/app_modules/job/fun/create/fun_create_no_file.ts new file mode 100644 index 00000000..0d8e5137 --- /dev/null +++ b/src/app_modules/job/fun/create/fun_create_no_file.ts @@ -0,0 +1,37 @@ +"use server"; + +import { prisma } from "@/app/lib"; +import { user_funGetOneUserId } from "@/app_modules/fun_global"; +import { revalidatePath } from "next/cache"; +import { MODEL_JOB } from "../../model/interface"; + +export async function job_funCreateNoFile({ data }: { data: MODEL_JOB }) { + const authorId = await user_funGetOneUserId(); + + const createNoImage = await prisma.job.create({ + data: { + title: data.title, + content: data.content, + deskripsi: data.deskripsi, + authorId: authorId, + }, + select: { + id: true, + authorId: true, + MasterStatus: { + select: { + name: true, + }, + }, + title: true, + }, + }); + + if (!createNoImage) return { status: 400, message: "Gagal Disimpan" }; + revalidatePath("/dev/job/main/status"); + return { + status: 201, + message: "Berhasil Disimpan", + data: createNoImage, + }; +} diff --git a/src/app_modules/job/fun/create/fun_create_with_file.ts b/src/app_modules/job/fun/create/fun_create_with_file.ts new file mode 100644 index 00000000..2007946f --- /dev/null +++ b/src/app_modules/job/fun/create/fun_create_with_file.ts @@ -0,0 +1,131 @@ +"use server"; + +import prisma from "@/app/lib/prisma"; +import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token"; +import _ from "lodash"; +import { v4 } from "uuid"; +import fs from "fs"; +import { revalidatePath } from "next/cache"; +import { MODEL_JOB } from "../../model/interface"; +import path from "path"; +import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; +import { DIRECTORY_ID } from "@/app/lib"; + +export async function job_funCreateWithFile({ + data, + fileId, +}: { + data: MODEL_JOB; + fileId: string; +}) { + const authorId = await user_funGetOneUserId(); + console.log(authorId); + + const createDataWithoutImg = await prisma.job.create({ + data: { + title: data.title, + content: data.content, + deskripsi: data.deskripsi, + authorId: authorId, + imageId: fileId, + }, + select: { + id: true, + authorId: true, + MasterStatus: { + select: { + name: true, + }, + }, + title: true, + }, + }); + + if (!createDataWithoutImg) return { status: 400, message: "Gagal Disimpan" }; + revalidatePath("/dev/job/main/status"); + return { + data: createDataWithoutImg, + status: 201, + message: "Berhasil Disimpan", + }; + + // const dataImage: any = file.get("file"); + // if (dataImage !== "null") { + // const fileName = dataImage.name; + // const fileExtension = _.lowerCase(dataImage.name.split(".").pop()); + // const fRandomName = v4(fileName) + "." + fileExtension; + + // const upload = await prisma.images.create({ + // data: { + // url: fRandomName, + // label: "JOB", + // }, + // select: { + // id: true, + // url: true, + // }, + // }); + + // if (!upload) return { status: 400, message: "Gagal upload gambar" }; + // const uploadFolder = Buffer.from(await dataImage.arrayBuffer()); + // fs.writeFileSync( + // path.join(root, `public/job/${upload.url}`), + // uploadFolder + // ); + // const createDataWithImg = await prisma.job.create({ + // data: { + // title: req.title, + // content: req.content, + // deskripsi: req.deskripsi, + // authorId: authorId, + // imagesId: upload.id, + // }, + // select: { + // id: true, + // authorId: true, + // MasterStatus: { + // select: { + // name: true, + // }, + // }, + // title: true, + // }, + // }); + + // if (!createDataWithImg) return { status: 400, message: "Gagal Disimpan" }; + // revalidatePath("/dev/job/main/status"); + // return { + // data: createDataWithImg, + // status: 201, + // message: "Berhasil Disimpan", + // }; + // } else { + // const createDataWithoutImg = await prisma.job.create({ + // data: { + // title: req.title, + // content: req.content, + // deskripsi: req.deskripsi, + // authorId: authorId, + // }, + // select: { + // id: true, + // authorId: true, + // MasterStatus: { + // select: { + // name: true, + // }, + // }, + // title: true, + // }, + // }); + + // if (!createDataWithoutImg) + // return { status: 400, message: "Gagal Disimpan" }; + // revalidatePath("/dev/job/main/status"); + // return { + // data: createDataWithoutImg, + // status: 201, + // message: "Berhasil Disimpan", + // }; + // } +} diff --git a/src/app_modules/job/fun/edit/fun_edit_by_id.ts b/src/app_modules/job/fun/edit/fun_edit_by_id.ts index 9d341fd5..ec59bcdb 100644 --- a/src/app_modules/job/fun/edit/fun_edit_by_id.ts +++ b/src/app_modules/job/fun/edit/fun_edit_by_id.ts @@ -6,68 +6,51 @@ import { v4 } from "uuid"; import fs from "fs"; import { MODEL_JOB } from "../../model/interface"; import { revalidatePath } from "next/cache"; +import { RouterJob } from "@/app/lib/router_hipmi/router_job"; -export async function Job_EditById(req: MODEL_JOB, file: FormData) { - // console.log(file); - // console.log(req); - // return { status: 200 }; - - const dataImage: any = file.get("file"); - if (dataImage !== "null") { - const fileName = dataImage.name; - const fileExtension = _.lowerCase(dataImage.name.split(".").pop()); - const fRandomName = v4(fileName) + "." + fileExtension; - - const upload = await prisma.images.create({ - data: { - url: fRandomName, - label: "JOB", - }, - select: { - id: true, - url: true, - }, - }); - - if (!upload) return { status: 400, message: "Gagal upload gambar" }; - const uploadFolder = Buffer.from(await dataImage.arrayBuffer()); - fs.writeFileSync(`./public/job/${upload.url}`, uploadFolder); - +export async function job_EditById({ + data, + imageId, +}: { + data: MODEL_JOB; + imageId?: string; +}) { + if (imageId == undefined) { const updt = await prisma.job.update({ where: { - id: req.id, + id: data.id, }, data: { - title: req.title, - content: req.content, - deskripsi: req.deskripsi, - imagesId: upload.id, + title: data.title, + content: data.content, + deskripsi: data.deskripsi, }, }); - if (!updt) return { status: 400, message: "Gagal Update" }; - revalidatePath("/dev/job/detail/draft"); + revalidatePath(RouterJob.status); + return { status: 200, - message: "Berhasil Disimpan", + message: "Berhasil Update", }; } else { - const updt = await prisma.job.update({ + const updtWithFile = await prisma.job.update({ where: { - id: req.id, + id: data.id, }, data: { - title: req.title, - content: req.content, - deskripsi: req.deskripsi, + title: data.title, + content: data.content, + deskripsi: data.deskripsi, + imageId: imageId, }, }); + if (!updtWithFile) return { status: 400, message: "Gagal Update" }; + revalidatePath(RouterJob.status); - if (!updt) return { status: 400, message: "Gagal Update" }; - revalidatePath("/dev/job/detail/draft"); return { status: 200, - message: "Berhasil Disimpan", + message: "Berhasil Update", }; } } diff --git a/src/app_modules/job/fun/get/get_two_for_home_view.ts b/src/app_modules/job/fun/get/get_two_for_home_view.ts index e1a0fd6a..fe9db5d6 100644 --- a/src/app_modules/job/fun/get/get_two_for_home_view.ts +++ b/src/app_modules/job/fun/get/get_two_for_home_view.ts @@ -10,6 +10,7 @@ export async function job_getTwoForHomeView() { }, where: { isActive: true, + masterStatusId: "1" }, select: { id: true, diff --git a/src/app_modules/job/fun/index.ts b/src/app_modules/job/fun/index.ts new file mode 100644 index 00000000..3e4cf25f --- /dev/null +++ b/src/app_modules/job/fun/index.ts @@ -0,0 +1,5 @@ +import { job_funCreateNoFile } from "./create/fun_create_no_file"; +import { job_funCreateWithFile } from "./create/fun_create_with_file"; + +export { job_funCreateWithFile }; +export { job_funCreateNoFile }; diff --git a/src/app_modules/job/model/interface.ts b/src/app_modules/job/model/interface.ts index 46548408..9ded22d2 100644 --- a/src/app_modules/job/model/interface.ts +++ b/src/app_modules/job/model/interface.ts @@ -1,11 +1,13 @@ import { MODEL_USER } from "@/app_modules/home/model/interface"; -import { MODEL_IMAGES, MODEL_NEW_DEFAULT_MASTER } from "@/app_modules/model_global/interface"; +import { + MODEL_NEW_DEFAULT_MASTER +} from "@/app_modules/model_global/interface"; export interface MODEL_JOB { id: string; - title: string + title: string; content: string; - deskripsi: string + deskripsi: string; isActive: boolean; isArsip: boolean; createdAt: Date; @@ -13,8 +15,7 @@ export interface MODEL_JOB { catatan: string; authorId: string; Author: MODEL_USER; - Images: MODEL_IMAGES - imagesId: string - MasterStatus: MODEL_NEW_DEFAULT_MASTER - masterStatusId: string + MasterStatus: MODEL_NEW_DEFAULT_MASTER; + masterStatusId: string; + imageId: string; } diff --git a/src/app_modules/job/non_user_view/view.tsx b/src/app_modules/job/non_user_view/view.tsx index e98a6a23..82d59658 100644 --- a/src/app_modules/job/non_user_view/view.tsx +++ b/src/app_modules/job/non_user_view/view.tsx @@ -1,16 +1,28 @@ "use client"; -import { Card, Center, Image, Overlay, Stack, Text, Title } from "@mantine/core"; +import { + Card, + Center, + Image, + Overlay, + Stack, + Text, + Title, +} from "@mantine/core"; import ComponentJob_DetailData from "../component/detail/detail_data"; import { RouterJob } from "@/app/lib/router_hipmi/router_job"; import { data } from "autoprefixer"; import { MODEL_JOB } from "../model/interface"; -import { AccentColor, MainColor } from "@/app_modules/_global/color/color_pallet"; +import { + AccentColor, + MainColor, +} from "@/app_modules/_global/color/color_pallet"; +import { APIs } from "@/app/lib"; export default function Job_NonUserView({ data }: { data: MODEL_JOB }) { return ( <> -
+
- {data.imagesId ? ( + {data.imageId ? ( ) : ( diff --git a/src/app_modules/notifikasi/fun/create/create_notif_to_admin.tsx b/src/app_modules/notifikasi/fun/create/create_notif_to_admin.ts similarity index 100% rename from src/app_modules/notifikasi/fun/create/create_notif_to_admin.tsx rename to src/app_modules/notifikasi/fun/create/create_notif_to_admin.ts diff --git a/src/app_modules/notifikasi/fun/create/create_notif_to_user.tsx b/src/app_modules/notifikasi/fun/create/create_notif_to_user.ts similarity index 100% rename from src/app_modules/notifikasi/fun/create/create_notif_to_user.tsx rename to src/app_modules/notifikasi/fun/create/create_notif_to_user.ts diff --git a/src/app_modules/notifikasi/fun/index.ts b/src/app_modules/notifikasi/fun/index.ts new file mode 100644 index 00000000..a8995e3c --- /dev/null +++ b/src/app_modules/notifikasi/fun/index.ts @@ -0,0 +1,9 @@ +import notifikasiToAdmin_funCreate from "./create/create_notif_to_admin"; +import notifikasiToUser_funCreate from "./create/create_notif_to_user"; +import { notifikasiToUser_CreateGroupCollaboration } from "./create/create_notif_to_user_collaboration"; +import { notifikasiToUser_CreateKabarDonasi } from "./create/create_notif_to_user_kabar_donasi"; + +export { notifikasiToAdmin_funCreate }; +export { notifikasiToUser_CreateGroupCollaboration }; +export { notifikasiToUser_CreateKabarDonasi }; +export { notifikasiToUser_funCreate }; diff --git a/src/app_modules/notifikasi/ui/ui_notifiaksi.tsx b/src/app_modules/notifikasi/ui/ui_notifiaksi.tsx index 1083ecb7..8a6c84ba 100644 --- a/src/app_modules/notifikasi/ui/ui_notifiaksi.tsx +++ b/src/app_modules/notifikasi/ui/ui_notifiaksi.tsx @@ -21,17 +21,15 @@ import { gs_vote_status, } from "@/app_modules/vote/global_state"; import { Box, Button, Center, Flex, Stack } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; import { useAtom } from "jotai"; -import _, { find } from "lodash"; +import _ from "lodash"; import { ScrollOnly } from "next-scroll-loader"; import { useState } from "react"; -import { ComponentNotifikasi_CardSkeleton } from "../component"; import { ComponentNotifiaksi_CardView } from "../component/card_view"; import notifikasi_getByUserId from "../fun/get/get_notifiaksi_by_id"; -import { MODEL_NOTIFIKASI } from "../model/interface"; -import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; import { gs_notifikasi_kategori_app } from "../lib"; -import { useShallowEffect } from "@mantine/hooks"; +import { MODEL_NOTIFIKASI } from "../model/interface"; export function Notifikasi_UiView({ listNotifikasi, diff --git a/src/app_modules/zCoba/ui_coba_upload_file.tsx b/src/app_modules/zCoba/ui_coba_upload_file.tsx new file mode 100644 index 00000000..7877bef7 --- /dev/null +++ b/src/app_modules/zCoba/ui_coba_upload_file.tsx @@ -0,0 +1,219 @@ +import { TokenStorage } from "@/app/lib/token"; +import { + Box, + Button, + Card, + Center, + FileButton, + Image, + Paper, + Stack, + Text, +} from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; +import { IconCamera, IconUpload } from "@tabler/icons-react"; +import { useState } from "react"; +import { AccentColor, MainColor } from "../_global/color"; +import { + ComponentGlobal_NotifikasiBerhasil, + ComponentGlobal_NotifikasiPeringatan, +} from "../_global/notif_global"; +import { DIRECTORY_ID } from "@/app/lib"; +import { funGlobal_UploadToStorage } from "../_global/fun"; + +export default function Coba_UploadFile() { + const [data, setData] = useState(); + const [file, setFile] = useState(null); + const [images, setImages] = useState(); + + async function loadListDir(setData: any) { + const rootDirEndPoint = await fetch( + "https://wibu-storage.wibudev.com/api/dir/root/list", + { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${TokenStorage.value}`, + }, + } + ); + const dataDir = await rootDirEndPoint.json(); + // console.log(dataDir); + + const dirHipmiEndPoint = await fetch( + `https://wibu-storage.wibudev.com/api/dir/${dataDir.dirs[0].id}/list`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${TokenStorage.value}`, + }, + } + ); + + const hipmiDir = await dirHipmiEndPoint.json(); + // console.log(hipmiDir.dirs[0]); + setData(hipmiDir.dirs[0]); + } + + // async function CcekToken() { + // const rootDirEndPoint = await fetch( + // "https://wibu-storage.wibudev.com/api/dir/root/list", + // { + // method: "GET", + // headers: { + // "Content-Type": "application/json", + // Authorization: `Bearer ${process.env.WS_APIKEY}`, + // }, + // } + // ); + // const dataDir = await rootDirEndPoint.json(); + // console.log(dataDir); + // } + + useShallowEffect(() => { + loadListDir(setData); + // CekToken() + }, [setData]); + + const [imagesId, setImagesId] = useState(""); + return ( + + + + {images ? ( + + ) : ( + + + + + Upload Gambar + + + + )} + + { + try { + const buffer = URL.createObjectURL( + new Blob([new Uint8Array(await files.arrayBuffer())]) + ); + setImages(buffer); + setFile(files); + } catch (error) { + console.log(error); + } + }} + accept="image/png,image/jpeg" + > + {(props) => ( + + )} + + + +
+ +
+
+ {/* +
{JSON.stringify(data, null, 2)}
+
*/} + + {/* + Foto + */} +
+ ); +} + +async function coba_ButtonFileUpload({ + file, + dirId, + onDone, +}: { + file: File; + dirId: string; + onDone: () => void; +}) { + if (!file) return ComponentGlobal_NotifikasiPeringatan("Tidak ada file"); + + const allowedMimeTypes = [ + "image/png", + "image/jpeg", + "image/gif", + "text/csv", + "application/pdf", + "application/msword", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "application/vnd.ms-excel", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "text/plain", + ]; + + if (!allowedMimeTypes.includes(file.type)) + return ComponentGlobal_NotifikasiPeringatan("File tidak sesuai"); + + if (file.size > 100 * 1024 * 1024) + return ComponentGlobal_NotifikasiPeringatan("File terlalu besar"); + + const formData = new FormData(); + formData.append("file", file); + formData.append("dirId", dirId); + + try { + const res = await fetch("https://wibu-storage.wibudev.com/api/upload", { + method: "POST", + body: formData, + headers: { + Authorization: `Bearer ${TokenStorage.value}`, + }, + }); + + const dataRes = await res.json(); + + if (res.ok) { + console.log("File Sukses Di Upload"); + console.log(dataRes); + } else { + const errorText = await res.text(); + console.log("jika error", errorText); + } + } catch (error) { + console.error("Upload error:", error); + } finally { + onDone(); + } +}