feat: added edit + delete collection functionality
This commit is contained in:
@@ -27,7 +27,7 @@ export default function AddCollection({ toggleCollectionModal }: Props) {
|
||||
|
||||
const session = useSession();
|
||||
|
||||
const submitCollection = async () => {
|
||||
const submit = async () => {
|
||||
console.log(newCollection);
|
||||
|
||||
const response = await addCollection(newCollection as NewCollection);
|
||||
@@ -249,7 +249,7 @@ export default function AddCollection({ toggleCollectionModal }: Props) {
|
||||
|
||||
<div
|
||||
className="mx-auto mt-2 bg-sky-500 text-white flex items-center gap-2 py-2 px-5 rounded-md select-none font-bold cursor-pointer duration-100 hover:bg-sky-400"
|
||||
onClick={submitCollection}
|
||||
onClick={submit}
|
||||
>
|
||||
<FontAwesomeIcon icon={faPlus} className="h-5" />
|
||||
Add Collection
|
||||
|
||||
@@ -67,7 +67,7 @@ export default function AddLink({ toggleLinkModal }: Props) {
|
||||
});
|
||||
};
|
||||
|
||||
const submitLink = async () => {
|
||||
const submit = async () => {
|
||||
console.log(newLink);
|
||||
|
||||
const response = await addLink(newLink as NewLink);
|
||||
@@ -119,7 +119,7 @@ export default function AddLink({ toggleLinkModal }: Props) {
|
||||
|
||||
<div
|
||||
className="mx-auto mt-2 bg-sky-500 text-white flex items-center gap-2 py-2 px-5 rounded-md select-none font-bold cursor-pointer duration-100 hover:bg-sky-400"
|
||||
onClick={submitLink}
|
||||
onClick={submit}
|
||||
>
|
||||
<FontAwesomeIcon icon={faPlus} className="h-5" />
|
||||
Add Link
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright (C) 2022-present Daniel31x13 <daniel31x13@gmail.com>
|
||||
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faPlus, faTrashCan } from "@fortawesome/free-solid-svg-icons";
|
||||
import { ExtendedCollection } from "@/types/global";
|
||||
import useCollectionStore from "@/store/collections";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
type Props = {
|
||||
toggleCollectionModal: Function;
|
||||
collection: ExtendedCollection;
|
||||
};
|
||||
|
||||
export default function AddCollection({
|
||||
toggleCollectionModal,
|
||||
collection,
|
||||
}: Props) {
|
||||
const [inputField, setInputField] = useState("");
|
||||
|
||||
const { removeCollection } = useCollectionStore();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const submit = async () => {
|
||||
const response = await removeCollection(collection.id);
|
||||
if (response) {
|
||||
toggleCollectionModal();
|
||||
router.push("/collections");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3 sm:w-[35rem] w-80">
|
||||
<p className="font-bold text-sky-300 text-center">Delete Collection</p>
|
||||
|
||||
<p className="text-sky-900 select-none text-center">
|
||||
To confirm, type "
|
||||
<span className="font-bold text-sky-500">{collection.name}</span>" in
|
||||
the box below:
|
||||
</p>
|
||||
|
||||
<input
|
||||
value={inputField}
|
||||
onChange={(e) => setInputField(e.target.value)}
|
||||
type="text"
|
||||
placeholder={`Type "${collection.name}" Here.`}
|
||||
className=" w-72 sm:w-96 rounded-md p-3 mx-auto border-sky-100 border-solid border text-sm outline-none focus:border-sky-500 duration-100"
|
||||
/>
|
||||
|
||||
<div
|
||||
className={`mx-auto mt-2 text-white flex items-center gap-2 py-2 px-5 rounded-md select-none font-bold duration-100 ${
|
||||
inputField === collection.name
|
||||
? "bg-red-500 hover:bg-red-400 cursor-pointer"
|
||||
: "cursor-not-allowed bg-red-300"
|
||||
}`}
|
||||
onClick={submit}
|
||||
>
|
||||
<FontAwesomeIcon icon={faTrashCan} className="h-5" />
|
||||
Delete Collection
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -5,10 +5,11 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faClose, faPlus } from "@fortawesome/free-solid-svg-icons";
|
||||
import { faClose, faPenToSquare } from "@fortawesome/free-solid-svg-icons";
|
||||
import useCollectionStore from "@/store/collections";
|
||||
import { ExtendedCollection, NewCollection } from "@/types/global";
|
||||
import { ExtendedCollection } from "@/types/global";
|
||||
import { useSession } from "next-auth/react";
|
||||
import getPublicUserDataByEmail from "@/lib/client/getPublicUserDataByEmail";
|
||||
|
||||
type Props = {
|
||||
toggleCollectionModal: Function;
|
||||
@@ -24,24 +25,18 @@ export default function EditCollection({
|
||||
|
||||
const [memberEmail, setMemberEmail] = useState("");
|
||||
|
||||
// const { addCollection } = useCollectionStore();
|
||||
const { updateCollection } = useCollectionStore();
|
||||
|
||||
const session = useSession();
|
||||
|
||||
const submitCollection = async () => {
|
||||
const submit = async () => {
|
||||
console.log(activeCollection);
|
||||
|
||||
// const response = await addCollection(newCollection as NewCollection);
|
||||
const response = await updateCollection(
|
||||
activeCollection as ExtendedCollection
|
||||
);
|
||||
|
||||
// if (response) toggleCollectionModal();
|
||||
};
|
||||
|
||||
const getUserByEmail = async (email: string) => {
|
||||
const response = await fetch(`/api/routes/users?email=${email}`);
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return data.response;
|
||||
if (response) toggleCollectionModal();
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -103,7 +98,7 @@ export default function EditCollection({
|
||||
memberEmail.trim() !== ownerEmail
|
||||
) {
|
||||
// Lookup, get data/err, list ...
|
||||
const user = await getUserByEmail(memberEmail.trim());
|
||||
const user = await getPublicUserDataByEmail(memberEmail.trim());
|
||||
|
||||
if (user.email) {
|
||||
const newMember = {
|
||||
@@ -257,10 +252,10 @@ export default function EditCollection({
|
||||
|
||||
<div
|
||||
className="mx-auto mt-2 bg-sky-500 text-white flex items-center gap-2 py-2 px-5 rounded-md select-none font-bold cursor-pointer duration-100 hover:bg-sky-400"
|
||||
onClick={submitCollection}
|
||||
onClick={submit}
|
||||
>
|
||||
<FontAwesomeIcon icon={faPlus} className="h-5" />
|
||||
Add Collection
|
||||
<FontAwesomeIcon icon={faPenToSquare} className="h-5" />
|
||||
Edit Collection
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -40,7 +40,7 @@ export default function EditLink({ toggleLinkModal, link }: Props) {
|
||||
});
|
||||
};
|
||||
|
||||
const submitLink = async () => {
|
||||
const submit = async () => {
|
||||
updateLink(currentLink);
|
||||
toggleLinkModal();
|
||||
};
|
||||
@@ -87,7 +87,7 @@ export default function EditLink({ toggleLinkModal, link }: Props) {
|
||||
|
||||
<div
|
||||
className="mx-auto mt-2 bg-sky-500 text-white flex items-center gap-2 py-2 px-5 rounded-md select-none font-bold cursor-pointer duration-100 hover:bg-sky-400"
|
||||
onClick={submitLink}
|
||||
onClick={submit}
|
||||
>
|
||||
<FontAwesomeIcon icon={faPenToSquare} className="h-5" />
|
||||
Edit Link
|
||||
|
||||
Reference in New Issue
Block a user