Skip to content

Commit

Permalink
Merge pull request #188 from Divyesh000/confirmdelete
Browse files Browse the repository at this point in the history
show confirmation dialog when deleting profile
  • Loading branch information
creme332 authored May 19, 2024
2 parents 0bce317 + ac0928f commit 22db6d5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
27 changes: 24 additions & 3 deletions src/controllers/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct()
$this->signed_client = null;
$this->view_data['errors'] = [];
$this->view_data['client'] = null;
$this->view_data['show_account_deletion_confirmation'] = false;
}

private function handleLogOut(): void
Expand All @@ -39,9 +40,29 @@ private function handleLogOut(): void

private function handleAccountDeletion(): void
{
// delete user account if delete button clicked
$this->signed_client->deleteUser();
$this->handleLogOut();
$this->view_data['show_account_deletion_confirmation'] = true;

// Check if the deletion confirmation has been submitted
if (isset($_POST['confirm_delete'])) {
// Perform account deletion
$this->signed_client->deleteUser();
$this->handleLogOut();
return;
}

// Check if cancel button is clicked
if (isset($_POST['cancel_delete'])) {
Utility::redirect('profile');
return;
}

// Render the view with the confirmation message
$this->view(
'Profile',
$this->view_data,
'Profile',
enableIndexing: false
);
}

/**
Expand Down
19 changes: 18 additions & 1 deletion src/views/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* The following attributes are defined in controllers/Profile.php
*
* @var $client Client signed in client
* @var $show_account_deletion_confirmation bool Whether to display a confirmation dialog for account deletion
* @var $orders array array of orders
*/

Expand Down Expand Up @@ -162,6 +163,7 @@
<form>
<button type="submit" name="account_delete_submit">Delete</button>
</form>

</article>
</div>
</div>
Expand Down Expand Up @@ -202,4 +204,19 @@ function openTab(evt, tabName) {


</script>

<?php
if ($show_account_deletion_confirmation) : ?>
<dialog open>
<article>
<h3>Deleting your account! </h3>
<p>Are you sure you want to delete your account? This action is irreversible.</p>
<footer>
<form method="post" class="grid">
<button class="secondary" type="submit" name="cancel_delete">Cancel</button>
<button type="submit" name="confirm_delete">Confirm</button>
</form>
</footer>
</article>
</dialog>
<?php
endif; ?>

0 comments on commit 22db6d5

Please sign in to comment.