import React, { useEffect, useState } from "react"; import CollectionSelection from "@/components/InputSelect/CollectionSelection"; import TagSelection from "@/components/InputSelect/TagSelection"; import TextInput from "@/components/TextInput"; import unescapeString from "@/lib/client/unescapeString"; import useLinkStore from "@/store/links"; import { LinkIncludingShortenedCollectionAndTags } from "@/types/global"; import toast from "react-hot-toast"; import Link from "next/link"; import Modal from "../Modal"; type Props = { onClose: Function; }; export default function EditLinkModal({ onClose }: Props) { const { updateLink, updateLinksById } = useLinkStore(); const [submitLoader, setSubmitLoader] = useState(false); const [updatedValues, setUpdatedValues] = useState>(); const setCollection = (e: any) => { if (e?.__isNew__) e.value = null; setUpdatedValues({ ...updatedValues, collection: { id: e?.value, name: e?.label, ownerId: e?.ownerId }, }); }; const setTags = (e: any) => { const tagNames = e.map((e: any) => { return { name: e.label }; }); setUpdatedValues({ ...updatedValues, tags: tagNames }); }; const submit = async () => { if (!submitLoader) { setSubmitLoader(true); let response; const load = toast.loading("Updating..."); response = await updateLinksById(user); toast.dismiss(load); if (response.ok) { toast.success(`Updated!`); onClose(); } else toast.error(response.data as string); setSubmitLoader(false); return response; } }; return (

Edit Link

{link.url ? (

{shortendURL}

) : undefined}

Name

setLink({ ...link, name: e.target.value })} placeholder="e.g. Example Link" className="bg-base-200" />
{/*
*/}

Collection

{link.collection.name ? ( ) : null}

Tags

{ return { label: e.name, value: e.id }; })} />

Description