Skip to content

Commit 71d15e3

Browse files
committed
feat: implement orders page to display user's order history
1 parent 8d02612 commit 71d15e3

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<script lang="ts">
2+
import { getPocketBase } from '$lib/services/pocketbase';
3+
import { getAuthStore } from '$lib/stores/auth.store.svelte';
4+
import { getCartStore } from '$lib/stores/cart.store.svelte';
5+
6+
const authStore = getAuthStore();
7+
const cartStore = getCartStore();
8+
9+
const orders = getPocketBase()
10+
.collection('orders')
11+
.getFullList({
12+
sort: '-created',
13+
filter: `user.id = '${authStore.id}'`
14+
});
15+
</script>
16+
17+
<div class="mb-4 flex items-center justify-between gap-4 bg-gray-100">
18+
<h1 class="px-4 py-2 text-xl">My Orders</h1>
19+
</div>
20+
{#await orders}
21+
<p>Loading orders...</p>
22+
{:then orders}
23+
<div class="grid grid-cols-1 gap-4">
24+
{#each orders as order}
25+
<div class="pb-4">
26+
<div class="items-between flex border-b border-b-gray-200 pb-4">
27+
<div class="flex-grow">
28+
<h2 class="text-lg font-bold">Order ID: {order.id}</h2>
29+
30+
<p>Last updated at {new Date(order.updated).toLocaleString('nl-BE')}</p>
31+
<p>
32+
Order status: {order.status[0].toUpperCase() + order.status.slice(1)}
33+
</p>
34+
<p>
35+
Order complete? {order.complete ? 'Yes' : 'No'}
36+
</p>
37+
{#if order.status === 'delivered' && order.delivered}
38+
<p>Order delivered at: {new Date(order.delivered).toLocaleString('nl-BE')}</p>
39+
{/if}
40+
</div>
41+
<div>
42+
<a href={`/order/${order.id}`} class="ml-auto bg-blue-400 px-4 py-2"> View Order </a>
43+
</div>
44+
</div>
45+
</div>
46+
{/each}
47+
</div>
48+
{:catch error}
49+
<p class="bg-red-400">Error loading orders: {error}</p>
50+
{/await}

0 commit comments

Comments
 (0)