el.xwx.moe/components/Modal/Collection/DeleteCollection.tsx

66 lines
2.0 KiB
TypeScript
Raw Normal View History

import React, { useState } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
2023-05-26 23:29:45 -05:00
import { faTrashCan } from "@fortawesome/free-solid-svg-icons";
2023-05-26 23:11:29 -05:00
import { CollectionIncludingMembers } from "@/types/global";
import useCollectionStore from "@/store/collections";
import { useRouter } from "next/router";
type Props = {
2023-05-18 13:02:17 -05:00
toggleDeleteCollectionModal: Function;
2023-05-26 23:11:29 -05:00
collection: CollectionIncludingMembers;
};
2023-05-26 23:29:45 -05:00
export default function DeleteCollection({
2023-05-18 13:02:17 -05:00
toggleDeleteCollectionModal,
collection,
}: Props) {
const [inputField, setInputField] = useState("");
const { removeCollection } = useCollectionStore();
const router = useRouter();
const submit = async () => {
2023-05-26 23:11:29 -05:00
if (!collection.id) return null;
const response = await removeCollection(collection.id);
if (response) {
2023-05-18 13:02:17 -05:00
toggleDeleteCollectionModal();
router.push("/collections");
}
};
return (
2023-05-28 01:00:12 -05:00
<div className="flex flex-col gap-3 sm:w-[35rem] w-80">
2023-05-18 13:02:17 -05:00
<p className="text-xl text-sky-500 mb-2 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
2023-05-08 09:35:39 -05:00
autoFocus
value={inputField}
onChange={(e) => setInputField(e.target.value)}
type="text"
placeholder={`Type "${collection.name}" Here.`}
2023-05-01 15:00:23 -05:00
className=" w-72 sm:w-96 rounded-md p-3 mx-auto border-sky-100 border-solid border 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>
);
}