Skip to content

Commit

Permalink
refactor code for cancel/reorder, display error message for cancel/re…
Browse files Browse the repository at this point in the history
…order
  • Loading branch information
creme332 committed May 23, 2024
1 parent ad3926a commit 90677aa
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/views/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
* @var Client $client signed in client
* @var Order[] $orders array of orders
* @var bool $show_account_deletion_confirmation Whether to display a confirmation dialog for account deletion
* @var bool $reorder_cancel Whether to display reorder and cancel buttons
* @var string $order_action_error Error when user performed action on orders tab
*/

use Steamy\Model\Client;
use Steamy\Model\Order;

?>

<?php if ($show_account_deletion_confirmation) : ?>
<?php
if ($show_account_deletion_confirmation) : ?>
<dialog open>
<article>
<h3>Deleting your account!</h3>
Expand All @@ -29,7 +30,8 @@
</footer>
</article>
</dialog>
<?php endif; ?>
<?php
endif; ?>

<main class="container">
<h1>My profile</h1>
Expand Down Expand Up @@ -72,6 +74,12 @@
<div id="Orders" class="tabcontent">
<h2>Orders summary</h2>

<?php
if (!empty($order_action_error)): ?>
<blockquote><strong> ERROR 🔺: <?= $order_action_error ?>.</strong></blockquote>
<?php
endif ?>

<figure>
<table>
<tr>
Expand All @@ -87,36 +95,30 @@
foreach ($orders as $order) {
$date = htmlspecialchars($order->getCreatedDate()->format('Y-m-d H:i:s'));
$id = filter_var($order->getOrderID(), FILTER_SANITIZE_NUMBER_INT);
$storeid = filter_var($order->getStoreID(), FILTER_SANITIZE_NUMBER_INT);
$store_id = filter_var($order->getStoreID(), FILTER_SANITIZE_NUMBER_INT);
$status = htmlspecialchars(ucfirst($order->getStatus()->value));
$totalPrice = htmlspecialchars(number_format($order->calculateTotalPrice(), 2));

// Determine button states
$cancelDisabled = $status === 'completed' ? 'disabled' : '';
$reorderDisabled = $status !== 'completed' ? 'disabled' : '';
$cancelDisabled = $order->getStatus()->value === 'completed' ? 'disabled' : '';

echo <<< EOL
<tr>
<td>$id</td>
<td>$storeid</td>
<td>$store_id</td>
<td>$date</td>
<td>$status</td>
<td>\$$totalPrice</td>
EOL;
if ($reorder_cancel) {
echo <<< EOL
<td class="grid">
<form method="post" class="reorder_cancel">
<input type="hidden" name="reorder_cancel">
<td>
<form style="display: flex; gap:1em;" method="post">
<input type="hidden" name="order_id" value="$id">
<button type="submit" name="reorder" $reorderDisabled>Reorder</button>
<button type="submit" name="cancel" $cancelDisabled>Cancel</button>
<button type="submit" name="cancel_order" $cancelDisabled>Cancel</button>
<button type="submit" name="reorder">Reorder</button>
</form>
</td>
EOL;
}
echo "</tr>";
</tr>
EOL;
}
?>
</table>
Expand Down

0 comments on commit 90677aa

Please sign in to comment.