add fields to tto order view
This commit is contained in:
@@ -4,6 +4,7 @@ import CartTotals from '@/app/home/(user)/_components/order/cart-totals';
|
||||
import OrderDetails from '@/app/home/(user)/_components/order/order-details';
|
||||
import OrderItems from '@/app/home/(user)/_components/order/order-items';
|
||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
import { retrieveOrder } from '@lib/data/orders';
|
||||
import Divider from '@modules/common/components/divider';
|
||||
|
||||
@@ -12,7 +13,6 @@ import { PageBody, PageHeader } from '@kit/ui/page';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
import { getAnalysisOrder } from '~/lib/services/order.service';
|
||||
|
||||
export async function generateMetadata() {
|
||||
const { t } = await createI18nServerInstance();
|
||||
@@ -25,11 +25,42 @@ export async function generateMetadata() {
|
||||
async function OrderConfirmedPage(props: {
|
||||
params: Promise<{ orderId: string }>;
|
||||
}) {
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
const params = await props.params;
|
||||
const medusaOrder = await retrieveOrder(params.orderId).catch(() => null);
|
||||
if (!medusaOrder) {
|
||||
redirect(pathsConfig.app.myOrders);
|
||||
}
|
||||
const ttoReservationId =
|
||||
medusaOrder.items &&
|
||||
(medusaOrder.items.find(
|
||||
({ metadata }) => !!metadata?.connectedOnlineReservationId,
|
||||
)?.metadata?.connectedOnlineReservationId as number);
|
||||
|
||||
const [{ data: ttoReservation }] = await Promise.all([
|
||||
ttoReservationId
|
||||
? await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('connected_online_reservation')
|
||||
.select('*')
|
||||
.eq('id', ttoReservationId)
|
||||
.single()
|
||||
: { data: null },
|
||||
]);
|
||||
const [{ data: location }, { data: serviceProvider }] = await Promise.all([
|
||||
supabaseClient
|
||||
.schema('medreport')
|
||||
.from('connected_online_locations')
|
||||
.select('name,address')
|
||||
.eq('sync_id', ttoReservation.location_sync_id || 0)
|
||||
.single(),
|
||||
supabaseClient
|
||||
.schema('medreport')
|
||||
.from('connected_online_providers')
|
||||
.select('email,phone_number,name')
|
||||
.eq('id', ttoReservation.clinic_id)
|
||||
.single(),
|
||||
]);
|
||||
|
||||
return (
|
||||
<PageBody>
|
||||
@@ -40,6 +71,8 @@ async function OrderConfirmedPage(props: {
|
||||
order={{
|
||||
id: medusaOrder.id,
|
||||
created_at: medusaOrder.created_at,
|
||||
location,
|
||||
serviceProvider,
|
||||
}}
|
||||
/>
|
||||
<Divider />
|
||||
|
||||
@@ -66,6 +66,15 @@ async function OrdersPage() {
|
||||
({ medusa_order_id }) => medusa_order_id === medusaOrder.id,
|
||||
);
|
||||
|
||||
const ttoReservation = ttoOrders.find(({ id }) => {
|
||||
const connectedOnlineReservationId =
|
||||
medusaOrder?.items &&
|
||||
medusaOrder.items.find(
|
||||
({ metadata }) => !!metadata?.connectedOnlineReservationId,
|
||||
)?.metadata?.connectedOnlineReservationId;
|
||||
return id === connectedOnlineReservationId;
|
||||
});
|
||||
|
||||
const medusaOrderItems = medusaOrder.items || [];
|
||||
const medusaOrderItemsAnalysisPackages = medusaOrderItems.filter(
|
||||
(item) => item.product_type_id === analysisPackagesTypeId,
|
||||
@@ -87,6 +96,7 @@ async function OrdersPage() {
|
||||
<OrderBlock
|
||||
medusaOrderId={medusaOrder.id}
|
||||
analysisOrder={analysisOrder}
|
||||
ttoReservation={ttoReservation}
|
||||
medusaOrderStatus={medusaOrder.status}
|
||||
itemsAnalysisPackage={medusaOrderItemsAnalysisPackages}
|
||||
itemsTtoService={medusaOrderItemsTtoServices}
|
||||
|
||||
@@ -1,27 +1,63 @@
|
||||
import { formatDate } from 'date-fns';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
export default function OrderDetails({
|
||||
order,
|
||||
}: {
|
||||
order: { id: string; created_at: string | Date };
|
||||
order: {
|
||||
id: string;
|
||||
created_at: string | Date;
|
||||
location: Pick<
|
||||
Database['medreport']['Tables']['connected_online_locations']['Row'],
|
||||
'name' | 'address'
|
||||
> | null;
|
||||
serviceProvider: Pick<
|
||||
Database['medreport']['Tables']['connected_online_providers']['Row'],
|
||||
'email' | 'phone_number' | 'name'
|
||||
> | null;
|
||||
};
|
||||
}) {
|
||||
const { id, created_at, location, serviceProvider } = order;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-y-2">
|
||||
<div>
|
||||
<span className="font-bold">
|
||||
<Trans i18nKey="cart:orderConfirmed.orderNumber" />:{' '}
|
||||
</span>
|
||||
<span className="break-all">{order.id}</span>
|
||||
<span className="break-all">{id}</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span className="font-bold">
|
||||
<Trans i18nKey="cart:orderConfirmed.orderDate" />:{' '}
|
||||
</span>
|
||||
<span>{formatDate(order.created_at, 'dd.MM.yyyy HH:mm')}</span>
|
||||
<span>{formatDate(created_at, 'dd.MM.yyyy HH:mm')}</span>
|
||||
</div>
|
||||
{(location?.name || location?.address) && (
|
||||
<div>
|
||||
<span className="font-bold">
|
||||
<Trans i18nKey="cart:orderConfirmed.location" />:{' '}
|
||||
</span>
|
||||
<span>
|
||||
{location.name || location.address}{' '}
|
||||
{location?.name ? location.address : ''}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{serviceProvider && (
|
||||
<div className="flex flex-col">
|
||||
<span className="font-bold">
|
||||
<Trans i18nKey="cart:orderConfirmed.serviceProvider" />:{' '}
|
||||
</span>
|
||||
<span>{serviceProvider.name}</span>
|
||||
<span>{serviceProvider.phone_number}</span>
|
||||
<span>{serviceProvider.email}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@ import { Eye } from 'lucide-react';
|
||||
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
|
||||
import type { AnalysisOrder } from '~/lib/types/order';
|
||||
import type { AnalysisOrder, TTOOrder } from '~/lib/types/order';
|
||||
|
||||
import OrderItemsTable from './order-items-table';
|
||||
|
||||
export default function OrderBlock({
|
||||
analysisOrder,
|
||||
ttoLocation,
|
||||
ttoReservation,
|
||||
medusaOrderStatus,
|
||||
itemsAnalysisPackage,
|
||||
itemsTtoService,
|
||||
@@ -20,6 +21,7 @@ export default function OrderBlock({
|
||||
}: {
|
||||
analysisOrder?: AnalysisOrder;
|
||||
ttoLocation?: { name: string };
|
||||
ttoReservation?: TTOOrder;
|
||||
medusaOrderStatus: string;
|
||||
itemsAnalysisPackage: StoreOrderLineItem[];
|
||||
itemsTtoService: StoreOrderLineItem[];
|
||||
@@ -70,6 +72,8 @@ export default function OrderBlock({
|
||||
status: medusaOrderStatus.toUpperCase(),
|
||||
medusaOrderId,
|
||||
location: ttoLocation?.name,
|
||||
bookingCode: ttoReservation?.booking_code,
|
||||
clinicId: ttoReservation?.clinic_id,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import ConfirmationModal from '@/packages/shared/src/components/confirmation-modal';
|
||||
import { StoreOrderLineItem } from '@medusajs/types';
|
||||
import { formatDate } from 'date-fns';
|
||||
|
||||
@@ -19,6 +22,7 @@ import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import type { Order } from '~/lib/types/order';
|
||||
|
||||
import { cancelTtoBooking } from '../../_lib/server/actions';
|
||||
import { logAnalysisResultsNavigateAction } from './actions';
|
||||
|
||||
export type OrderItemType = 'analysisOrder' | 'ttoService';
|
||||
@@ -35,12 +39,14 @@ export default function OrderItemsTable({
|
||||
type?: OrderItemType;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
||||
|
||||
if (!items || items.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isAnalysisOrder = type === 'analysisOrder';
|
||||
const isTtoservice = type === 'ttoService';
|
||||
|
||||
const openDetailedView = async () => {
|
||||
if (isAnalysisOrder && order?.medusaOrderId && order?.id) {
|
||||
@@ -50,7 +56,7 @@ export default function OrderItemsTable({
|
||||
router.push(`${pathsConfig.app.myOrders}/${order.medusaOrderId}`);
|
||||
}
|
||||
};
|
||||
|
||||
console.log('order', order);
|
||||
return (
|
||||
<Table className="border-separate rounded-lg border">
|
||||
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
|
||||
@@ -103,10 +109,30 @@ export default function OrderItemsTable({
|
||||
<Button size="sm" onClick={openDetailedView}>
|
||||
<Trans i18nKey="analysis-results:view" />
|
||||
</Button>
|
||||
{isTtoservice && order.bookingCode && (
|
||||
<Button
|
||||
size="sm"
|
||||
className="bg-warning/90 hover:bg-warning mt-2 w-full"
|
||||
onClick={() => setIsConfirmOpen(true)}
|
||||
>
|
||||
<Trans i18nKey="analysis-results:cancel" />
|
||||
</Button>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
{order?.bookingCode && order?.clinicId && (
|
||||
<ConfirmationModal
|
||||
isOpen={isConfirmOpen}
|
||||
onClose={() => setIsConfirmOpen(false)}
|
||||
onConfirm={async () => {
|
||||
await cancelTtoBooking(order.bookingCode!, order.clinicId!);
|
||||
}}
|
||||
titleKey="orders:confirmBookingCancel.title"
|
||||
descriptionKey="orders:confirmBookingCancel.description"
|
||||
/>
|
||||
)}
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,12 @@
|
||||
import { updateLineItem } from '@lib/data/cart';
|
||||
import { StoreProductVariant } from '@medusajs/types';
|
||||
|
||||
import logRequestResult from '~/lib/services/audit.service';
|
||||
import { handleAddToCart } from '~/lib/services/medusaCart.service';
|
||||
import { createInitialReservation } from '~/lib/services/reservation.service';
|
||||
import { RequestStatus } from '~/lib/types/audit';
|
||||
import { ConnectedOnlineMethodName } from '~/lib/types/connected-online';
|
||||
import { ExternalApi } from '~/lib/types/external';
|
||||
|
||||
export async function createInitialReservationAction(
|
||||
selectedVariant: Pick<StoreProductVariant, 'id'>,
|
||||
@@ -41,3 +45,32 @@ export async function createInitialReservationAction(
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function cancelTtoBooking(bookingCode: string, clinicId: number) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.CONNECTED_ONLINE_URL}/${ConnectedOnlineMethodName.ConfirmedCancel}`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
param: `{'Value':'${bookingCode}|${clinicId}|et'}`,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
await logRequestResult(
|
||||
ExternalApi.ConnectedOnline,
|
||||
ConnectedOnlineMethodName.ConfirmedCancel,
|
||||
RequestStatus.Fail,
|
||||
JSON.stringify(error),
|
||||
);
|
||||
if (error instanceof Error) {
|
||||
console.error('Error cancelling booking: ' + error.message);
|
||||
}
|
||||
console.error('Error cancelling booking: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ export const isValidOpenAiEnv = async () => {
|
||||
await client.models.list();
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.log('AI not enabled');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,4 +10,6 @@ export type Order = {
|
||||
id?: number;
|
||||
status?: string;
|
||||
location?: string;
|
||||
bookingCode?: string | null;
|
||||
clinicId?: number;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { sdk } from '@lib/config';
|
||||
|
||||
import {
|
||||
renderAllResultsReceivedEmail,
|
||||
renderFirstResultsReceivedEmail,
|
||||
|
||||
@@ -80,7 +80,9 @@
|
||||
"orderStatus": "Order status",
|
||||
"paymentStatus": "Payment status",
|
||||
"discount": "Discount",
|
||||
"paymentConfirmationLoading": "Payment confirmation..."
|
||||
"paymentConfirmationLoading": "Payment confirmation...",
|
||||
"location": "Location",
|
||||
"serviceProvider": "Service provider"
|
||||
},
|
||||
"montonioCallback": {
|
||||
"title": "Montonio checkout",
|
||||
|
||||
@@ -31,5 +31,9 @@
|
||||
"REJECTED": "Rejected",
|
||||
"CANCELLED": "Cancelled"
|
||||
}
|
||||
},
|
||||
"confirmBookingCancel": {
|
||||
"title": "Are you sure?",
|
||||
"description": "Are you sure you wish to cancel this booking?"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,9 @@
|
||||
"orderStatus": "Tellimuse olek",
|
||||
"paymentStatus": "Makse olek",
|
||||
"discount": "Soodus",
|
||||
"paymentConfirmationLoading": "Makse kinnitamine..."
|
||||
"paymentConfirmationLoading": "Makse kinnitamine...",
|
||||
"location": "Asukoht",
|
||||
"serviceProvider": "Teenuse pakkuja"
|
||||
},
|
||||
"montonioCallback": {
|
||||
"title": "Montonio makseprotsess",
|
||||
|
||||
@@ -33,5 +33,9 @@
|
||||
"REJECTED": "Tagasi lükatud",
|
||||
"CANCELLED": "Tühistatud"
|
||||
}
|
||||
},
|
||||
"confirmBookingCancel": {
|
||||
"title": "Oled kindel?",
|
||||
"description": "Oled kindel, et soovitd broneeringu tühistada?"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,9 @@
|
||||
"orderStatus": "Статус заказа",
|
||||
"paymentStatus": "Статус оплаты",
|
||||
"discount": "Скидка",
|
||||
"paymentConfirmationLoading": "Ожидание подтверждения оплаты..."
|
||||
"paymentConfirmationLoading": "Ожидание подтверждения оплаты...",
|
||||
"location": "Location",
|
||||
"serviceProvider": "Service provider"
|
||||
},
|
||||
"montonioCallback": {
|
||||
"title": "Процесс оплаты Montonio",
|
||||
|
||||
@@ -31,5 +31,9 @@
|
||||
"REJECTED": "Отклонено",
|
||||
"CANCELLED": "Отменено"
|
||||
}
|
||||
},
|
||||
"confirmBookingCancel": {
|
||||
"title": "Are you sure?",
|
||||
"description": "Are you sure you wish to cancel this booking?"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user