diff --git a/src/app/api/document/route.ts b/src/app/api/document/route.ts index d8ef815..8576245 100644 --- a/src/app/api/document/route.ts +++ b/src/app/api/document/route.ts @@ -125,6 +125,11 @@ export async function GET(request: Request) { updatedAt: true } } + }, + orderBy: { + DivisionDocumentFolderFile: { + createdAt: 'desc' + } } }) @@ -169,7 +174,7 @@ export async function GET(request: Request) { updatedAt: true }, orderBy: { - name: 'asc' + createdAt: 'desc' } }) @@ -185,7 +190,7 @@ export async function GET(request: Request) { allData.push(...formatDataShare) } - const formatData = _.orderBy(allData, ['category', 'name'], ['desc', 'asc']); + const formatData = _.orderBy(allData, ['category', 'createdAt'], ['desc', 'asc']); let pathNow = path let jalur = [] diff --git a/src/app/page.tsx b/src/app/page.tsx index 4bec541..132e428 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,8 +1,4 @@ -import { pwd_key_config } from "@/module/_global"; import { funDetectCookies, ViewLogin } from "@/module/auth"; -import { unsealData } from "iron-session"; -import _ from "lodash"; -import { cookies } from "next/headers"; import { redirect } from "next/navigation"; export default async function Home() { diff --git a/src/module/auth/login/view/view_login.tsx b/src/module/auth/login/view/view_login.tsx index 8fba247..4d6e0af 100644 --- a/src/module/auth/login/view/view_login.tsx +++ b/src/module/auth/login/view/view_login.tsx @@ -1,28 +1,14 @@ "use client" import { LayoutLogin, WARNA } from "@/module/_global"; -import { - Box, - Button, - Checkbox, - Image, - rem, - Stack, - Text, - TextInput, - Title, -} from "@mantine/core"; -import { useRouter } from "next/navigation"; -import React, { useState } from "react"; +import { Box, Button, Stack, Text, TextInput } from "@mantine/core"; +import { useFocusTrap } from "@mantine/hooks"; +import { useState } from "react"; import toast from "react-hot-toast"; import ViewVerification from "../../varification/view/view_verification"; -import { useFocusTrap } from "@mantine/hooks"; function ViewLogin() { const focusTrapRef = useFocusTrap() - const router = useRouter() - const textInfo = - "Kami akan mengirimkan kode verifikasi melalui WhatsApp untuk mengonfirmasi nomor Anda."; - + const textInfo = "Kami akan mengirimkan kode verifikasi melalui WhatsApp untuk mengonfirmasi nomor Anda."; const [isPhone, setPhone] = useState("") const [isOTP, setOTP] = useState(null) const [isValPhone, setValPhone] = useState(null) @@ -37,46 +23,50 @@ function ViewLogin() { if (isPhone.toString().length <= 11) return toast.error('Nomor telepon tidak valid') - const cek = await fetch('/api/auth/login', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ phone: isPhone }) - }) - const cekLogin = await cek.json() - - if (cekLogin.success) { - const code = Math.floor(Math.random() * 1000) + 1000 + try { setLoading(true) - try { - const res = await fetch(`https://wa.wibudev.com/code?nom=${cekLogin.phone}&text=*DARMASABA*%0A%0A - JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`).then( - async (res) => { - if (res.status == 200) { - setValPhone(cekLogin.phone) - setOTP(code) - setUser(cekLogin.id) - setVerif(true) - setLoading(false) - toast.success('Kode verifikasi telah dikirim') - } else { - console.error(res.status) - toast.error('Internal Server Error') - setLoading(false) + const cek = await fetch('/api/auth/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ phone: isPhone }) + }) + const cekLogin = await cek.json() + if (cekLogin.success) { + const code = Math.floor(Math.random() * 1000) + 1000 + try { + const res = await fetch(`https://wa.wibudev.com/code?nom=${cekLogin.phone}&text=*DARMASABA*%0A%0A + JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`).then( + async (res) => { + if (res.status == 200) { + setValPhone(cekLogin.phone) + setOTP(code) + setUser(cekLogin.id) + setVerif(true) + toast.success('Kode verifikasi telah dikirim') + } else { + console.error(res.status) + toast.error('Internal Server Error') + } } - } - ) - } catch (error) { - console.error(error) - toast.error('Internal Server Error') - }finally{ - setLoading(false) + ) + } catch (error) { + console.error(error) + toast.error('Internal Server Error') + } + } else { + return toast.error(cekLogin.message) } - } else { - return toast.error(cekLogin.message) + } catch (error) { + console.error(error) + toast.error('Internal Server Error') + } finally { + setLoading(false) } + + } if (isVerif) return diff --git a/src/module/document/ui/drawer_cut_documents.tsx b/src/module/document/ui/drawer_cut_documents.tsx index 16a70c0..161111a 100644 --- a/src/module/document/ui/drawer_cut_documents.tsx +++ b/src/module/document/ui/drawer_cut_documents.tsx @@ -8,11 +8,11 @@ import toast from "react-hot-toast"; import { FcFolder } from "react-icons/fc"; import { GoChevronRight } from "react-icons/go"; import { MdFolder } from "react-icons/md"; +import { useWibuRealtime } from "wibu-realtime"; import { funCreateFolder, funGetAllDocument } from "../lib/api_document"; import { IDataDocument, IFormDetailMoreItem, IJalurItem, } from "../lib/type_document"; -import { useWibuRealtime } from "wibu-realtime"; -export default function DrawerCutDocuments({ category, onChoosePath, data, }: { category: string; data: IFormDetailMoreItem[]; onChoosePath: (val: string) => void; }) { +export default function DrawerCutDocuments({ category, loadingAction, onChoosePath, data, }: { category: string; loadingAction: boolean; data: IFormDetailMoreItem[]; onChoosePath: (val: string) => void; }) { const [opened, setOpened] = useState(false); const param = useParams<{ id: string }>(); const [path, setPath] = useState("home"); @@ -100,6 +100,7 @@ export default function DrawerCutDocuments({ category, onChoosePath, data, }: { - + diff --git a/src/module/document/ui/drawer_more.tsx b/src/module/document/ui/drawer_more.tsx index 56c6d3d..494132a 100644 --- a/src/module/document/ui/drawer_more.tsx +++ b/src/module/document/ui/drawer_more.tsx @@ -2,15 +2,15 @@ import { keyWibu, LayoutDrawer, TEMA } from "@/module/_global"; import { useHookstate } from "@hookstate/core"; import { Box, Flex, SimpleGrid, Stack, Text } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; -import { useParams } from "next/navigation"; +import { useParams, useSearchParams } from "next/navigation"; import { useState } from "react"; import toast from "react-hot-toast"; import { LuFolders, LuFolderSymlink } from "react-icons/lu"; +import { useWibuRealtime } from "wibu-realtime"; import { funCopyDocument, funMoveDocument } from "../lib/api_document"; import { IDataDocument } from "../lib/type_document"; import { globalRefreshDocument } from "../lib/val_document"; import DrawerCutDocuments from "./drawer_cut_documents"; -import { useWibuRealtime } from "wibu-realtime"; export default function DrawerMore({ data }: { data: IDataDocument[] }) { const [isCut, setIsCut] = useState(false) @@ -19,20 +19,31 @@ export default function DrawerMore({ data }: { data: IDataDocument[] }) { const param = useParams<{ id: string }>() const [forbidCopy, setForbidCopy] = useState(true) const tema = useHookstate(TEMA) + const [loadingMove, setLoadingMove] = useState(false) + const [loadingCopy, setLoadingCopy] = useState(false) const [dataRealTime, setDataRealtime] = useWibuRealtime({ WIBU_REALTIME_TOKEN: keyWibu, project: "sdm" }) + const searchParams = useSearchParams() + const pathAwal = searchParams.get('path') async function onMoveItem(path: string) { try { + setLoadingMove(true) const res = await funMoveDocument({ path, dataItem: data }) if (res.success) { - setDataRealtime([{ - category: "division-document", - id: path, - }]) + setDataRealtime([ + { + category: "division-document", + id: path, + }, + { + category: "division-document", + id: pathAwal, + } + ]) toast.success(res.message) refresh.set(true) } else { @@ -41,13 +52,16 @@ export default function DrawerMore({ data }: { data: IDataDocument[] }) { } catch (error) { console.error(error) toast.error("Gagal memindahkan item, coba lagi nanti") + } finally { + setLoadingMove(false) + setIsCut(false) } - setIsCut(false) } async function onCopyItem(path: string) { try { + setLoadingCopy(true) const res = await funCopyDocument({ idDivision: param.id, path, dataItem: data }) if (res.success) { setDataRealtime([{ @@ -62,8 +76,10 @@ export default function DrawerMore({ data }: { data: IDataDocument[] }) { } catch (error) { console.error(error) toast.error("Gagal memindahkan item, coba lagi nanti") + } finally { + setLoadingCopy(false) + setIsCopy(false) } - setIsCopy(false) } @@ -108,11 +124,11 @@ export default function DrawerMore({ data }: { data: IDataDocument[] }) { setIsCut(false)} title={'Pilih Lokasi Pemindahan'} size="lg"> - { onMoveItem(val) }} category="move" /> + { onMoveItem(val) }} category="move" /> setIsCopy(false)} title={'Pilih Lokasi Salin'} size="lg"> - { onCopyItem(val) }} category="copy" /> + { onCopyItem(val) }} category="copy" /> ); diff --git a/src/module/document/ui/navbar_document_division.tsx b/src/module/document/ui/navbar_document_division.tsx index 7fe8071..c6e929a 100644 --- a/src/module/document/ui/navbar_document_division.tsx +++ b/src/module/document/ui/navbar_document_division.tsx @@ -18,13 +18,13 @@ import { HiMenu } from "react-icons/hi"; import { LuShare2 } from "react-icons/lu"; import { MdClose, MdOutlineMoreHoriz } from "react-icons/md"; import { RiListCheck } from "react-icons/ri"; +import { useWibuRealtime } from "wibu-realtime"; import { funDeleteDocument, funGetAllDocument, funRenameDocument, } from "../lib/api_document"; import { IDataDocument, IJalurItem } from "../lib/type_document"; import { globalRefreshDocument } from "../lib/val_document"; import DrawerMenuDocumentDivision from "./drawer_menu_document_division"; import DrawerMore from "./drawer_more"; import DrawerShareDocument from "./drawer_share_document"; -import { useWibuRealtime } from "wibu-realtime"; export default function NavbarDocumentDivision() { const router = useRouter(); @@ -52,6 +52,8 @@ export default function NavbarDocumentDivision() { const isMobile2 = useMediaQuery("(max-width: 496px)"); const tema = useHookstate(TEMA); const [loading, setLoading] = useState(true); + const [loadingRename, setLoadingRename] = useState(false); + const [loadingDelete, setLoadingDelete] = useState(false); const [dataRealTime, setDataRealtime] = useWibuRealtime({ WIBU_REALTIME_TOKEN: keyWibu, project: "sdm" @@ -138,8 +140,9 @@ export default function NavbarDocumentDivision() { }; async function onConfirmDelete(val: boolean) { - if (val) { - try { + try { + if (val) { + setLoadingDelete(true) const respon = await funDeleteDocument(selectedFiles); if (respon.success) { getOneData(false); @@ -150,19 +153,20 @@ export default function NavbarDocumentDivision() { } else { toast.error(respon.message); } - } catch (error) { - console.error(error); - toast.error("Gagal menghapus item, coba lagi nanti"); + handleBatal(); } - - handleBatal(); + } catch (error) { + console.error(error); + toast.error("Gagal menghapus item, coba lagi nanti"); + } finally { + setLoadingDelete(false) + setIsDelete(false); } - - setIsDelete(false); } async function onRenameSubmit() { try { + setLoadingRename(true); const res = await funRenameDocument(bodyRename); if (res.success) { setDataRealtime([{ @@ -176,11 +180,13 @@ export default function NavbarDocumentDivision() { } catch (error) { console.error(error); toast.error("Gagal mengganti nama item, coba lagi nanti"); + } finally { + setLoadingRename(false) + setSelectedFiles([]); + setDariSelectAll(false); + setRename(false); } - setSelectedFiles([]); - setDariSelectAll(false); - setRename(false); } useShallowEffect(() => { @@ -802,6 +808,7 @@ export default function NavbarDocumentDivision() { {/* MODAL KONFIRMASI DELETE */} setIsDelete(false)} description="Apakah Anda yakin ingin menghapus item?" @@ -861,6 +868,7 @@ export default function NavbarDocumentDivision() {