Skip to content
Prev Previous commit
feat: 新增歷史訂單頁面
  • Loading branch information
Aya-X committed Nov 26, 2022
commit 2d275e43f7443e4b29a15f724ff493c324b5182c
158 changes: 158 additions & 0 deletions page/me/history.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>History</title>

<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU"
crossorigin="anonymous"
/>

<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.2/font/bootstrap-icons.css"
/>

<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0"
/>
</head>

<body>
<header class="sticky-top">
<!-- Navbar -->
<nav class="navbar navbar-expand-md navbar-light bg-light">
<!-- Container-wrapper -->
<section class="container-fluid">
<!-- Navbar brand -->
<a class="navbar-brand me-2" href="/">LOGO</a>

<!-- Toggle button -->
<button
type="button"
class="navbar-toggler"
data-bs-toggle="collapse"
data-bs-target="#navbarCollapse"
aria-controls="navbarCollapse"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>

<!-- Collapsible-wrapper -->
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0"></ul>
<!-- end of Left-links -->

<div class="d-flex align-items-center">
<ul class="navbar-nav js-user-menu">
<!-- #NOTE: check IF-login and inject dropdown-btns -->
</ul>
<!-- end of User-btns -->

<div class="js-guest-menu">
<a href="../login.html" class="btn btn-sm text-muted px-3 me-2">
登入
</a>

<a href="../register.html" class="btn btn-primary btn-sm me-3"
>免費註冊</a
>
</div>
<!-- end of GUEST-btns -->
</div>
</div>
<!-- end of Collapsible-wrapper -->
</section>
<!-- end of Container-wrapper -->
</nav>
</header>

<main class="container py-4">
<div class="card mt-4">
<div class="card-footer text-muted fs-4">
<code class="js-msg">LOG</code>
</div>
</div>
</main>

<footer class="footer mt-auto py-3 bg-light">
<div class="container">
<!-- <a class="nav-link text-muted" href="/admin">前往後台</a> -->
</div>
</footer>
<!-- end of DOM -->

<!-- Bootstrap5 JavaScript Bundle with Popper -->
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ"
crossorigin="anonymous"
></script>

<script src="https://unpkg.com/axios@1.1.2/dist/axios.min.js"></script>

<script src="../helpers/renderUserMenu.js"></script>

<script>
// const BASE_URL = 'http://localhost:3000';
const PRODUCTS_URL = `${BASE_URL}/664/products`;
const USERS_URL = `${BASE_URL}/600/users`;

const domMsg = document.querySelector('.js-msg');

/* end of definition */

function getLoggedID() {
return localStorage.getItem('userId') || 0;
}
/* end of hasLogged() */

function renderTheGetOrders() {
const userId = getLoggedID();

const AUTH = `Bearer ${localStorage.getItem('token')}`;
axios.defaults.headers.common.Authorization = AUTH;

const url = `${USERS_URL}/${userId}/orders`;

axios
.get(url)
.then(function (response) {
// console.log('carts:::', JSON.stringify(response, null, 2));

// domMsg.innerHTML = response.statusText;
domMsg.innerHTML = `orders-
<pre>${JSON.stringify(response.data, null, 2)}</pre>
`;

if (response.status === 200) {
}
/* end of res-OK */
})
.catch(function (error) {
console.log('error:::', JSON.stringify(error, null, 2));

domMsg.innerHTML = error.response.data;
});
/* end of axios */
}
/* end of renderTheGetOrders() */

function init() {
renderTheGetOrders();
}
/* end of init() */

init();
</script>
</body>
</html>