diff --git a/components/InputSelect/CollectionSelection.tsx b/components/InputSelect/CollectionSelection.tsx index 71dc075..07532e6 100644 --- a/components/InputSelect/CollectionSelection.tsx +++ b/components/InputSelect/CollectionSelection.tsx @@ -7,12 +7,12 @@ import CreatableSelect from "react-select/creatable"; type Props = { onChange: any; - defaultValue: - | { - label: string; - value?: number; - } - | undefined; + defaultValue?: + | { + label: string; + value?: number; + } + | undefined; }; export default function CollectionSelection({ onChange, defaultValue }: Props) { @@ -51,7 +51,7 @@ export default function CollectionSelection({ onChange, defaultValue }: Props) { options={options} styles={styles} defaultValue={defaultValue} - // menuPosition="fixed" + // menuPosition="fixed" /> ); } diff --git a/components/ModalContent/BulkEditLinksModal.tsx b/components/ModalContent/BulkEditLinksModal.tsx index 5896f6b..4086ff6 100644 --- a/components/ModalContent/BulkEditLinksModal.tsx +++ b/components/ModalContent/BulkEditLinksModal.tsx @@ -1,50 +1,38 @@ -import React, { useEffect, useState } from "react"; +import React, { 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; }; -// TODO: Make this work -export default function EditLinkModal({ onClose }: Props) { - const { updateLink, updateLinksById } = useLinkStore(); +export default function BulkEditLinksModal({ onClose }: Props) { + const { updateLinks, selectedLinks, setSelectedLinks } = useLinkStore(); const [submitLoader, setSubmitLoader] = useState(false); - const [updatedValues, setUpdatedValues] = useState>(); + const [updatedValues, setUpdatedValues] = useState>({ tags: [] }); const setCollection = (e: any) => { - if (e?.__isNew__) e.value = null; - - setUpdatedValues({ - ...updatedValues, - collection: { id: e?.value, name: e?.label, ownerId: e?.ownerId }, - }); + const collectionId = e?.value || null; + setUpdatedValues((prevValues) => ({ ...prevValues, collectionId })); }; const setTags = (e: any) => { - const tagNames = e.map((e: any) => { - return { name: e.label }; - }); - - setUpdatedValues({ ...updatedValues, tags: tagNames }); + const tags = e.map((tag: any) => ({ name: tag.label })); + setUpdatedValues((prevValues) => ({ ...prevValues, tags })); }; const submit = async () => { if (!submitLoader) { setSubmitLoader(true); - let response; const load = toast.loading("Updating..."); - response = await updateLinksById(user); + const response = await updateLinks(selectedLinks, updatedValues); toast.dismiss(load); @@ -53,8 +41,9 @@ export default function EditLinkModal({ onClose }: Props) { onClose(); } else toast.error(response.data as string); + setSelectedLinks([]); setSubmitLoader(false); - + onClose(); return response; } }; @@ -62,78 +51,17 @@ export default function EditLinkModal({ onClose }: Props) { 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

-