🔄 cleanup: more order logic cleanup on the admin side mostly
This commit is contained in:
@@ -1,5 +1,78 @@
|
||||
<script lang="ts">
|
||||
let { order }: { order?: any } = $props();
|
||||
import { Badge } from "$lib/components/ui/badge";
|
||||
import { Separator } from "$lib/components/ui/separator";
|
||||
import type { FullOrderModel } from "$lib/domains/order/data/entities";
|
||||
import { OrderStatus } from "$lib/domains/order/data/entities";
|
||||
import OrderMainInfo from "./order-main-info.svelte";
|
||||
import OrderMiscInfo from "./order-misc-info.svelte";
|
||||
|
||||
let { order }: { order?: FullOrderModel } = $props();
|
||||
|
||||
function getStatusVariant(status: OrderStatus) {
|
||||
switch (status) {
|
||||
case OrderStatus.FULFILLED:
|
||||
return "success";
|
||||
case OrderStatus.PARTIALLY_FULFILLED:
|
||||
return "default";
|
||||
case OrderStatus.PENDING_FULFILLMENT:
|
||||
return "secondary";
|
||||
case OrderStatus.CANCELLED:
|
||||
return "destructive";
|
||||
default:
|
||||
return "outline";
|
||||
}
|
||||
}
|
||||
|
||||
function formatStatus(status: OrderStatus): string {
|
||||
return status
|
||||
.split("_")
|
||||
.map((word) => word.charAt(0) + word.slice(1).toLowerCase())
|
||||
.join(" ");
|
||||
}
|
||||
</script>
|
||||
|
||||
<span>show the order details - todo</span>
|
||||
{#if order}
|
||||
<div class="container mx-auto py-6">
|
||||
<!-- Order Header -->
|
||||
<div class="mb-6 flex items-center justify-between">
|
||||
<div class="flex flex-col gap-2">
|
||||
<h1 class="text-3xl font-bold">Order #{order.id}</h1>
|
||||
<p class="text-gray-600">
|
||||
Created on {new Date(order.createdAt).toLocaleDateString(
|
||||
"en-US",
|
||||
{
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
},
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<Badge
|
||||
variant={getStatusVariant(order.status)}
|
||||
class="px-4 py-2 text-base"
|
||||
>
|
||||
{formatStatus(order.status)}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<Separator class="my-6" />
|
||||
|
||||
<!-- Order Content Grid -->
|
||||
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||
<!-- Main Info Column -->
|
||||
<div class="flex flex-col gap-6">
|
||||
<OrderMainInfo {order} />
|
||||
</div>
|
||||
|
||||
<!-- Misc Info Column -->
|
||||
<div class="flex flex-col gap-6">
|
||||
<OrderMiscInfo {order} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="container mx-auto py-12 text-center">
|
||||
<p class="text-xl text-gray-500">Order not found</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
import Icon from "$lib/components/atoms/icon.svelte";
|
||||
import Title from "$lib/components/atoms/title.svelte";
|
||||
import { Badge } from "$lib/components/ui/badge";
|
||||
import CustomerDetailsCard from "$lib/domains/customerinfo/view/customer-details-card.svelte";
|
||||
import type { FullOrderModel } from "$lib/domains/order/data/entities";
|
||||
import TicketLegsOverview from "$lib/domains/ticket/view/ticket/ticket-legs-overview.svelte";
|
||||
import ProductIcon from "~icons/solar/box-broken";
|
||||
import CreditCardIcon from "~icons/solar/card-broken";
|
||||
import EmailIcon from "~icons/solar/letter-broken";
|
||||
import TicketIcon from "~icons/solar/ticket-broken";
|
||||
|
||||
let { order }: { order: FullOrderModel } = $props();
|
||||
|
||||
@@ -17,38 +17,59 @@
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-6">
|
||||
{#if order.emailAccountId && order.emailAccount}
|
||||
{#if order.emailAccountId}
|
||||
<!-- Email Account Info -->
|
||||
<div class={cardStyle}>
|
||||
<div class="flex items-center gap-2">
|
||||
<Icon icon={EmailIcon} cls="w-5 h-5" />
|
||||
<Title size="h5" color="black">Account Information</Title>
|
||||
</div>
|
||||
<p class="text-gray-800">{order.emailAccount?.email}</p>
|
||||
<p class="text-gray-800">Email Account ID: #{order.emailAccountId}</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Flight Ticket Info -->
|
||||
<!-- Product Info -->
|
||||
<div class={cardStyle}>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-2">
|
||||
<Icon icon={TicketIcon} cls="w-5 h-5" />
|
||||
<Title size="h5" color="black">Flight Details</Title>
|
||||
<Icon icon={ProductIcon} cls="w-5 h-5" />
|
||||
<Title size="h5" color="black">Product Details</Title>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<Badge variant="outline">
|
||||
{order.flightTicketInfo.flightType}
|
||||
</Badge>
|
||||
<Badge variant="secondary">
|
||||
{order.flightTicketInfo.cabinClass}
|
||||
</Badge>
|
||||
</div>
|
||||
{#if order.product.discountPrice > 0 && order.product.discountPrice < order.product.price}
|
||||
<Badge variant="success">Discounted</Badge>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<TicketLegsOverview data={order.flightTicketInfo} />
|
||||
<div class="flex flex-col gap-3">
|
||||
<div>
|
||||
<span class="text-sm text-gray-500">Product Name</span>
|
||||
<p class="font-medium">{order.product.title}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="text-sm text-gray-500">Description</span>
|
||||
<p class="text-gray-700">{order.product.description}</p>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<span class="text-sm text-gray-500">Regular Price</span>
|
||||
<p class="font-medium">${order.product.price.toFixed(2)}</p>
|
||||
</div>
|
||||
{#if order.product.discountPrice > 0}
|
||||
<div>
|
||||
<span class="text-sm text-gray-500">Discount Price</span>
|
||||
<p class="font-medium text-green-600">
|
||||
${order.product.discountPrice.toFixed(2)}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Price Summary -->
|
||||
<div class={cardStyle}>
|
||||
<div class="flex items-center gap-2">
|
||||
<Icon icon={CreditCardIcon} cls="w-5 h-5" />
|
||||
@@ -58,6 +79,11 @@
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="flex items-center justify-between">
|
||||
<span>Base Price</span>
|
||||
<span>${order.basePrice.toFixed(2)}</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between">
|
||||
<span>Display Price</span>
|
||||
<span>${order.displayPrice.toFixed(2)}</span>
|
||||
</div>
|
||||
|
||||
@@ -71,9 +97,19 @@
|
||||
{/if}
|
||||
|
||||
<div class="mt-2 flex items-center justify-between border-t pt-2">
|
||||
<span class="font-medium">Total Price</span>
|
||||
<span class="font-medium">Order Price</span>
|
||||
<span class="font-medium">${order.orderPrice.toFixed(2)}</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-gray-500">Fulfilled</span>
|
||||
<span class="text-sm">${order.fullfilledPrice.toFixed(2)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if order.customerInfo}
|
||||
<!-- Customer Information -->
|
||||
<CustomerDetailsCard customerInfo={order.customerInfo} />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,118 +1,115 @@
|
||||
<script lang="ts">
|
||||
import Icon from "$lib/components/atoms/icon.svelte";
|
||||
import Title from "$lib/components/atoms/title.svelte";
|
||||
import { adminSiteNavMap } from "$lib/core/constants";
|
||||
import { capitalize } from "$lib/core/string.utils";
|
||||
import CinfoCard from "$lib/domains/customerinfo/view/cinfo-card.svelte";
|
||||
import { Badge } from "$lib/components/ui/badge";
|
||||
import type { FullOrderModel } from "$lib/domains/order/data/entities";
|
||||
import SuitcaseIcon from "~icons/bi/suitcase2";
|
||||
import BagIcon from "~icons/lucide/briefcase";
|
||||
import BackpackIcon from "~icons/solar/backpack-linear";
|
||||
import PackageIcon from "~icons/solar/box-broken";
|
||||
import UsersIcon from "~icons/solar/users-group-rounded-broken";
|
||||
import { OrderStatus } from "$lib/domains/order/data/entities";
|
||||
import CalendarIcon from "~icons/solar/calendar-broken";
|
||||
import InfoIcon from "~icons/solar/info-circle-broken";
|
||||
|
||||
let { order }: { order: FullOrderModel } = $props();
|
||||
|
||||
const cardStyle =
|
||||
"flex flex-col gap-4 rounded-lg border border-gray-200 bg-white p-6 shadow-md";
|
||||
|
||||
function getStatusVariant(status: OrderStatus) {
|
||||
switch (status) {
|
||||
case OrderStatus.FULFILLED:
|
||||
return "success";
|
||||
case OrderStatus.PARTIALLY_FULFILLED:
|
||||
return "default";
|
||||
case OrderStatus.PENDING_FULFILLMENT:
|
||||
return "secondary";
|
||||
case OrderStatus.CANCELLED:
|
||||
return "destructive";
|
||||
default:
|
||||
return "outline";
|
||||
}
|
||||
}
|
||||
|
||||
function formatStatus(status: OrderStatus): string {
|
||||
return status
|
||||
.split("_")
|
||||
.map((word) => word.charAt(0) + word.slice(1).toLowerCase())
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
function formatDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString("en-US", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-6">
|
||||
<!-- Passenger Information -->
|
||||
<!-- Order Status -->
|
||||
<div class={cardStyle}>
|
||||
<div class="flex items-center gap-2">
|
||||
<Icon icon={UsersIcon} cls="w-5 h-5" />
|
||||
<Title size="h5" color="black">Passengers</Title>
|
||||
<Icon icon={InfoIcon} cls="w-5 h-5" />
|
||||
<Title size="h5" color="black">Order Status</Title>
|
||||
</div>
|
||||
|
||||
{#each order.passengerInfos as passenger, index}
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="font-semibold">
|
||||
Passenger {index + 1} ({capitalize(
|
||||
passenger.passengerType,
|
||||
)})
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-gray-600">Current Status</span>
|
||||
<Badge variant={getStatusVariant(order.status)}>
|
||||
{formatStatus(order.status)}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<!-- Personal Info -->
|
||||
<div class="rounded-lg border bg-gray-50 p-4">
|
||||
<div class="grid grid-cols-2 gap-3 text-sm md:grid-cols-3">
|
||||
<div>
|
||||
<span class="text-gray-500">Name</span>
|
||||
<p class="font-medium">
|
||||
{passenger.passengerPii.firstName}
|
||||
{passenger.passengerPii.middleName}
|
||||
{passenger.passengerPii.lastName}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500">Nationality</span>
|
||||
<p class="font-medium">
|
||||
{capitalize(passenger.passengerPii.nationality)}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500">Date of Birth</span>
|
||||
<p class="font-medium">
|
||||
{passenger.passengerPii.dob}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Baggage Info -->
|
||||
<div class="flex flex-wrap gap-4 text-sm">
|
||||
{#if passenger.bagSelection.personalBags > 0}
|
||||
<div class="flex items-center gap-2">
|
||||
<Icon
|
||||
icon={BackpackIcon}
|
||||
cls="h-5 w-5 text-gray-600"
|
||||
/>
|
||||
<span
|
||||
>{passenger.bagSelection.personalBags}x Personal
|
||||
Item</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
{#if passenger.bagSelection.handBags > 0}
|
||||
<div class="flex items-center gap-2">
|
||||
<Icon
|
||||
icon={SuitcaseIcon}
|
||||
cls="h-5 w-5 text-gray-600"
|
||||
/>
|
||||
<span
|
||||
>{passenger.bagSelection.handBags}x Cabin Bag</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
{#if passenger.bagSelection.checkedBags > 0}
|
||||
<div class="flex items-center gap-2">
|
||||
<Icon icon={BagIcon} cls="h-5 w-5 text-gray-600" />
|
||||
<span
|
||||
>{passenger.bagSelection.checkedBags}x Checked Bag</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 text-sm">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-gray-600">Order ID</span>
|
||||
<span class="font-medium">#{order.id}</span>
|
||||
</div>
|
||||
|
||||
{#if index < order.passengerInfos.length - 1}
|
||||
<div class="border-b border-dashed"></div>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if order.flightTicketInfo.refOIds}
|
||||
{#each order.flightTicketInfo.refOIds as refOId}
|
||||
<CinfoCard icon={PackageIcon} title="Order">
|
||||
<a
|
||||
href={`${adminSiteNavMap.orders}/${refOId}`}
|
||||
class="mt-1 inline-block font-medium text-primary hover:underline"
|
||||
>
|
||||
Reference Order #{refOId}
|
||||
</a>
|
||||
</CinfoCard>
|
||||
{/each}
|
||||
<!-- Timestamps -->
|
||||
<div class={cardStyle}>
|
||||
<div class="flex items-center gap-2">
|
||||
<Icon icon={CalendarIcon} cls="w-5 h-5" />
|
||||
<Title size="h5" color="black">Timeline</Title>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-3">
|
||||
<div>
|
||||
<span class="text-sm text-gray-500">Created At</span>
|
||||
<p class="font-medium">{formatDate(order.createdAt)}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="text-sm text-gray-500">Last Updated</span>
|
||||
<p class="font-medium">{formatDate(order.updatedAt)}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Additional Info -->
|
||||
{#if order.emailAccountId}
|
||||
<div class={cardStyle}>
|
||||
<div class="flex items-center gap-2">
|
||||
<Icon icon={InfoIcon} cls="w-5 h-5" />
|
||||
<Title size="h5" color="black">Additional Information</Title>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2 text-sm">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-gray-600">Email Account ID</span>
|
||||
<span class="font-medium">#{order.emailAccountId}</span>
|
||||
</div>
|
||||
|
||||
{#if order.paymentInfoId}
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-gray-600">Payment Info ID</span>
|
||||
<span class="font-medium">#{order.paymentInfoId}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { get } from "svelte/store";
|
||||
import {
|
||||
getDefaultOrderCursor,
|
||||
type PaginatedOrderInfoModel,
|
||||
type OrderCursorModel,
|
||||
getDefaultPaginatedOrderInfoModel,
|
||||
} from "../data/entities";
|
||||
import { encodeCursor } from "$lib/core/string.utils";
|
||||
import { trpcApiStore } from "$lib/stores/api";
|
||||
import type { Result } from "@pkg/result";
|
||||
import { toast } from "svelte-sonner";
|
||||
import { encodeCursor } from "$lib/core/string.utils";
|
||||
import { get } from "svelte/store";
|
||||
import {
|
||||
getDefaultOrderCursor,
|
||||
getDefaultPaginatedOrderInfoModel,
|
||||
type OrderCursorModel,
|
||||
type PaginatedOrderInfoModel,
|
||||
} from "../data/entities";
|
||||
|
||||
export class OrderViewModel {
|
||||
orderInfo = $state<PaginatedOrderInfoModel>(
|
||||
@@ -82,16 +82,7 @@ export class OrderViewModel {
|
||||
this.resetOrderInfo();
|
||||
return;
|
||||
}
|
||||
this.orderInfo = {
|
||||
...res.data,
|
||||
data: res.data.data.map((item) => {
|
||||
return {
|
||||
...item,
|
||||
createdAt: new Date(item.createdAt),
|
||||
updatedAt: new Date(item.updatedAt),
|
||||
};
|
||||
}),
|
||||
};
|
||||
this.orderInfo = { ...res.data, data: res.data.data };
|
||||
}
|
||||
|
||||
async searchOrders() {
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
getCoreRowModel,
|
||||
getPaginationRowModel,
|
||||
getFilteredRowModel,
|
||||
type ColumnDef,
|
||||
type PaginationState,
|
||||
type ColumnFiltersState,
|
||||
} from "@tanstack/table-core";
|
||||
import { goto } from "$app/navigation";
|
||||
import Title from "$lib/components/atoms/title.svelte";
|
||||
import DataTableActions from "$lib/components/molecules/data-table/data-table-actions.svelte";
|
||||
import DataTable from "$lib/components/molecules/data-table/data-table.svelte";
|
||||
import {
|
||||
createSvelteTable,
|
||||
renderComponent,
|
||||
} from "$lib/components/ui/data-table";
|
||||
import DataTable from "$lib/components/molecules/data-table/data-table.svelte";
|
||||
import DataTableActions from "$lib/components/molecules/data-table/data-table-actions.svelte";
|
||||
import Title from "$lib/components/atoms/title.svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { adminBasePath } from "$lib/core/constants";
|
||||
import { snakeToSpacedPascal } from "$lib/core/string.utils";
|
||||
import {
|
||||
getCoreRowModel,
|
||||
getFilteredRowModel,
|
||||
getPaginationRowModel,
|
||||
type ColumnDef,
|
||||
type ColumnFiltersState,
|
||||
type PaginationState,
|
||||
} from "@tanstack/table-core";
|
||||
import { useDebounce } from "runed";
|
||||
import type { FullOrderModel } from "../data/entities";
|
||||
import { orderVM } from "./order.vm.svelte";
|
||||
import { capitalize, snakeToSpacedPascal } from "$lib/core/string.utils";
|
||||
|
||||
let { data }: { data: FullOrderModel[] } = $props();
|
||||
|
||||
@@ -33,34 +33,45 @@
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Places",
|
||||
accessorKey: "direction",
|
||||
header: "Order ID",
|
||||
accessorKey: "orderId",
|
||||
cell: ({ row }) => {
|
||||
const r = row.original as FullOrderModel;
|
||||
return `${r.flightTicketInfo.departure} - ${r.flightTicketInfo.arrival}`;
|
||||
return `#${r.id}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Type",
|
||||
accessorKey: "type",
|
||||
header: "Product",
|
||||
accessorKey: "product",
|
||||
cell: ({ row }) => {
|
||||
const r = row.original as FullOrderModel;
|
||||
return capitalize(r.flightTicketInfo.flightType.toLowerCase());
|
||||
return r.product.title;
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Passenger(s)",
|
||||
accessorKey: "passengers",
|
||||
header: "Customer",
|
||||
accessorKey: "customer",
|
||||
cell: ({ row }) => {
|
||||
const _o = (row.original as FullOrderModel).flightTicketInfo
|
||||
.passengerCounts;
|
||||
return `${_o.adults + _o.children}`;
|
||||
const r = row.original as FullOrderModel;
|
||||
if (!r.customerInfo) return "N/A";
|
||||
return `${r.customerInfo.firstName} ${r.customerInfo.lastName}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Customer Email",
|
||||
accessorKey: "customerEmail",
|
||||
cell: ({ row }) => {
|
||||
const r = row.original as FullOrderModel;
|
||||
return r.customerInfo?.email || "N/A";
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Price",
|
||||
accessorKey: "orderPrice",
|
||||
cell: ({ row }) => (row.original as FullOrderModel).orderPrice!,
|
||||
cell: ({ row }) => {
|
||||
const r = row.original as FullOrderModel;
|
||||
return `$${r.orderPrice.toFixed(2)}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Status",
|
||||
@@ -141,7 +152,7 @@
|
||||
() => debounceDuration,
|
||||
);
|
||||
|
||||
let pageCount = $derived(2);
|
||||
let pageCount = $derived(Math.ceil(data.length / pagination.pageSize) || 1);
|
||||
</script>
|
||||
|
||||
{#if data.length > 0}
|
||||
@@ -162,7 +173,7 @@
|
||||
orderVM.query = q;
|
||||
debouncedSearch();
|
||||
}}
|
||||
filterFieldPlaceholder="Search users..."
|
||||
filterFieldPlaceholder="Search orders..."
|
||||
/>
|
||||
{:else}
|
||||
<div class="grid h-full place-items-center p-4 py-12 md:p-8 md:py-32">
|
||||
|
||||
@@ -1,34 +1,80 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
getCoreRowModel,
|
||||
getPaginationRowModel,
|
||||
getFilteredRowModel,
|
||||
type ColumnDef,
|
||||
type PaginationState,
|
||||
type ColumnFiltersState,
|
||||
} from "@tanstack/table-core";
|
||||
import { goto } from "$app/navigation";
|
||||
import Title from "$lib/components/atoms/title.svelte";
|
||||
import DataTableActions from "$lib/components/molecules/data-table/data-table-actions.svelte";
|
||||
import DataTable from "$lib/components/molecules/data-table/data-table.svelte";
|
||||
import {
|
||||
createSvelteTable,
|
||||
renderComponent,
|
||||
} from "$lib/components/ui/data-table";
|
||||
import DataTable from "$lib/components/molecules/data-table/data-table.svelte";
|
||||
import DataTableActions from "$lib/components/molecules/data-table/data-table-actions.svelte";
|
||||
import Title from "$lib/components/atoms/title.svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { adminBasePath } from "$lib/core/constants";
|
||||
import { orderVM } from "./order.vm.svelte";
|
||||
import {
|
||||
getCoreRowModel,
|
||||
getFilteredRowModel,
|
||||
getPaginationRowModel,
|
||||
type ColumnDef,
|
||||
type ColumnFiltersState,
|
||||
type PaginationState,
|
||||
} from "@tanstack/table-core";
|
||||
import { useDebounce } from "runed";
|
||||
import { OrderStatus } from "../data/entities";
|
||||
import { orderVM } from "./order.vm.svelte";
|
||||
|
||||
function getStatusVariant(status: OrderStatus) {
|
||||
switch (status) {
|
||||
case OrderStatus.FULFILLED:
|
||||
return "success";
|
||||
case OrderStatus.PARTIALLY_FULFILLED:
|
||||
return "default";
|
||||
case OrderStatus.PENDING_FULFILLMENT:
|
||||
return "secondary";
|
||||
case OrderStatus.CANCELLED:
|
||||
return "destructive";
|
||||
default:
|
||||
return "outline";
|
||||
}
|
||||
}
|
||||
|
||||
function formatStatus(status: OrderStatus): string {
|
||||
return status
|
||||
.split("_")
|
||||
.map((word) => word.charAt(0) + word.slice(1).toLowerCase())
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
// Define columns
|
||||
const columns: ColumnDef<any>[] = [
|
||||
{
|
||||
header: "Username",
|
||||
accessorKey: "username",
|
||||
header: "Order ID",
|
||||
accessorKey: "id",
|
||||
cell: ({ row }) => `#${row.original.id}`,
|
||||
},
|
||||
{
|
||||
header: "Email",
|
||||
accessorKey: "email",
|
||||
cell: ({ getValue }) => getValue<string>().toLowerCase(),
|
||||
header: "Product",
|
||||
id: "product",
|
||||
cell: ({ row }) => {
|
||||
return row.original.product.title;
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Price",
|
||||
id: "price",
|
||||
cell: ({ row }) => {
|
||||
const basePrice = row.original.displayPrice;
|
||||
const finalPrice = row.original.basePrice;
|
||||
const hasDiscount = row.original.discountAmount > 0;
|
||||
|
||||
return hasDiscount
|
||||
? `$${finalPrice.toFixed(2)} (was $${basePrice.toFixed(2)})`
|
||||
: `$${finalPrice.toFixed(2)}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Status",
|
||||
accessorKey: "status",
|
||||
cell: ({ row }) => {
|
||||
return formatStatus(row.original.status);
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Action",
|
||||
@@ -37,9 +83,11 @@
|
||||
return renderComponent(DataTableActions, {
|
||||
actions: [
|
||||
{
|
||||
title: "View agent",
|
||||
title: "View Order",
|
||||
action: () => {
|
||||
goto(`${adminBasePath}/users/${row.original.id}`);
|
||||
goto(
|
||||
`${adminBasePath}/orders/${row.original.id}`,
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -113,7 +161,7 @@
|
||||
orderVM.query = q;
|
||||
debouncedSearch();
|
||||
}}
|
||||
filterFieldPlaceholder="Search users..."
|
||||
filterFieldPlaceholder="Search orders..."
|
||||
/>
|
||||
{:else}
|
||||
<div class="grid place-items-center p-4 py-12 md:p-8 md:py-24">
|
||||
|
||||
@@ -2,17 +2,17 @@ import { eq, type Database } from "@pkg/db";
|
||||
import { paymentInfo } from "@pkg/db/schema";
|
||||
import { Logger } from "@pkg/logger";
|
||||
import type { Result } from "@pkg/result";
|
||||
import { paymentDetailsModel, type PaymentDetails } from "./data";
|
||||
import { paymentInfoModel, type PaymentInfo } from "./data";
|
||||
|
||||
export class PaymentInfoRepository {
|
||||
constructor(private db: Database) {}
|
||||
|
||||
async getPaymentInfo(id: number): Promise<Result<PaymentDetails>> {
|
||||
async getPaymentInfo(id: number): Promise<Result<PaymentInfo>> {
|
||||
Logger.info(`Getting payment info with id ${id}`);
|
||||
const out = await this.db.query.paymentInfo.findFirst({
|
||||
where: eq(paymentInfo.id, id),
|
||||
});
|
||||
const parsed = paymentDetailsModel.safeParse(out);
|
||||
const parsed = paymentInfoModel.safeParse(out);
|
||||
if (parsed.error) {
|
||||
Logger.error(parsed.error);
|
||||
return {};
|
||||
|
||||
Reference in New Issue
Block a user