From d62b1266e409e4a0a4d51298515b2062e760fb66 Mon Sep 17 00:00:00 2001 From: pheralb Date: Mon, 18 Mar 2024 16:10:37 +0000 Subject: [PATCH] Add delete link + update link improvements & fix search bar --- src/app/dashboard/page.tsx | 32 +++++-- src/components/links/card-link.tsx | 18 +++- src/components/links/create-link.tsx | 10 ++- src/components/links/delete-link.tsx | 122 +++++++++++++++++++++++++++ src/components/links/edit-link.tsx | 41 ++++++++- src/components/links/search-link.tsx | 2 + 6 files changed, 209 insertions(+), 16 deletions(-) create mode 100644 src/components/links/delete-link.tsx diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index 9fbe730..6229723 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -1,8 +1,17 @@ +import type { Metadata } from "next"; + import { getLinksByUser } from "@/server/queries"; import CardLink from "@/components/links/card-link"; import LinksLimit from "@/components/links/links-limit"; import SearchLinks from "@/components/links/search-link"; +import { CreateLink } from "@/components/links/create-link"; +import { Button } from "@/ui/button"; +import { PackageOpenIcon, PlusIcon } from "lucide-react"; + +export const metadata: Metadata = { + title: "Dashboard", +}; const DashboardPage = async ({ searchParams, @@ -18,6 +27,11 @@ const DashboardPage = async ({ return
Error
; } + const filteredLinks = data.links.filter((link) => { + if (!query) return true; + return link.slug.includes(query); + }); + return ( <>
@@ -25,20 +39,28 @@ const DashboardPage = async ({
- {data.links + {filteredLinks .sort((a, b) => { return ( new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime() ); }) - .filter((link) => { - if (!query) return true; - return link.slug.includes(query); - }) .map((link) => { return ; })}
+ {filteredLinks.length === 0 && ( +
+ +

No slug found.

+ + + +
+ )} ); }; diff --git a/src/components/links/card-link.tsx b/src/components/links/card-link.tsx index c29255c..a1063cc 100644 --- a/src/components/links/card-link.tsx +++ b/src/components/links/card-link.tsx @@ -3,8 +3,9 @@ import type { Links } from "@prisma/client"; import ExternalLink from "@/ui/external-link"; import { formatDate } from "@/utils/formatDate"; import EditLink from "./edit-link"; -import { CopyIcon, SettingsIcon } from "lucide-react"; +import { CopyIcon, SettingsIcon, TrashIcon } from "lucide-react"; import CopyLink from "./copy-link"; +import DeleteLink from "./delete-link"; interface CardLinkProps { linkInfo: Links; @@ -35,6 +36,14 @@ const CardLink = ({ linkInfo }: CardLinkProps) => { } link={linkInfo} /> + + + + } + />

{ > {linkInfo.url}

-
-

- {formatDate(linkInfo.createdAt)} +

+

+ {linkInfo.description}

+

{formatDate(linkInfo.createdAt)}

); diff --git a/src/components/links/create-link.tsx b/src/components/links/create-link.tsx index d90fe50..d43ecf6 100644 --- a/src/components/links/create-link.tsx +++ b/src/components/links/create-link.tsx @@ -37,6 +37,7 @@ import { LoaderIcon, RocketIcon, ShuffleIcon } from "lucide-react"; interface CreateLinkProps { children: ReactNode; + slug?: string; } export function CreateLink(props: CreateLinkProps) { @@ -50,7 +51,7 @@ export function CreateLink(props: CreateLinkProps) { resolver: zodResolver(CreateLinkSchema), defaultValues: { url: "", - slug: "", + slug: props.slug ?? "", description: "", }, }); @@ -94,10 +95,11 @@ export function CreateLink(props: CreateLinkProps) { duration: 10000, closeButton: true, }); + + setOpen(false); } catch (error) { toast.error("An unexpected error has occurred. Please try again later."); } finally { - setOpen(false); setError(false); setMessage(""); setLoading(false); @@ -152,8 +154,8 @@ export function CreateLink(props: CreateLinkProps) { /> + + + + + + + + ); +}; + +export default DeleteLink; diff --git a/src/components/links/edit-link.tsx b/src/components/links/edit-link.tsx index ff90676..753676c 100644 --- a/src/components/links/edit-link.tsx +++ b/src/components/links/edit-link.tsx @@ -21,7 +21,7 @@ import { DialogTrigger, } from "@/ui/dialog"; import { Button } from "@/ui/button"; -import { LoaderIcon, SaveIcon } from "lucide-react"; +import { LoaderIcon, LockIcon, LockOpenIcon, SaveIcon } from "lucide-react"; import Alert from "@/ui/alert"; import { Form, @@ -33,6 +33,7 @@ import { } from "@/ui/form"; import { Input, Textarea } from "@/ui/input"; import { EditLinkSchema } from "@/server/schemas"; +import { Popover, PopoverContent, PopoverTrigger } from "@/ui/popover"; interface EditLinkProps { trigger: ReactNode; @@ -44,11 +45,13 @@ const EditLink = (props: EditLinkProps) => { const [open, setOpen] = useState(false); const [message, setMessage] = useState(""); const [isError, setError] = useState(false); + const [unlockSlug, setUnlockSlug] = useState(true); // Main form: const form = useForm>({ resolver: zodResolver(EditLinkSchema), defaultValues: { + id: props.link.id, url: props.link.url, slug: props.link.slug, description: props.link.description ?? "", @@ -124,8 +127,41 @@ const EditLink = (props: EditLinkProps) => { + {unlockSlug ? ( + + + + + +

+ Editing the custom link will remove access from + the previous link and it will be available to + everyone. Are you sure you want to continue? +

+ +
+
+ ) : ( + + )} @@ -142,7 +178,6 @@ const EditLink = (props: EditLinkProps) => {