2023-04-28 16:10:29 -05:00
// 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 = {
2023-05-18 13:02:17 -05:00
toggleDeleteCollectionModal : Function ;
2023-04-28 16:10:29 -05:00
collection : ExtendedCollection ;
} ;
export default function AddCollection ( {
2023-05-18 13:02:17 -05:00
toggleDeleteCollectionModal ,
2023-04-28 16:10:29 -05:00
collection ,
} : Props ) {
const [ inputField , setInputField ] = useState ( "" ) ;
const { removeCollection } = useCollectionStore ( ) ;
const router = useRouter ( ) ;
const submit = async ( ) = > {
const response = await removeCollection ( collection . id ) ;
if ( response ) {
2023-05-18 13:02:17 -05:00
toggleDeleteCollectionModal ( ) ;
2023-04-28 16:10:29 -05:00
router . push ( "/collections" ) ;
}
} ;
return (
2023-05-01 05:07:01 -05:00
< div className = "flex flex-col gap-3 sm:w-[33rem] w-72" >
2023-05-18 13:02:17 -05:00
< p className = "text-xl text-sky-500 mb-2 text-center" > Delete Collection < / p >
2023-04-28 16:10:29 -05:00
< 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
2023-04-28 16:10:29 -05:00
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"
2023-04-28 16:10:29 -05:00
/ >
< 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 >
) ;
}