aboutsummaryrefslogtreecommitdiff
path: root/client/src/views/Orders.vue
blob: 9eb121e33e98a79c87b9d2ef282c162436f1e0ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<template>
  <div class="row mt-5 d-flex justify-content-center">
    <div class="col-md-6">
      <div v-if="orders">
        <div v-for="order in orders" :key="order._id" class="card bg-dark text-white mb-3">
          <div class="card-header">Order made: {{ getDate(order) }}</div>
          <div class="card-body">
            <ul class="list-group">
              <li v-for="item in order.items" :key="item.productId"
                class="list-group-item d-flex justify-content-between align-items-start">
                <div class="me-auto" v-text="item.name"></div>
                <span class="badge bg-dark rounded-circle" v-text="item.quantity"></span>
              </li>
            </ul>
          </div>
          <div class="card-footer">
            Delivering to: {{ getShipping(order) }}
          </div>
        </div>
      </div>
      <div v-else class="card text-center fw-bold">
        You currently have no orders.
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Orders',
  mounted() {
    this.$store.dispatch('pullUserOrders');
  },
  computed: {
    orders() {
      return this.$store.getters.getUserOrders;
    }
  },
  methods: {
    getDate(order) {
      let dt = new Date(order.updatedAt);
      return `${dt.getUTCDay()}.${dt.getUTCMonth()}.${dt.getUTCFullYear()}. ${dt.getUTCHours()}:${dt.getUTCMinutes()} UTC`;
    },
    getShipping(order) {
      return Object.values(order.shipping.address).join(", ");
    }
  }
}
</script>