feat: add location handling for TTO orders and update related components

This commit is contained in:
Danel Kungla
2025-09-30 18:05:32 +03:00
parent bfdd1ec62a
commit 52eac590a4
7 changed files with 62 additions and 7 deletions

View File

@@ -53,14 +53,14 @@ async function OrdersPage() {
/>
<PageBody>
{medusaOrders.map((medusaOrder) => {
const analysisOrder = analysisOrders.find(
({ medusa_order_id }) => medusa_order_id === medusaOrder.id,
);
if (!medusaOrder) {
return null;
}
const analysisOrder = analysisOrders.find(
({ medusa_order_id }) => medusa_order_id === medusaOrder.id,
);
const medusaOrderItems = medusaOrder.items || [];
const medusaOrderItemsAnalysisPackages = medusaOrderItems.filter(
(item) => item.product_type_id === analysisPackagesTypeId,

View File

@@ -11,6 +11,7 @@ import OrderItemsTable from './order-items-table';
export default function OrderBlock({
analysisOrder,
ttoLocation,
medusaOrderStatus,
itemsAnalysisPackage,
itemsTtoService,
@@ -18,6 +19,7 @@ export default function OrderBlock({
medusaOrderId,
}: {
analysisOrder?: AnalysisOrder;
ttoLocation?: { name: string };
medusaOrderStatus: string;
itemsAnalysisPackage: StoreOrderLineItem[];
itemsTtoService: StoreOrderLineItem[];
@@ -67,6 +69,7 @@ export default function OrderBlock({
order={{
status: medusaOrderStatus.toUpperCase(),
medusaOrderId,
location: ttoLocation?.name,
}}
/>
)}

View File

@@ -61,6 +61,11 @@ export default function OrderItemsTable({
<TableHead className="px-6">
<Trans i18nKey="orders:table.createdAt" />
</TableHead>
{order.location && (
<TableHead className="px-6">
<Trans i18nKey="orders:table.location" />
</TableHead>
)}
<TableHead className="px-6">
<Trans i18nKey="orders:table.status" />
</TableHead>
@@ -83,7 +88,11 @@ export default function OrderItemsTable({
<TableCell className="px-6 whitespace-nowrap">
{formatDate(orderItem.created_at, 'dd.MM.yyyy HH:mm')}
</TableCell>
{order.location && (
<TableCell className="min-w-[180px] px-6">
{order.location}
</TableCell>
)}
<TableCell className="min-w-[180px] px-6">
<Trans
i18nKey={`orders:status.${type}.${order?.status ?? 'CONFIRMED'}`}

View File

@@ -205,5 +205,42 @@ export async function getTtoOrders({
const orders = await query
.order('created_at', { ascending: false })
.throwOnError();
return orders.data;
const ordersWithLocation = await Promise.all(
orders.data.map(async (order) => ({
...order,
location: await getTtoLocation(order.location_sync_id),
})),
);
return ordersWithLocation;
}
export async function getTtoLocation(syncId?: number | null) {
if (!syncId) {
return null;
}
const client = getSupabaseServerClient();
const {
data: { user },
} = await client.auth.getUser();
if (!user) {
throw new Error('Unauthorized');
}
const { data, error } = await client
.schema('medreport')
.from('connected_online_locations')
.select('name')
.eq('sync_id', syncId)
.single();
if (error) {
throw new Error('Could not receive online locations: ', error);
}
return data;
}

View File

@@ -9,4 +9,5 @@ export type Order = {
medusaOrderId?: string;
id?: number;
status?: string;
location?: string;
};

View File

@@ -7,7 +7,8 @@
"ttoService": "Broneering",
"otherOrders": "Tellimus",
"createdAt": "Tellitud",
"status": "Olek"
"status": "Olek",
"location": "Asukoht"
},
"status": {
"QUEUED": "Esitatud",

View File

@@ -0,0 +1,4 @@
ALTER TABLE medreport.connected_online_reservation
ADD CONSTRAINT fk_reservation_location_sync_id
FOREIGN KEY (location_sync_id)
REFERENCES medreport.connected_online_locations(sync_id);