feat: add location handling for TTO orders and update related components
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -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'}`}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -9,4 +9,5 @@ export type Order = {
|
||||
medusaOrderId?: string;
|
||||
id?: number;
|
||||
status?: string;
|
||||
location?: string;
|
||||
};
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
"ttoService": "Broneering",
|
||||
"otherOrders": "Tellimus",
|
||||
"createdAt": "Tellitud",
|
||||
"status": "Olek"
|
||||
"status": "Olek",
|
||||
"location": "Asukoht"
|
||||
},
|
||||
"status": {
|
||||
"QUEUED": "Esitatud",
|
||||
|
||||
4
supabase/migrations/20250930175100_update_tto_tables.sql
Normal file
4
supabase/migrations/20250930175100_update_tto_tables.sql
Normal 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);
|
||||
Reference in New Issue
Block a user