Skip to content

Commit

Permalink
insert confirmation dialog in html only during deletion, rename view …
Browse files Browse the repository at this point in the history
…variable to be more meaningful, improve dialog ui
  • Loading branch information
creme332 committed May 19, 2024
1 parent 19ef71c commit ac0928f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/controllers/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct()
$this->signed_client = null;
$this->view_data['errors'] = [];
$this->view_data['client'] = null;
$this->view_data['confirmation_message'] = false;
$this->view_data['show_account_deletion_confirmation'] = false;
}

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

private function handleAccountDeletion(): void
{
// Display confirmation message
$confirmation_message = "Are you sure you want to delete your account? This action is irreversible.";
$this->view_data['confirmation_message'] = $confirmation_message;
$this->view_data['show_account_deletion_confirmation'] = true;

// Check if the deletion confirmation has been submitted
if (isset($_POST['confirm_delete'])) {
Expand Down Expand Up @@ -205,7 +203,6 @@ public function index(): void

// delete user account if delete button clicked
if (isset($_GET['account_delete_submit'])) {
$this->view_data['confirmation_message'] = true;
$this->handleAccountDeletion();
return;
}
Expand Down
28 changes: 17 additions & 11 deletions 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 @@ -203,14 +204,19 @@ function openTab(evt, tabName) {


</script>

<dialog <?= $confirmation_message ? "open" : "" ?>>
<article>
<h3>Deleting your account!! </h3>
<p><?= $confirmation_message ?></p><br>
<form method="post">
<button type="submit" name="confirm_delete">Confirm</button>
<button type="submit" name="cancel_delete">Cancel</button>
</form>
</article>
</dialog>
<?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 ac0928f

Please sign in to comment.