Skip to content

Commit

Permalink
feat(delete item): add delete item warning and confiramtion component
Browse files Browse the repository at this point in the history
  • Loading branch information
ismail-benlaredj committed Nov 5, 2023
1 parent 88735f6 commit e6bb2b2
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/components/delete-warning/index.jsx
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>
);
}

0 comments on commit e6bb2b2

Please sign in to comment.