-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
* add speechgenarator * css updated * css upadate * add validations * ✨ Account Deletion --------- Co-authored-by: dinidusachintha <dinidusachintha7@gmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
|
||
const ConfirmationModalDelete = ({ isOpen, onClose, onConfirm, confirmationText, setConfirmationText }) => { | ||
Check failure on line 3 in frontend/src/Components/ConfirmationModalDelete.jsx GitHub Actions / ESLint Report Analysisfrontend/src/Components/ConfirmationModalDelete.jsx#L3
Check failure on line 3 in frontend/src/Components/ConfirmationModalDelete.jsx GitHub Actions / ESLint Report Analysisfrontend/src/Components/ConfirmationModalDelete.jsx#L3
Check failure on line 3 in frontend/src/Components/ConfirmationModalDelete.jsx GitHub Actions / ESLint Report Analysisfrontend/src/Components/ConfirmationModalDelete.jsx#L3
Check failure on line 3 in frontend/src/Components/ConfirmationModalDelete.jsx GitHub Actions / ESLint Report Analysisfrontend/src/Components/ConfirmationModalDelete.jsx#L3
|
||
if (!isOpen) return null; | ||
|
||
return ( | ||
<div className="fixed inset-0 bg-gray-800 bg-opacity-50 flex justify-center items-center z-50"> | ||
<div className="bg-white p-6 rounded shadow-md w-1/3"> | ||
<h2 className="text-xl font-semibold mb-4">Confirm Account Deletion</h2> | ||
<p>Type <strong>"I want to delete my account"</strong> to confirm:</p> | ||
Check failure on line 10 in frontend/src/Components/ConfirmationModalDelete.jsx GitHub Actions / ESLint Report Analysisfrontend/src/Components/ConfirmationModalDelete.jsx#L10
Check failure on line 10 in frontend/src/Components/ConfirmationModalDelete.jsx GitHub Actions / ESLint Report Analysisfrontend/src/Components/ConfirmationModalDelete.jsx#L10
|
||
<input | ||
type="text" | ||
value={confirmationText} | ||
onChange={(e) => setConfirmationText(e.target.value)} | ||
className="border border-gray-300 p-2 rounded mb-4 w-full" | ||
/> | ||
<div className="flex justify-end"> | ||
<button onClick={onClose} className="mr-2 bg-gray-300 text-gray-700 font-bold py-1 px-3 rounded"> | ||
Cancel | ||
</button> | ||
<button onClick={onConfirm} className="bg-red-600 text-white font-bold py-1 px-3 rounded"> | ||
Confirm | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ConfirmationModalDelete; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React, { useState } from 'react'; | ||
import { toast } from 'react-hot-toast'; | ||
import axios from 'axios'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import ConfirmationModal from './ConfirmationModalDelete'; // Import the modal component | ||
|
||
const DeleteAccountButton = () => { | ||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
const [confirmationText, setConfirmationText] = useState(''); | ||
const navigate = useNavigate(); | ||
|
||
const handleDeleteAccount = async () => { | ||
if (confirmationText !== 'I want to delete my account') { | ||
toast.error('Please type "I want to delete my account" to confirm.'); | ||
return; | ||
} | ||
|
||
try { | ||
const response = await axios.delete('/api/users'); // Adjust the endpoint as necessary | ||
toast.success(response.data.message); | ||
|
||
// Redirect to the registration page after deletion | ||
navigate('/register'); // Adjust the path as necessary | ||
} catch (error) { | ||
toast.error(error.response?.data?.message || 'Failed to delete account'); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<button | ||
onClick={() => setIsModalOpen(true)} | ||
className="bg-red-600 text-white font-bold py-2 px-4 rounded hover:bg-red-700 transition duration-200" | ||
> | ||
Delete Account | ||
</button> | ||
|
||
<ConfirmationModal | ||
isOpen={isModalOpen} | ||
onClose={() => setIsModalOpen(false)} | ||
onConfirm={handleDeleteAccount} | ||
confirmationText={confirmationText} | ||
setConfirmationText={setConfirmationText} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DeleteAccountButton; |