Created
November 3, 2023 13:11
-
-
Save popeating/3dcdff0da5216bfd2ab7ffc03406a4fc to your computer and use it in GitHub Desktop.
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
import { contactDelete } from '@/actions/actions'; | |
import React, { startTransition, useState } from 'react'; | |
function Delete({ dopen, setDopen, currId, setCurrId }) { | |
const [error, setError] = useState(); | |
async function doDelete(id) { | |
const result = await contactDelete(id); | |
if (result.error) { | |
setError(result.error); | |
} | |
setDopen(false); | |
setCurrId(); | |
} | |
return ( | |
<> | |
{error && ( | |
<div className="toast" onClick={() => setError()}> | |
<div className="alert alert-error"> | |
<span> | |
An error occurred | |
<br /> | |
{error} | |
</span> | |
</div> | |
</div> | |
)} | |
<dialog id="add_modal" className="modal" open={dopen}> | |
<div className="modal-box "> | |
<h3 className="font-bold text-lg">Confirm Deletion</h3> | |
<p className="py-4">Are you sure you want to delete the contact?</p> | |
<div className="flex my-4 justify-between"> | |
<div className="btn" onClick={() => setDopen(false)}> | |
Cancel | |
</div> | |
<button | |
className="btn btn-primary" | |
onClick={() => startTransition(() => doDelete(currId))} | |
> | |
Confirm | |
</button> | |
</div> | |
</div> | |
</dialog> | |
</> | |
); | |
} | |
export default Delete; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment