generated from 202306-NEA-DZ-FEW/capstone-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(delete item): add delete item warning and confiramtion component
- Loading branch information
1 parent
88735f6
commit e6bb2b2
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useState } from "react"; | ||
|
||
import { deleteDocData } from "@/lib/firebase/firestoreFunctions"; | ||
|
||
import Button from "../button/Button"; | ||
|
||
export default function DeleteWarning({ | ||
setDeleteWarningItem, | ||
deleteWarningItem, | ||
setItems, | ||
items, | ||
}) { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const handleDelete = async () => { | ||
setIsLoading(true); | ||
await deleteDocData("items", deleteWarningItem); | ||
setItems(items.filter((item) => item.id !== deleteWarningItem)); | ||
setDeleteWarningItem(false); | ||
setIsLoading(false); | ||
}; | ||
return ( | ||
<div className='fixed w-full h-full inset-0 z-40 flex justify-center items-center overflow-hidden transition-opacity'> | ||
<div className='absolute w-full h-full bg-[black] opacity-80 right-0 top-0'></div> | ||
<div className='relative text-white py-12 px-16 bg-[#00000059] rounded-lg z-60 shadow-xl border border-slate-200 '> | ||
<p> Do you want to delete this item?</p> | ||
<div className='flex gap-9 mt-10 w-full justify-center'> | ||
<Button | ||
className={`${isLoading ? "bg-slate-300 " : "bg-red"}`} | ||
onClick={handleDelete} | ||
disabled={isLoading} | ||
> | ||
Delete | ||
</Button> | ||
<Button | ||
onClick={() => setDeleteWarningItem(false)} | ||
variant='outlinePrimary' | ||
className={`${isLoading ? "bg-slate-300 " : ""}`} | ||
disabled={isLoading} | ||
> | ||
Cancel | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |