Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions packages/theme/modules/checkout/getters/orderGetters.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
import { AgnosticPagination } from '~/composables/types';
import { CustomerOrder, OrderItemInterface } from '~/modules/GraphQL/types';
import type { AgnosticPagination } from '~/composables/types';
import type { CustomerOrders, CustomerOrder, OrderItemInterface } from '~/modules/GraphQL/types';

export const getDate = (order: CustomerOrder): string => new Date(order?.order_date?.replace(/ /g, 'T')).toLocaleDateString() || '';
export const getDate = (order: CustomerOrder): string => new Date(order?.order_date?.replace(/ /g, 'T')).toLocaleDateString();

export const getId = (order: CustomerOrder): string => order?.number || '';
export const getPrice = (order: CustomerOrder): number => order?.total?.base_grand_total?.value ?? 0;

export const getStatus = (order: CustomerOrder): string => order?.status || 'Failed';
export const getItemPrice = (item: OrderItemInterface): number => item?.product_sale_price?.value ?? 0;

export const getPrice = (order: CustomerOrder): number | null => order?.total?.base_grand_total?.value || 0;

export const getItems = (order: CustomerOrder): OrderItemInterface[] => order?.items || [];

export const getItemSku = (item: OrderItemInterface): string => item?.product_sku || '';

export const getItemName = (item: OrderItemInterface): string => item?.product_name || '';

export const getItemQty = (item: OrderItemInterface): number => item?.quantity_ordered || 0;

export const getItemPrice = (item: OrderItemInterface): number => item?.product_sale_price?.value || 0;

export const getFormattedPrice = (price: OrderItemInterface) => String(price);

const getPagination = (orders: any): AgnosticPagination => ({
const getPagination = (orders: CustomerOrders): AgnosticPagination => ({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed any

currentPage: orders?.page_info?.current_page || 1,
totalPages: orders?.page_info?.total_pages || 1,
totalItems: orders?.total_count || 0,
Expand All @@ -31,15 +17,8 @@ const getPagination = (orders: any): AgnosticPagination => ({

const orderGetters = {
getDate,
getId,
getStatus,
getPrice,
getItems,
getItemSku,
getItemName,
getItemQty,
getItemPrice,
getFormattedPrice,
getPagination,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<SfTableData>{{ orderGetters.getDate(order) }}</SfTableData>
<SfTableData>{{ $fc(orderGetters.getPrice(order)) }}</SfTableData>
<SfTableData>
<span :class="getStatusTextClass(order)">{{ orderGetters.getStatus(order) }}</span>
<span :class="getStatusTextClass(order)">{{ order.status }}</span>
</SfTableData>
<SfTableData class="orders__view orders__element--right">
<SfLink
Expand Down Expand Up @@ -173,8 +173,7 @@ export default defineComponent({
];

const getStatusTextClass = (order: CustomerOrder) => {
const status = orderGetters.getStatus(order);
switch (status) {
switch (order.status) {
case AgnosticOrderStatus.Open:
return 'text-warning';
case AgnosticOrderStatus.Complete:
Expand All @@ -190,8 +189,7 @@ export default defineComponent({
getStatusTextClass,
loading,
orderGetters,
// @ts-expect-error Wrong type returned by useUserOrder. See M2-579 in VSF Jira
orders: computed(() => orderGetters.getItems(orders.value)),
orders: computed(() => orders.value.items),
pagination,
tableHeaders,
th,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{{ $t('Status') }}
</template>
<template #value>
{{ getStatus(asyncData.order) }}
{{ asyncData.order.status }}
</template>
</OrderSummaryRow>

Expand Down Expand Up @@ -170,7 +170,6 @@ export default defineComponent({
ordersRoute,
asyncData,
getDate: orderGetters.getDate,
getStatus: orderGetters.getStatus,
};
},
});
Expand Down