diff --git a/components/InputSelect/TagSelection.tsx b/components/InputSelect/TagSelection.tsx index 08460ea..cf03e6f 100644 --- a/components/InputSelect/TagSelection.tsx +++ b/components/InputSelect/TagSelection.tsx @@ -7,7 +7,7 @@ import { useTags } from "@/hooks/store/tags"; type Props = { onChange: any; defaultValue?: { - value: number; + value?: number; label: string; }[]; autoFocus?: boolean; diff --git a/components/ModalContent/NewLinkModal.tsx b/components/ModalContent/NewLinkModal.tsx index f0030e4..e5394c9 100644 --- a/components/ModalContent/NewLinkModal.tsx +++ b/components/ModalContent/NewLinkModal.tsx @@ -3,14 +3,13 @@ import CollectionSelection from "@/components/InputSelect/CollectionSelection"; import TagSelection from "@/components/InputSelect/TagSelection"; import TextInput from "@/components/TextInput"; import unescapeString from "@/lib/client/unescapeString"; -import { LinkIncludingShortenedCollectionAndTags } from "@/types/global"; -import { useSession } from "next-auth/react"; import { useRouter } from "next/router"; import Modal from "../Modal"; import { useTranslation } from "next-i18next"; import { useCollections } from "@/hooks/store/collections"; import { useAddLink } from "@/hooks/store/links"; import toast from "react-hot-toast"; +import { PostLinkSchemaType } from "@/lib/shared/schemaValidation"; type Props = { onClose: Function; @@ -18,30 +17,19 @@ type Props = { export default function NewLinkModal({ onClose }: Props) { const { t } = useTranslation(); - const { data } = useSession(); const initial = { name: "", url: "", description: "", type: "url", tags: [], - preview: "", - image: "", - pdf: "", - readable: "", - monolith: "", - textContent: "", - icon: "", - iconWeight: "", - color: "", collection: { + id: undefined, name: "", - ownerId: data?.user.id as number, }, - } as LinkIncludingShortenedCollectionAndTags; + } as PostLinkSchemaType; - const [link, setLink] = - useState(initial); + const [link, setLink] = useState(initial); const addLink = useAddLink(); @@ -51,10 +39,10 @@ export default function NewLinkModal({ onClose }: Props) { const { data: collections = [] } = useCollections(); const setCollection = (e: any) => { - if (e?.__isNew__) e.value = null; + if (e?.__isNew__) e.value = undefined; setLink({ ...link, - collection: { id: e?.value, name: e?.label, ownerId: e?.ownerId }, + collection: { id: e?.value, name: e?.label }, }); }; @@ -68,23 +56,19 @@ export default function NewLinkModal({ onClose }: Props) { const currentCollection = collections.find( (e) => e.id == Number(router.query.id) ); - if ( - currentCollection && - currentCollection.ownerId && - router.asPath.startsWith("/collections/") - ) + + if (currentCollection && currentCollection.ownerId) setLink({ ...initial, collection: { id: currentCollection.id, name: currentCollection.name, - ownerId: currentCollection.ownerId, }, }); } else setLink({ ...initial, - collection: { name: "Unorganized", ownerId: data?.user.id as number }, + collection: { name: "Unorganized" }, }); }, []); @@ -99,7 +83,7 @@ export default function NewLinkModal({ onClose }: Props) { toast.dismiss(load); if (error) { - toast.error(error.message); + toast.error(t(error.message)); } else { onClose(); toast.success(t("link_created")); @@ -127,12 +111,12 @@ export default function NewLinkModal({ onClose }: Props) {

{t("collection")}

- {link.collection.name && ( + {link.collection?.name && ( )} @@ -155,7 +139,7 @@ export default function NewLinkModal({ onClose }: Props) {

{t("tags")}

({ + defaultValue={link.tags?.map((e) => ({ label: e.name, value: e.id, }))} @@ -164,7 +148,7 @@ export default function NewLinkModal({ onClose }: Props) {

{t("description")}