diff --git a/src/app/(admin)/admin/components/Icons.tsx b/src/app/(admin)/admin/components/Icons.tsx new file mode 100644 index 00000000..30762305 --- /dev/null +++ b/src/app/(admin)/admin/components/Icons.tsx @@ -0,0 +1,43 @@ +export const DashboardIcon = () => { + return ( + + + + + + + ); +}; diff --git a/src/app/(admin)/admin/components/Sidebar.tsx b/src/app/(admin)/admin/components/Sidebar.tsx index 65ef5ab2..c098767a 100644 --- a/src/app/(admin)/admin/components/Sidebar.tsx +++ b/src/app/(admin)/admin/components/Sidebar.tsx @@ -2,9 +2,9 @@ import Link from "next/link"; import Image from "next/image"; import { Session } from "next-auth"; import { P } from "@/app/_components/global/Text"; -import { MdDashboard, MdOutlineDashboard } from "react-icons/md"; import { protectedRoutes } from "@/utils/protectedRoutes"; import { usePathname } from "next/navigation"; +import { DashboardIcon } from "./Icons"; type navbarParam = { nav: boolean; @@ -47,45 +47,7 @@ export function Sidebar({ nav, session }: navbarParam) { href={"/admin"} className="group flex items-center rounded-lg p-2 text-base font-normal text-primary-400 hover:bg-red-100 transition-all" > - - - - - - +

Dashboard

diff --git a/src/app/(admin)/admin/link/_components/Icons.tsx b/src/app/(admin)/admin/link/_components/Icons.tsx new file mode 100644 index 00000000..a5848294 --- /dev/null +++ b/src/app/(admin)/admin/link/_components/Icons.tsx @@ -0,0 +1,315 @@ +export const StatsIcon = () => { + return ( + + + + + ); +}; + +export const DateIcon = () => { + return ( + + + + + + + + + + + + + ); +}; + +export const UserIcon = () => { + return ( + + + + + + ); +}; + +export const CopyIcon = () => { + return ( + + + + + + + + + ); +}; + +export const EditIcon = () => { + return ( + + + + + + ); +}; + +export const DeleteIcon = () => { + return ( + + + + + + + + ); +}; + +export const PlusIcon = () => { + return ( + + + + + ); +}; diff --git a/src/app/(admin)/admin/link/_components/LinkFigure.tsx b/src/app/(admin)/admin/link/_components/LinkFigure.tsx index 102621d3..7d422311 100644 --- a/src/app/(admin)/admin/link/_components/LinkFigure.tsx +++ b/src/app/(admin)/admin/link/_components/LinkFigure.tsx @@ -8,6 +8,14 @@ import Modal from "./Modal"; import { useState } from "react"; import { toast } from "sonner"; import { deleteLink } from "../action"; +import { + CopyIcon, + DateIcon, + DeleteIcon, + EditIcon, + StatsIcon, + UserIcon, +} from "./Icons"; export default function LinkFigure({ link }: { link: LinkWithCountAndUser }) { const [isOpenModal, setIsOpenModal] = useState(false); @@ -48,149 +56,17 @@ export default function LinkFigure({ link }: { link: LinkWithCountAndUser }) {

{link.target_url}

- - - - +

{link.count?.click_count}

- - - - - - - - - - - - +

{stringifyDate(link.created_at)}

- - - - - +

{link.user.name}

@@ -201,60 +77,10 @@ export default function LinkFigure({ link }: { link: LinkWithCountAndUser }) {
diff --git a/src/app/(admin)/admin/link/_components/LinkForm.tsx b/src/app/(admin)/admin/link/_components/LinkForm.tsx index cebfe7d4..1afbebf3 100644 --- a/src/app/(admin)/admin/link/_components/LinkForm.tsx +++ b/src/app/(admin)/admin/link/_components/LinkForm.tsx @@ -1,27 +1,14 @@ "use client"; -import { TextField } from "@/app/_components/global/Input"; -import { useRef, useState } from "react"; -import { toast } from "sonner"; -import FormButton from "./part/SubmitButton"; -import { addLink } from "../action"; +import { useState } from "react"; import { H2, P } from "@/app/_components/global/Text"; import { PrimaryButton } from "@/app/_components/global/Button"; import ModalCreate from "./ModalCreate"; +import { PlusIcon } from "./Icons"; export default function LinkForm() { - const ref = useRef(null); - const [password, setPassword] = useState(false); const [isOpenModal, setIsOpenModal] = useState(false); - async function create(formdata: FormData) { - const toastId = toast.loading("Loading..."); - const result = await addLink(formdata); - if (!result.error) { - toast.success(result.message, { id: toastId }); - ref.current?.reset(); - } - toast.error(result.message, { id: toastId }); - } + return ( <>
@@ -32,74 +19,13 @@ export default function LinkForm() {
setIsOpenModal(true)}>
- - - - + Create Link
{isOpenModal && } - {/*
-
-

Buat URL

-
- - - {password && ( - - )} - - setPassword(!password)} - /> - - -
-
- -
-
-
*/} ); } diff --git a/src/app/(admin)/admin/link/_components/Modal.tsx b/src/app/(admin)/admin/link/_components/Modal.tsx index b2d0ebdd..50efdb9c 100644 --- a/src/app/(admin)/admin/link/_components/Modal.tsx +++ b/src/app/(admin)/admin/link/_components/Modal.tsx @@ -2,7 +2,7 @@ import { H3 } from "@/app/_components/global/Text"; import { FaX } from "react-icons/fa6"; import { TextField } from "@/app/_components/global/Input"; import { LinkWithCountAndUser } from "@/types/entityRelations"; -import { Dispatch, SetStateAction } from "react"; +import { Dispatch, SetStateAction, useState } from "react"; import { toast } from "sonner"; import { updateLink } from "../action"; import FormButton from "./part/SubmitButton"; @@ -14,6 +14,7 @@ export default function Modal({ setIsOpenModal: Dispatch>; link?: LinkWithCountAndUser; }) { + const [password, setPassword] = useState(!!link?.password); async function update(formdata: FormData) { const toastId = toast.loading("Loading..."); const result = await updateLink(formdata); @@ -21,7 +22,7 @@ export default function Modal({ toast.error(result.message, { id: toastId }); } return ( -
+
@@ -51,11 +52,25 @@ export default function Modal({ placeholder="mylink" required /> - + {password && ( + + )} + + setPassword(!password)} + /> + +
diff --git a/src/app/(admin)/admin/link/_components/ModalCreate.tsx b/src/app/(admin)/admin/link/_components/ModalCreate.tsx index 3ef9c788..bc92bbf9 100644 --- a/src/app/(admin)/admin/link/_components/ModalCreate.tsx +++ b/src/app/(admin)/admin/link/_components/ModalCreate.tsx @@ -21,10 +21,10 @@ export default function ModalCreate({ const result = await addLink(formdata); if (!result.error) { toast.error(result.message, { id: toastId }); - ref.current?.reset(); + return ref.current?.reset(); } toast.success(result.message, { id: toastId }); - setIsOpenModal(true); + setIsOpenModal(false); } return (
diff --git a/src/app/(admin)/admin/link/action.ts b/src/app/(admin)/admin/link/action.ts index aa0430f5..93686e59 100644 --- a/src/app/(admin)/admin/link/action.ts +++ b/src/app/(admin)/admin/link/action.ts @@ -47,7 +47,8 @@ export async function updateLink(data: FormData) { let slug = data.get("slug") as string; let id = data.get("id") as string; try { - if (data.get("password")) { + if (!data.get("private_url")) hashedpass = null; + else { hashedpass = createHash("md5") .update((data.get("password") as string) || "") .digest("hex"); @@ -63,7 +64,7 @@ export async function updateLink(data: FormData) { data: { slug, target_url: data.get("target_url") as string, - password: hashedpass ? hashedpass : undefined, + password: hashedpass, }, }); if (!update) throw new Error("Update failed");