fix tto order tables
This commit is contained in:
@@ -66,14 +66,16 @@ 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 orderIds = new Set(
|
||||
(medusaOrder?.items ?? [])
|
||||
.map((i) => i?.metadata?.connectedOnlineReservationId)
|
||||
.filter(Boolean)
|
||||
.map(String),
|
||||
);
|
||||
|
||||
const ttoReservation = ttoOrders.find((o) =>
|
||||
orderIds.has(String(o.id)),
|
||||
);
|
||||
|
||||
const medusaOrderItems = medusaOrder.items || [];
|
||||
const medusaOrderItemsAnalysisPackages = medusaOrderItems.filter(
|
||||
@@ -105,7 +107,6 @@ async function OrdersPage() {
|
||||
medusaOrderId={medusaOrder.id}
|
||||
analysisOrder={analysisOrder}
|
||||
ttoReservation={ttoReservation}
|
||||
medusaOrderStatus={medusaOrder.status}
|
||||
itemsAnalysisPackage={medusaOrderItemsAnalysisPackages}
|
||||
itemsTtoService={medusaOrderItemsTtoServices}
|
||||
itemsOther={medusaOrderItemsOther}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Label } from '@medusajs/ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { RadioGroup, RadioGroupItem } from '@kit/ui/radio-group';
|
||||
import { Card } from '@kit/ui/shadcn/card';
|
||||
@@ -8,7 +7,6 @@ import { Trans } from '@kit/ui/trans';
|
||||
import { useBooking } from './booking.provider';
|
||||
|
||||
const LocationSelector = () => {
|
||||
const { t } = useTranslation();
|
||||
const { selectedLocationId, setSelectedLocationId, locations } = useBooking();
|
||||
|
||||
const onLocationSelect = (locationId: number | string | null) => {
|
||||
@@ -16,6 +14,15 @@ const LocationSelector = () => {
|
||||
setSelectedLocationId(Number(locationId));
|
||||
};
|
||||
|
||||
const uniqueLocations = locations?.filter((item, index, self) => {
|
||||
return (
|
||||
index ===
|
||||
self.findIndex(
|
||||
(loc) => loc.sync_id === item.sync_id && loc.name === item.name,
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<Card className="mb-4 p-4">
|
||||
<h5 className="text-semibold mb-2">
|
||||
@@ -26,20 +33,23 @@ const LocationSelector = () => {
|
||||
className="mb-2 flex flex-col"
|
||||
onValueChange={(val) => onLocationSelect(val)}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
{/* <div className="flex items-center gap-2">
|
||||
<RadioGroupItem
|
||||
value={'all'}
|
||||
id={'all'}
|
||||
value="all"
|
||||
id="all"
|
||||
checked={selectedLocationId === null}
|
||||
/>
|
||||
<Label htmlFor={'all'}>{t('booking:showAllLocations')}</Label>
|
||||
</div>
|
||||
{locations?.map((location) => (
|
||||
<Label htmlFor="all">{t('booking:showAllLocations')}</Label>
|
||||
</div> */}
|
||||
{uniqueLocations?.map((location, index) => (
|
||||
<div key={location.sync_id} className="flex items-center gap-2">
|
||||
<RadioGroupItem
|
||||
value={location.sync_id.toString()}
|
||||
id={location.sync_id.toString()}
|
||||
checked={selectedLocationId === location.sync_id}
|
||||
checked={
|
||||
selectedLocationId === location.sync_id ||
|
||||
(index === 0 && selectedLocationId === null)
|
||||
}
|
||||
/>
|
||||
<Label htmlFor={location.sync_id.toString()}>
|
||||
{location.name}
|
||||
|
||||
@@ -18,19 +18,19 @@ const MobileCartItems = ({
|
||||
productColumnLabelKey: string;
|
||||
}) => {
|
||||
const {
|
||||
i18n: { language },
|
||||
i18n: { language, t },
|
||||
} = useTranslation();
|
||||
|
||||
return (
|
||||
<Table className="border-separate rounded-lg border p-2">
|
||||
<TableBody>
|
||||
<MobileTableRow
|
||||
titleKey={productColumnLabelKey}
|
||||
title={t(productColumnLabelKey)}
|
||||
value={item.product_title}
|
||||
/>
|
||||
<MobileTableRow titleKey="cart:table.time" value={item.quantity} />
|
||||
<MobileTableRow title={t('cart:table.time')} value={item.quantity} />
|
||||
<MobileTableRow
|
||||
titleKey="cart:table.price"
|
||||
title={t('cart:table.price')}
|
||||
value={formatCurrency({
|
||||
value: item.unit_price,
|
||||
currencyCode,
|
||||
@@ -38,7 +38,7 @@ const MobileCartItems = ({
|
||||
})}
|
||||
/>
|
||||
<MobileTableRow
|
||||
titleKey="cart:table.total"
|
||||
title={t('cart:table.total')}
|
||||
value={
|
||||
item.total &&
|
||||
formatCurrency({
|
||||
|
||||
@@ -25,27 +25,30 @@ const MobileCartServiceItems = ({
|
||||
setEditingItem: (item: EnrichedCartItem | null) => void;
|
||||
}) => {
|
||||
const {
|
||||
i18n: { language },
|
||||
i18n: { language, t },
|
||||
} = useTranslation();
|
||||
|
||||
return (
|
||||
<Table className="border-separate rounded-lg border p-2">
|
||||
<TableBody>
|
||||
<MobileTableRow
|
||||
titleKey={productColumnLabelKey}
|
||||
title={t(productColumnLabelKey)}
|
||||
value={item.product_title}
|
||||
/>
|
||||
<MobileTableRow
|
||||
titleKey="cart:table.time"
|
||||
title={t('cart:table.time')}
|
||||
value={formatDateAndTime(item.reservation.startTime.toString())}
|
||||
/>
|
||||
<MobileTableRow
|
||||
titleKey="cart:table.location"
|
||||
title={t('cart:table.location')}
|
||||
value={item.reservation.location?.address ?? '-'}
|
||||
/>
|
||||
<MobileTableRow titleKey="cart:table.quantity" value={item.quantity} />
|
||||
<MobileTableRow
|
||||
titleKey="cart:table.price"
|
||||
title={t('cart:table.quantity')}
|
||||
value={item.quantity}
|
||||
/>
|
||||
<MobileTableRow
|
||||
title={t('cart:table.price')}
|
||||
value={formatCurrency({
|
||||
value: item.unit_price,
|
||||
currencyCode,
|
||||
@@ -53,7 +56,7 @@ const MobileCartServiceItems = ({
|
||||
})}
|
||||
/>
|
||||
<MobileTableRow
|
||||
titleKey="cart:table.total"
|
||||
title={t('cart:table.total')}
|
||||
value={
|
||||
item.total &&
|
||||
formatCurrency({
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { TableCell, TableHead, TableRow } from '@kit/ui/shadcn/table';
|
||||
|
||||
const MobleTableRow = ({
|
||||
titleKey,
|
||||
title,
|
||||
value,
|
||||
}: {
|
||||
titleKey?: string;
|
||||
title?: string;
|
||||
value?: string | number;
|
||||
}) => (
|
||||
<TableRow>
|
||||
<TableHead className="h-2 font-bold">
|
||||
<Trans i18nKey={titleKey} />
|
||||
</TableHead>
|
||||
<TableHead className="h-2 font-bold">{title}</TableHead>
|
||||
|
||||
<TableCell className="p-0 text-right">
|
||||
<p className="txt-medium-plus text-ui-fg-base">{value}</p>
|
||||
|
||||
@@ -13,7 +13,6 @@ export default function OrderBlock({
|
||||
analysisOrder,
|
||||
ttoLocation,
|
||||
ttoReservation,
|
||||
medusaOrderStatus,
|
||||
itemsAnalysisPackage,
|
||||
itemsTtoService,
|
||||
itemsOther,
|
||||
@@ -22,7 +21,6 @@ export default function OrderBlock({
|
||||
analysisOrder?: AnalysisOrder;
|
||||
ttoLocation?: { name: string };
|
||||
ttoReservation?: TTOOrder;
|
||||
medusaOrderStatus: string;
|
||||
itemsAnalysisPackage: StoreOrderLineItem[];
|
||||
itemsTtoService: StoreOrderLineItem[];
|
||||
itemsOther: StoreOrderLineItem[];
|
||||
@@ -76,6 +74,7 @@ export default function OrderBlock({
|
||||
bookingCode: ttoReservation?.booking_code,
|
||||
clinicId: ttoReservation?.clinic_id,
|
||||
medusaLineItemId: ttoReservation?.medusa_cart_line_item_id,
|
||||
id: ttoReservation?.id,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { redirect, useRouter } from 'next/navigation';
|
||||
|
||||
import ConfirmationModal from '@/packages/shared/src/components/confirmation-modal';
|
||||
import { StoreOrderLineItem } from '@medusajs/types';
|
||||
import { formatDate } from 'date-fns';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { pathsConfig } from '@kit/shared/config';
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -41,6 +42,9 @@ export default function OrderItemsTable({
|
||||
type?: OrderItemType;
|
||||
isPackage?: boolean;
|
||||
}) {
|
||||
const {
|
||||
i18n: { t },
|
||||
} = useTranslation();
|
||||
const router = useRouter();
|
||||
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
||||
const isCancelOrderAllowed =
|
||||
@@ -61,7 +65,7 @@ export default function OrderItemsTable({
|
||||
await logAnalysisResultsNavigateAction(order.medusaOrderId);
|
||||
router.push(`${pathsConfig.app.analysisResults}/${order.id}`);
|
||||
} else {
|
||||
router.push(`${pathsConfig.app.myOrders}/${order.medusaOrderId}`);
|
||||
router.push(`${pathsConfig.app.myOrders}/${order.id}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -74,27 +78,31 @@ export default function OrderItemsTable({
|
||||
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||
)
|
||||
.map((orderItem) => (
|
||||
<div key={`${orderItem.id}-mobile`}>
|
||||
<React.Fragment key={`${orderItem.id}-mobile`}>
|
||||
<MobileTableRow
|
||||
titleKey={title}
|
||||
title={t(title)}
|
||||
value={orderItem.product_title || ''}
|
||||
/>
|
||||
<MobileTableRow
|
||||
titleKey="orders:table.createdAt"
|
||||
title={t('orders:table.createdAt')}
|
||||
value={formatDate(orderItem.created_at, 'dd.MM.yyyy HH:mm')}
|
||||
/>
|
||||
{order.location && (
|
||||
<MobileTableRow
|
||||
titleKey="orders:table.location"
|
||||
title={t('orders:table.location')}
|
||||
value={order.location}
|
||||
/>
|
||||
)}
|
||||
<MobileTableRow
|
||||
titleKey="orders:table.status"
|
||||
title={t('orders:table.status')}
|
||||
value={
|
||||
isPackage
|
||||
? `orders:status.analysisPackageOrder.${order?.status ?? 'CONFIRMED'}`
|
||||
: `orders:status.${type}.${order?.status ?? 'CONFIRMED'}`
|
||||
? t(
|
||||
`orders:status.analysisPackageOrder.${order?.status ?? 'CONFIRMED'}`,
|
||||
)
|
||||
: t(
|
||||
`orders:status.${type}.${order?.status ?? 'CONFIRMED'}`,
|
||||
)
|
||||
}
|
||||
/>
|
||||
<TableRow>
|
||||
@@ -114,7 +122,7 @@ export default function OrderItemsTable({
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</div>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
@@ -172,23 +180,24 @@ export default function OrderItemsTable({
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="px-6 text-right">
|
||||
<Button size="sm" onClick={openDetailedView}>
|
||||
<Trans i18nKey="analysis-results:view" />
|
||||
</Button>
|
||||
{isCancelOrderAllowed && (
|
||||
<Button
|
||||
size="sm"
|
||||
className="bg-warning/90 hover:bg-warning mt-2 w-full"
|
||||
onClick={() => setIsConfirmOpen(true)}
|
||||
>
|
||||
<Trans i18nKey="analysis-results:cancel" />
|
||||
<TableCell className="px-6 text-right">
|
||||
<Button size="sm" onClick={openDetailedView}>
|
||||
<Trans i18nKey="analysis-results:view" />
|
||||
</Button>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
{isCancelOrderAllowed && (
|
||||
<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>
|
||||
</Table>
|
||||
{isCancelOrderAllowed && (
|
||||
<ConfirmationModal
|
||||
isOpen={isConfirmOpen}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use server';
|
||||
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
import { updateLineItem } from '@lib/data/cart';
|
||||
import { StoreProductVariant } from '@medusajs/types';
|
||||
|
||||
@@ -89,3 +90,22 @@ export async function cancelTtoBooking(
|
||||
console.error('Error cancelling booking: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function isPaymentRequiredForService(serviceId: number) {
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
|
||||
try {
|
||||
const { data } = await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('connected_online_services')
|
||||
.select('requires_payment')
|
||||
.eq('id', serviceId)
|
||||
.is('requires_payment', true)
|
||||
.maybeSingle();
|
||||
|
||||
return !!data;
|
||||
} catch (error) {
|
||||
console.error('Error checking payment requirement: ', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ import { z } from 'zod';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
|
||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||
import {
|
||||
bookAppointment,
|
||||
getConfirmedService,
|
||||
} from '~/lib/services/connected-online.service';
|
||||
import { bookAppointment } from '~/lib/services/connected-online.service';
|
||||
import { sendOrderToMedipost } from '~/lib/services/medipost/medipostPrivateMessage.service';
|
||||
import { handleNavigateToPayment } from '~/lib/services/medusaCart.service';
|
||||
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
|
||||
|
||||
@@ -2,6 +2,7 @@ import { cache } from 'react';
|
||||
|
||||
import { getProductCategories, listProducts } from '@lib/data';
|
||||
|
||||
import { isPaymentRequiredForService } from './actions';
|
||||
import { loadCountryCodes } from './load-analyses';
|
||||
|
||||
async function categoryLoader({ handle }: { handle: string }) {
|
||||
@@ -26,6 +27,24 @@ async function categoryLoader({ handle }: { handle: string }) {
|
||||
queryParams: { limit: 100, category_id: response.product_categories[0].id },
|
||||
});
|
||||
|
||||
const productsWithNoRequiredPayment = categoryProducts.filter(
|
||||
async (product) => {
|
||||
if (product.metadata?.serviceIds) {
|
||||
const serviceIds: number[] = JSON.parse(
|
||||
product.metadata.serviceIds as string,
|
||||
);
|
||||
for (const serviceId of serviceIds) {
|
||||
const requiresPayment = await isPaymentRequiredForService(serviceId);
|
||||
if (requiresPayment) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
category: {
|
||||
color:
|
||||
@@ -36,7 +55,7 @@ async function categoryLoader({ handle }: { handle: string }) {
|
||||
handle: category?.handle || '',
|
||||
name: category?.name || '',
|
||||
countryCode,
|
||||
products: categoryProducts,
|
||||
products: productsWithNoRequiredPayment,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -194,6 +194,7 @@ export async function getTtoLocation(syncId?: number | null) {
|
||||
.from('connected_online_locations')
|
||||
.select('name')
|
||||
.eq('sync_id', syncId)
|
||||
.limit(1)
|
||||
.single();
|
||||
|
||||
if (error) {
|
||||
|
||||
@@ -5,7 +5,9 @@ import { redirect } from 'next/navigation';
|
||||
|
||||
import { sdk } from '@lib/config';
|
||||
import medusaError from '@lib/util/medusa-error';
|
||||
import type { HttpTypes, StoreCart } from '@medusajs/types';
|
||||
import type { HttpTypes, StoreCart, StoreCartPromotion } from '@medusajs/types';
|
||||
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
|
||||
import {
|
||||
getAuthHeaders,
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
"FULL_ANALYSIS_RESPONSE": "Kõik tulemused käes",
|
||||
"COMPLETED": "Kinnitatud",
|
||||
"REJECTED": "Tagastatud",
|
||||
"CANCELLED": "Tühistatud"
|
||||
"CANCELLED": "Tühistatud",
|
||||
"CONFIRMED": "Kinnitatud"
|
||||
},
|
||||
"analysisPackageOrder": {
|
||||
"QUEUED": "Esitatud",
|
||||
|
||||
Reference in New Issue
Block a user