OrderSingle
One order's details for its customer: items, amounts, shipping and status, with reorder, cancel, receipt and rating actions.
import { OrderSingle, OrderSinglePage, orderSingleLoader, OrderSinglePageProps } from '@salla.sa/twilight-theme-engine/routes/account/orders';In plain words
/account/orders/<id> shows one of the customer's orders in full: what was bought, what it cost, how it ships and where it is. Depending on the order, the customer can reorder it, cancel it, print the receipt or rate it.
Signature
const OrderSingle: {
readonly id: 'customer.orders.single';
readonly loader: (
ctx: { params: { id: string }; locale?: string },
extend?: (data: OrderSinglePageProps, ctx: { params: { id: string } }) => Record<string, unknown> | Promise<Record<string, unknown>>
) => Promise<OrderSinglePageProps>;
readonly head: (ctx: TwilightContext, data: OrderSinglePageProps) => HeadDescriptor;
readonly Component: React.LazyExoticComponent<(props: OrderSinglePageProps) => JSX.Element>;
};
const OrderSinglePage: typeof OrderSingle.Component;
function orderSingleLoader({ params }: { params: { id: string } }): Promise<OrderSinglePageProps>;
interface OrderSinglePageProps {
page: Page; // { slug: 'customer.orders.single', id, title }
order: Order;
}Example
import { createFileRoute } from '@tanstack/react-router';
import { OrderSingle } from '@salla.sa/twilight-theme-engine/routes/account/orders';
import type { OrderSinglePageProps } from '@salla.sa/twilight-theme-engine/routes/account/orders';
import { CustomerPageSkeleton } from '@salla.sa/twilight-theme-engine/skeleton';
import { withHead } from '@salla.sa/twilight-theme-engine/tanstack';
export const Route = createFileRoute('/{-$locale}/account/orders/$id')({
loader: ({ params }): Promise<OrderSinglePageProps> =>
OrderSingle.loader({ params: { id: params.id }, locale: params.locale }),
head: withHead(OrderSingle),
pendingComponent: () => <CustomerPageSkeleton />,
component: OrderSingleComponent,
});
function OrderSingleComponent() {
const data: OrderSinglePageProps = Route.useLoaderData();
return <OrderSingle.Component {...data} />;
}
How it behaves
orderSingleLoadercallsorder.findOrThrow(id), which isorUnauthorized(order.find(id)). The title is thepages.orders.order_detailstranslation with:idreplaced by the id (orOrder Details).headsets the title and hreflang alternates only.OrderSinglePageignorespage. In the browser it loads the shipments when the order is shippable and the ratings when it is rateable. Reorder callsSalla.order.createCartFromOrder(id)and then navigates to/cart; cancel callsSalla.order.cancel(id); print opensorder.urls.receiptin a window. Slots:customer:orders.single.details.startandcustomer:orders.single.details.end.Also re-exported from
@salla.sa/twilight-theme-engine/routes/account.
Gotchas
A wrong order id does not show the 404 page.
orUnauthorizedturns only a 401 or 403 into the 401 page; any other API error reaches the router's default error component as a 400 page. That includes a guest: Salla answers400 token_not_provided, not 401.
Related
The signed-in customer's order history, optionally filtered by status, as a table that loads more orders on request.
Order, OrderItem, OrderListItemThe order shapes the account and thank-you pages use: a full order, one line of it, and the lighter row the orders list returns.
ThankYouThe order confirmation page Salla sends shoppers to after paying, which renders even when the order details cannot be loaded.
Source and docs
- Engine source:
packages/theme-engine/src/routes/account/orders/index.tsx