feat: add location handling for TTO orders and update related components
This commit is contained in:
@@ -53,14 +53,14 @@ async function OrdersPage() {
|
|||||||
/>
|
/>
|
||||||
<PageBody>
|
<PageBody>
|
||||||
{medusaOrders.map((medusaOrder) => {
|
{medusaOrders.map((medusaOrder) => {
|
||||||
const analysisOrder = analysisOrders.find(
|
|
||||||
({ medusa_order_id }) => medusa_order_id === medusaOrder.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!medusaOrder) {
|
if (!medusaOrder) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const analysisOrder = analysisOrders.find(
|
||||||
|
({ medusa_order_id }) => medusa_order_id === medusaOrder.id,
|
||||||
|
);
|
||||||
|
|
||||||
const medusaOrderItems = medusaOrder.items || [];
|
const medusaOrderItems = medusaOrder.items || [];
|
||||||
const medusaOrderItemsAnalysisPackages = medusaOrderItems.filter(
|
const medusaOrderItemsAnalysisPackages = medusaOrderItems.filter(
|
||||||
(item) => item.product_type_id === analysisPackagesTypeId,
|
(item) => item.product_type_id === analysisPackagesTypeId,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import OrderItemsTable from './order-items-table';
|
|||||||
|
|
||||||
export default function OrderBlock({
|
export default function OrderBlock({
|
||||||
analysisOrder,
|
analysisOrder,
|
||||||
|
ttoLocation,
|
||||||
medusaOrderStatus,
|
medusaOrderStatus,
|
||||||
itemsAnalysisPackage,
|
itemsAnalysisPackage,
|
||||||
itemsTtoService,
|
itemsTtoService,
|
||||||
@@ -18,6 +19,7 @@ export default function OrderBlock({
|
|||||||
medusaOrderId,
|
medusaOrderId,
|
||||||
}: {
|
}: {
|
||||||
analysisOrder?: AnalysisOrder;
|
analysisOrder?: AnalysisOrder;
|
||||||
|
ttoLocation?: { name: string };
|
||||||
medusaOrderStatus: string;
|
medusaOrderStatus: string;
|
||||||
itemsAnalysisPackage: StoreOrderLineItem[];
|
itemsAnalysisPackage: StoreOrderLineItem[];
|
||||||
itemsTtoService: StoreOrderLineItem[];
|
itemsTtoService: StoreOrderLineItem[];
|
||||||
@@ -67,6 +69,7 @@ export default function OrderBlock({
|
|||||||
order={{
|
order={{
|
||||||
status: medusaOrderStatus.toUpperCase(),
|
status: medusaOrderStatus.toUpperCase(),
|
||||||
medusaOrderId,
|
medusaOrderId,
|
||||||
|
location: ttoLocation?.name,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ export default function OrderItemsTable({
|
|||||||
<TableHead className="px-6">
|
<TableHead className="px-6">
|
||||||
<Trans i18nKey="orders:table.createdAt" />
|
<Trans i18nKey="orders:table.createdAt" />
|
||||||
</TableHead>
|
</TableHead>
|
||||||
|
{order.location && (
|
||||||
|
<TableHead className="px-6">
|
||||||
|
<Trans i18nKey="orders:table.location" />
|
||||||
|
</TableHead>
|
||||||
|
)}
|
||||||
<TableHead className="px-6">
|
<TableHead className="px-6">
|
||||||
<Trans i18nKey="orders:table.status" />
|
<Trans i18nKey="orders:table.status" />
|
||||||
</TableHead>
|
</TableHead>
|
||||||
@@ -83,7 +88,11 @@ export default function OrderItemsTable({
|
|||||||
<TableCell className="px-6 whitespace-nowrap">
|
<TableCell className="px-6 whitespace-nowrap">
|
||||||
{formatDate(orderItem.created_at, 'dd.MM.yyyy HH:mm')}
|
{formatDate(orderItem.created_at, 'dd.MM.yyyy HH:mm')}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
{order.location && (
|
||||||
|
<TableCell className="min-w-[180px] px-6">
|
||||||
|
{order.location}
|
||||||
|
</TableCell>
|
||||||
|
)}
|
||||||
<TableCell className="min-w-[180px] px-6">
|
<TableCell className="min-w-[180px] px-6">
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey={`orders:status.${type}.${order?.status ?? 'CONFIRMED'}`}
|
i18nKey={`orders:status.${type}.${order?.status ?? 'CONFIRMED'}`}
|
||||||
|
|||||||
@@ -205,5 +205,42 @@ export async function getTtoOrders({
|
|||||||
const orders = await query
|
const orders = await query
|
||||||
.order('created_at', { ascending: false })
|
.order('created_at', { ascending: false })
|
||||||
.throwOnError();
|
.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;
|
medusaOrderId?: string;
|
||||||
id?: number;
|
id?: number;
|
||||||
status?: string;
|
status?: string;
|
||||||
|
location?: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
"ttoService": "Broneering",
|
"ttoService": "Broneering",
|
||||||
"otherOrders": "Tellimus",
|
"otherOrders": "Tellimus",
|
||||||
"createdAt": "Tellitud",
|
"createdAt": "Tellitud",
|
||||||
"status": "Olek"
|
"status": "Olek",
|
||||||
|
"location": "Asukoht"
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
"QUEUED": "Esitatud",
|
"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