MED-102: improve tto orders view
MED-102
This commit is contained in:
@@ -26,17 +26,7 @@ async function OrderConfirmedPage(props: {
|
||||
params: Promise<{ orderId: string }>;
|
||||
}) {
|
||||
const params = await props.params;
|
||||
|
||||
const order = await getAnalysisOrder({
|
||||
analysisOrderId: Number(params.orderId),
|
||||
}).catch(() => null);
|
||||
if (!order) {
|
||||
redirect(pathsConfig.app.myOrders);
|
||||
}
|
||||
|
||||
const medusaOrder = await retrieveOrder(order.medusa_order_id).catch(
|
||||
() => null,
|
||||
);
|
||||
const medusaOrder = await retrieveOrder(params.orderId).catch(() => null);
|
||||
if (!medusaOrder) {
|
||||
redirect(pathsConfig.app.myOrders);
|
||||
}
|
||||
@@ -46,7 +36,12 @@ async function OrderConfirmedPage(props: {
|
||||
<PageHeader title={<Trans i18nKey="cart:order.title" />} />
|
||||
<Divider />
|
||||
<div className="small:grid-cols-[1fr_360px] grid grid-cols-1 gap-x-40 gap-y-6 lg:px-4">
|
||||
<OrderDetails order={order} />
|
||||
<OrderDetails
|
||||
order={{
|
||||
id: medusaOrder.id,
|
||||
created_at: medusaOrder.created_at,
|
||||
}}
|
||||
/>
|
||||
<Divider />
|
||||
<OrderItems medusaOrder={medusaOrder} />
|
||||
<CartTotals medusaOrder={medusaOrder} />
|
||||
|
||||
@@ -56,6 +56,7 @@ async function OrdersPage() {
|
||||
const analysisOrder = analysisOrders.find(
|
||||
({ medusa_order_id }) => medusa_order_id === medusaOrder.id,
|
||||
);
|
||||
|
||||
if (!medusaOrder) {
|
||||
return null;
|
||||
}
|
||||
@@ -81,6 +82,7 @@ async function OrdersPage() {
|
||||
<OrderBlock
|
||||
medusaOrderId={medusaOrder.id}
|
||||
analysisOrder={analysisOrder}
|
||||
medusaOrderStatus={medusaOrder.status}
|
||||
itemsAnalysisPackage={medusaOrderItemsAnalysisPackages}
|
||||
itemsTtoService={medusaOrderItemsTtoServices}
|
||||
itemsOther={medusaOrderItemsOther}
|
||||
@@ -88,7 +90,7 @@ async function OrdersPage() {
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
{analysisOrders.length === 0 && (
|
||||
{analysisOrders.length === 0 && ttoOrders.length === 0 && (
|
||||
<h5 className="mt-6">
|
||||
<Trans i18nKey="orders:noOrders" />
|
||||
</h5>
|
||||
|
||||
@@ -167,15 +167,17 @@ const TimeSlots = ({
|
||||
return toast.error(t('booking:serviceNotFound'));
|
||||
}
|
||||
|
||||
const bookTimePromise = updateReservationTime(
|
||||
const bookTimePromise = updateReservationTime({
|
||||
reservationId,
|
||||
timeSlot.StartTime,
|
||||
Number(syncedService.id),
|
||||
timeSlot.UserID,
|
||||
timeSlot.SyncUserID,
|
||||
booking.selectedLocationId ? booking.selectedLocationId : null,
|
||||
newStartTime: timeSlot.StartTime,
|
||||
newServiceId: Number(syncedService.id),
|
||||
newAppointmentUserId: timeSlot.UserID,
|
||||
newSyncUserId: timeSlot.SyncUserID,
|
||||
newLocationId: booking.selectedLocationId
|
||||
? booking.selectedLocationId
|
||||
: null,
|
||||
cartId,
|
||||
);
|
||||
});
|
||||
|
||||
toast.promise(() => bookTimePromise, {
|
||||
success: <Trans i18nKey={'booking:bookTimeSuccess'} />,
|
||||
|
||||
@@ -2,16 +2,20 @@ import { formatDate } from 'date-fns';
|
||||
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import type { AnalysisOrder } from '~/lib/types/analysis-order';
|
||||
import type { AnalysisOrder } from '~/lib/types/order';
|
||||
|
||||
export default function OrderDetails({ order }: { order: AnalysisOrder }) {
|
||||
export default function OrderDetails({
|
||||
order,
|
||||
}: {
|
||||
order: { id: string; created_at: string | Date };
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-col gap-y-2">
|
||||
<div>
|
||||
<span className="font-bold">
|
||||
<Trans i18nKey="cart:orderConfirmed.orderNumber" />:{' '}
|
||||
</span>
|
||||
<span>{order.medusa_order_id}</span>
|
||||
<span>{order.id}</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
@@ -5,18 +5,20 @@ import { Eye } from 'lucide-react';
|
||||
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
|
||||
import type { AnalysisOrder } from '~/lib/types/analysis-order';
|
||||
import type { AnalysisOrder } from '~/lib/types/order';
|
||||
|
||||
import OrderItemsTable from './order-items-table';
|
||||
|
||||
export default function OrderBlock({
|
||||
analysisOrder,
|
||||
medusaOrderStatus,
|
||||
itemsAnalysisPackage,
|
||||
itemsTtoService,
|
||||
itemsOther,
|
||||
medusaOrderId,
|
||||
}: {
|
||||
analysisOrder?: AnalysisOrder;
|
||||
medusaOrderStatus: string;
|
||||
itemsAnalysisPackage: StoreOrderLineItem[];
|
||||
itemsTtoService: StoreOrderLineItem[];
|
||||
itemsOther: StoreOrderLineItem[];
|
||||
@@ -50,7 +52,11 @@ export default function OrderBlock({
|
||||
<OrderItemsTable
|
||||
items={itemsAnalysisPackage}
|
||||
title="orders:table.analysisPackage"
|
||||
analysisOrder={analysisOrder}
|
||||
order={{
|
||||
medusaOrderId: analysisOrder.medusa_order_id,
|
||||
id: analysisOrder.id,
|
||||
status: analysisOrder.status,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{itemsTtoService && (
|
||||
@@ -58,12 +64,18 @@ export default function OrderBlock({
|
||||
items={itemsTtoService}
|
||||
title="orders:table.ttoService"
|
||||
type="ttoService"
|
||||
order={{
|
||||
status: medusaOrderStatus.toUpperCase(),
|
||||
medusaOrderId,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<OrderItemsTable
|
||||
items={itemsOther}
|
||||
title="orders:table.otherOrders"
|
||||
analysisOrder={analysisOrder}
|
||||
order={{
|
||||
status: analysisOrder?.status,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from '@kit/ui/table';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import type { AnalysisOrder } from '~/lib/types/analysis-order';
|
||||
import type { Order } from '~/lib/types/order';
|
||||
|
||||
import { logAnalysisResultsNavigateAction } from './actions';
|
||||
|
||||
@@ -26,12 +26,12 @@ export type OrderItemType = 'analysisOrder' | 'ttoService';
|
||||
export default function OrderItemsTable({
|
||||
items,
|
||||
title,
|
||||
analysisOrder,
|
||||
order,
|
||||
type = 'analysisOrder',
|
||||
}: {
|
||||
items: StoreOrderLineItem[];
|
||||
title: string;
|
||||
analysisOrder?: AnalysisOrder;
|
||||
order: Order;
|
||||
type?: OrderItemType;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
@@ -42,10 +42,12 @@ export default function OrderItemsTable({
|
||||
|
||||
const isAnalysisOrder = type === 'analysisOrder';
|
||||
|
||||
const openAnalysisResults = async () => {
|
||||
if (analysisOrder) {
|
||||
await logAnalysisResultsNavigateAction(analysisOrder.medusa_order_id);
|
||||
router.push(`${pathsConfig.app.analysisResults}/${analysisOrder.id}`);
|
||||
const openDetailedView = async () => {
|
||||
if (isAnalysisOrder && order?.medusaOrderId && order?.id) {
|
||||
await logAnalysisResultsNavigateAction(order.medusaOrderId);
|
||||
router.push(`${pathsConfig.app.analysisResults}/${order.id}`);
|
||||
} else {
|
||||
router.push(`${pathsConfig.app.myOrders}/${order.medusaOrderId}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -84,17 +86,15 @@ export default function OrderItemsTable({
|
||||
|
||||
<TableCell className="min-w-[180px] px-6">
|
||||
<Trans
|
||||
i18nKey={`orders:status.${type}.${analysisOrder?.status ?? 'CONFIRMED'}`}
|
||||
i18nKey={`orders:status.${type}.${order?.status ?? 'CONFIRMED'}`}
|
||||
/>
|
||||
</TableCell>
|
||||
|
||||
{isAnalysisOrder && (
|
||||
<TableCell className="px-6 text-right">
|
||||
<Button size="sm" onClick={openAnalysisResults}>
|
||||
<Trans i18nKey="analysis-results:view" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
)}
|
||||
<TableCell className="px-6 text-right">
|
||||
<Button size="sm" onClick={openDetailedView}>
|
||||
<Trans i18nKey="analysis-results:view" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
|
||||
@@ -23,16 +23,16 @@ export async function createInitialReservationAction(
|
||||
});
|
||||
|
||||
if (addedItem) {
|
||||
const reservation = await createInitialReservation(
|
||||
const reservation = await createInitialReservation({
|
||||
serviceId,
|
||||
clinicId,
|
||||
appointmentUserId,
|
||||
syncUserId,
|
||||
syncUserID: syncUserId,
|
||||
startTime,
|
||||
addedItem.id,
|
||||
medusaLineItemId: addedItem.id,
|
||||
locationId,
|
||||
comments,
|
||||
);
|
||||
});
|
||||
|
||||
await updateLineItem({
|
||||
lineId: addedItem.id,
|
||||
|
||||
@@ -16,8 +16,8 @@ import axios from 'axios';
|
||||
import { toArray } from '@kit/shared/utils';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
|
||||
import type { AnalysisOrder } from '~/lib/types/analysis-order';
|
||||
import type { AnalysisResponseElement } from '~/lib/types/analysis-response-element';
|
||||
import type { AnalysisOrder } from '~/lib/types/order';
|
||||
|
||||
import { getAccountAdmin } from '../account.service';
|
||||
import { getAnalyses } from '../analyses.service';
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Tables } from '@kit/supabase/database';
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import type { AnalysisOrder } from '../types/analysis-order';
|
||||
import type { AnalysisOrder, TTOOrder } from '../types/order';
|
||||
|
||||
export async function createAnalysisOrder({
|
||||
medusaOrder,
|
||||
@@ -176,10 +176,7 @@ export async function getTtoOrders({
|
||||
orderStatus,
|
||||
lineItemIds,
|
||||
}: {
|
||||
orderStatus?: Tables<
|
||||
{ schema: 'medreport' },
|
||||
'connected_online_reservation'
|
||||
>['status'];
|
||||
orderStatus?: TTOOrder['status'];
|
||||
lineItemIds?: string[];
|
||||
} = {}) {
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
@@ -150,16 +150,25 @@ export async function getCartReservations(
|
||||
return results;
|
||||
}
|
||||
|
||||
export async function createInitialReservation(
|
||||
serviceId: number,
|
||||
clinicId: number,
|
||||
appointmentUserId: number,
|
||||
syncUserID: number,
|
||||
startTime: Date,
|
||||
medusaLineItemId: string,
|
||||
locationId?: number | null,
|
||||
export async function createInitialReservation({
|
||||
serviceId,
|
||||
clinicId,
|
||||
appointmentUserId,
|
||||
syncUserID,
|
||||
startTime,
|
||||
medusaLineItemId,
|
||||
locationId,
|
||||
comments = '',
|
||||
) {
|
||||
}: {
|
||||
serviceId: number;
|
||||
clinicId: number;
|
||||
appointmentUserId: number;
|
||||
syncUserID: number;
|
||||
startTime: Date;
|
||||
medusaLineItemId: string;
|
||||
locationId?: number | null;
|
||||
comments?: string;
|
||||
}) {
|
||||
const logger = await getLogger();
|
||||
const supabase = getSupabaseServerClient();
|
||||
|
||||
@@ -255,15 +264,23 @@ export async function getOrderedTtoServices({
|
||||
return orderedTtoServices;
|
||||
}
|
||||
|
||||
export async function updateReservationTime(
|
||||
reservationId: number,
|
||||
newStartTime: Date,
|
||||
newServiceId: number,
|
||||
newAppointmentUserId: number,
|
||||
newSyncUserId: number,
|
||||
newLocationId: number | null, // TODO stop allowing null when Connected starts returning the correct ids instead of -1
|
||||
cartId: string,
|
||||
) {
|
||||
export async function updateReservationTime({
|
||||
reservationId,
|
||||
newStartTime,
|
||||
newServiceId,
|
||||
newAppointmentUserId,
|
||||
newSyncUserId,
|
||||
newLocationId, // TODO stop allowing null when Connected starts returning the correct ids instead of -1
|
||||
cartId,
|
||||
}: {
|
||||
reservationId: number;
|
||||
newStartTime: Date;
|
||||
newServiceId: number;
|
||||
newAppointmentUserId: number;
|
||||
newSyncUserId: number;
|
||||
newLocationId: number | null;
|
||||
cartId: string;
|
||||
}) {
|
||||
const logger = await getLogger();
|
||||
const supabase = getSupabaseServerClient();
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import type { Tables } from '@kit/supabase/database';
|
||||
|
||||
export type AnalysisOrder = Tables<{ schema: 'medreport' }, 'analysis_orders'>;
|
||||
12
lib/types/order.ts
Normal file
12
lib/types/order.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { Tables } from '@kit/supabase/database';
|
||||
|
||||
export type AnalysisOrder = Tables<{ schema: 'medreport' }, 'analysis_orders'>;
|
||||
export type TTOOrder = Tables<
|
||||
{ schema: 'medreport' },
|
||||
'connected_online_reservation'
|
||||
>;
|
||||
export type Order = {
|
||||
medusaOrderId?: string;
|
||||
id?: number;
|
||||
status?: string;
|
||||
};
|
||||
@@ -61,11 +61,6 @@ export const listOrders = async (
|
||||
};
|
||||
|
||||
export const createTransferRequest = async (
|
||||
state: {
|
||||
success: boolean;
|
||||
error: string | null;
|
||||
order: HttpTypes.StoreOrder | null;
|
||||
},
|
||||
formData: FormData,
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
"CANCELLED": "Tühistatud"
|
||||
},
|
||||
"ttoService": {
|
||||
"PENDING": "Alustatud",
|
||||
"PENDING": "Laekumise ootel",
|
||||
"CONFIRMED": "Kinnitatud",
|
||||
"REJECTED": "Tagasi lükatud",
|
||||
"CANCELLED": "Tühistatud"
|
||||
|
||||
Reference in New Issue
Block a user