Merge branch 'develop' into MED-98

This commit is contained in:
Karli
2025-09-30 21:48:02 +03:00
60 changed files with 3841 additions and 395 deletions

View File

@@ -32,7 +32,16 @@ const BookingContainer = ({
<BookingProvider category={{ products }} service={cartItem?.product}>
<div className="xs:flex-row flex max-h-full flex-col gap-6">
<div className="flex flex-col">
<ServiceSelector products={products} />
<ServiceSelector
products={products.filter((product) => {
if (product.metadata?.serviceIds) {
return Array.isArray(
JSON.parse(product.metadata.serviceIds as string),
);
}
return false;
})}
/>
<BookingCalendar />
<LocationSelector />
</div>

View File

@@ -0,0 +1,113 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Trans } from '@kit/ui/makerkit/trans';
import { cn } from '@kit/ui/shadcn';
import { Button } from '@kit/ui/shadcn/button';
const BookingPagination = ({
totalPages,
setCurrentPage,
currentPage,
}: {
totalPages: number;
setCurrentPage: (page: number) => void;
currentPage: number;
}) => {
const { t } = useTranslation();
const generatePageNumbers = () => {
const pages = [];
const maxVisiblePages = 5;
if (totalPages <= maxVisiblePages) {
for (let i = 1; i <= totalPages; i++) {
pages.push(i);
}
} else {
if (currentPage <= 3) {
for (let i = 1; i <= 4; i++) {
pages.push(i);
}
pages.push('...');
pages.push(totalPages);
} else if (currentPage >= totalPages - 2) {
pages.push(1);
pages.push('...');
for (let i = totalPages - 3; i <= totalPages; i++) {
pages.push(i);
}
} else {
pages.push(1);
pages.push('...');
for (let i = currentPage - 1; i <= currentPage + 1; i++) {
pages.push(i);
}
pages.push('...');
pages.push(totalPages);
}
}
return pages;
};
if (totalPages === 0) {
return (
<div className="wrap text-muted-foreground flex size-full content-center-safe justify-center-safe">
<p>{t('booking:noResults')}</p>
</div>
);
}
return (
totalPages > 1 && (
<div className="flex items-center justify-between">
<div className="text-muted-foreground text-sm">
{t('common:pageOfPages', {
page: currentPage,
total: totalPages,
})}
</div>
<div className="flex items-center gap-1">
<Button
variant="outline"
size="sm"
onClick={() => setCurrentPage(currentPage - 1)}
disabled={currentPage === 1}
>
<Trans i18nKey="common:previous" defaultValue="Previous" />
</Button>
{generatePageNumbers().map((page, index) => (
<Button
key={index}
variant={page === currentPage ? 'default' : 'outline'}
size="sm"
onClick={() => typeof page === 'number' && setCurrentPage(page)}
disabled={page === '...'}
className={cn(
'min-w-[2rem]',
page === '...' && 'cursor-default hover:bg-transparent',
)}
>
{page}
</Button>
))}
<Button
variant="outline"
size="sm"
onClick={() => setCurrentPage(currentPage + 1)}
disabled={currentPage === totalPages}
>
<Trans i18nKey="common:next" defaultValue="Next" />
</Button>
</div>
</div>
)
);
};
export default BookingPagination;

View File

@@ -45,7 +45,6 @@ export const BookingProvider: React.FC<{
const updateTimeSlots = async (serviceIds: number[]) => {
setIsLoadingTimeSlots(true);
try {
console.log('serviceIds', serviceIds, selectedLocationId);
const response = await getAvailableTimeSlotsForDisplay(
serviceIds,
selectedLocationId,

View File

@@ -11,6 +11,7 @@ import { pathsConfig } from '@kit/shared/config';
import { formatDateAndTime } from '@kit/shared/utils';
import { Button } from '@kit/ui/shadcn/button';
import { Card } from '@kit/ui/shadcn/card';
import { Skeleton } from '@kit/ui/shadcn/skeleton';
import { toast } from '@kit/ui/sonner';
import { Trans } from '@kit/ui/trans';
import { cn } from '@kit/ui/utils';
@@ -19,6 +20,7 @@ import { updateReservationTime } from '~/lib/services/reservation.service';
import { createInitialReservationAction } from '../../_lib/server/actions';
import { EnrichedCartItem } from '../cart/types';
import BookingPagination from './booking-pagination';
import { ServiceProvider, TimeSlot } from './booking.context';
import { useBooking } from './booking.provider';
@@ -68,57 +70,16 @@ const TimeSlots = ({
}) ?? [],
'StartTime',
'asc',
),
).filter(({ StartTime }) => isSameDay(StartTime, selectedDate)),
[booking.timeSlots, selectedDate],
);
const totalPages = Math.ceil(filteredBookings.length / PAGE_SIZE);
const paginatedBookings = useMemo(() => {
const startIndex = (currentPage - 1) * PAGE_SIZE;
const endIndex = startIndex + PAGE_SIZE;
return filteredBookings.slice(startIndex, endIndex);
}, [filteredBookings, currentPage, PAGE_SIZE]);
const handlePageChange = (page: number) => {
setCurrentPage(page);
};
const generatePageNumbers = () => {
const pages = [];
const maxVisiblePages = 5;
if (totalPages <= maxVisiblePages) {
for (let i = 1; i <= totalPages; i++) {
pages.push(i);
}
} else {
if (currentPage <= 3) {
for (let i = 1; i <= 4; i++) {
pages.push(i);
}
pages.push('...');
pages.push(totalPages);
} else if (currentPage >= totalPages - 2) {
pages.push(1);
pages.push('...');
for (let i = totalPages - 3; i <= totalPages; i++) {
pages.push(i);
}
} else {
pages.push(1);
pages.push('...');
for (let i = currentPage - 1; i <= currentPage + 1; i++) {
pages.push(i);
}
pages.push('...');
pages.push(totalPages);
}
}
return pages;
};
if (!booking?.timeSlots?.length) {
return null;
}
@@ -143,12 +104,17 @@ const TimeSlots = ({
timeSlot.StartTime,
booking.selectedLocationId ? booking.selectedLocationId : null,
comments,
).then(() => {
if (onComplete) {
onComplete();
}
router.push(pathsConfig.app.cart);
});
)
.then(() => {
if (onComplete) {
onComplete();
}
router.push(pathsConfig.app.cart);
})
.catch((error) => {
console.error('Booking error: ', error);
throw error;
});
toast.promise(() => bookTimePromise, {
success: <Trans i18nKey={'booking:bookTimeSuccess'} />,
@@ -203,10 +169,13 @@ const TimeSlots = ({
};
return (
<div className="flex w-full flex-col gap-4">
<Skeleton
isLoading={booking.isLoadingTimeSlots}
className="flex w-full flex-col gap-4"
>
<div className="flex h-full w-full flex-col gap-2 overflow-auto">
{paginatedBookings.map((timeSlot, index) => {
const isEHIF = timeSlot.HKServiceID > 0;
const isHaigeKassa = timeSlot.HKServiceID > 0;
const serviceProviderTitle = getServiceProviderTitle(
currentLocale,
timeSlot.serviceProvider,
@@ -214,6 +183,7 @@ const TimeSlots = ({
const price =
booking.selectedService?.variants?.[0]?.calculated_price
?.calculated_amount ?? cartItem?.unit_price;
return (
<Card
className="xs:flex xs:justify-between grid w-full justify-center-safe gap-3 p-4"
@@ -224,7 +194,7 @@ const TimeSlots = ({
<div className="flex">
<h5
className={cn(
(serviceProviderTitle || isEHIF) &&
(serviceProviderTitle || isHaigeKassa) &&
"after:mx-2 after:content-['·']",
)}
>
@@ -232,12 +202,14 @@ const TimeSlots = ({
</h5>
{serviceProviderTitle && (
<span
className={cn(isEHIF && "after:mx-2 after:content-['·']")}
className={cn(
isHaigeKassa && "after:mx-2 after:content-['·']",
)}
>
{serviceProviderTitle}
</span>
)}
{isEHIF && <span>{t('booking:ehifBooking')}</span>}
{isHaigeKassa && <span>{t('booking:ehifBooking')}</span>}
</div>
<div className="flex text-xs">{timeSlot.location?.address}</div>
</div>
@@ -256,63 +228,14 @@ const TimeSlots = ({
</Card>
);
})}
{!paginatedBookings.length && (
<div className="wrap text-muted-foreground flex size-full content-center-safe justify-center-safe">
<p>{t('booking:noResults')}</p>
</div>
)}
</div>
{totalPages > 1 && (
<div className="flex items-center justify-between">
<div className="text-muted-foreground text-sm">
{t('common:pageOfPages', {
page: currentPage,
total: totalPages,
})}
</div>
<div className="flex items-center gap-1">
<Button
variant="outline"
size="sm"
onClick={() => handlePageChange(currentPage - 1)}
disabled={currentPage === 1}
>
<Trans i18nKey="common:previous" defaultValue="Previous" />
</Button>
{generatePageNumbers().map((page, index) => (
<Button
key={index}
variant={page === currentPage ? 'default' : 'outline'}
size="sm"
onClick={() =>
typeof page === 'number' && handlePageChange(page)
}
disabled={page === '...'}
className={cn(
'min-w-[2rem]',
page === '...' && 'cursor-default hover:bg-transparent',
)}
>
{page}
</Button>
))}
<Button
variant="outline"
size="sm"
onClick={() => handlePageChange(currentPage + 1)}
disabled={currentPage === totalPages}
>
<Trans i18nKey="common:next" defaultValue="Next" />
</Button>
</div>
</div>
)}
</div>
<BookingPagination
totalPages={Math.ceil(filteredBookings.length / PAGE_SIZE)}
setCurrentPage={setCurrentPage}
currentPage={currentPage}
/>
</Skeleton>
);
};

View File

@@ -1,5 +1,6 @@
import { StoreCartLineItem } from "@medusajs/types";
import { Reservation } from "~/lib/types/reservation";
import { StoreCartLineItem } from '@medusajs/types';
import { Reservation } from '~/lib/types/reservation';
export interface MontonioOrderToken {
uuid: string;

View File

@@ -1,5 +1,7 @@
import Link from 'next/link';
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
import { formatCurrency } from '@/packages/shared/src/utils';
import { ChevronRight, HeartPulse } from 'lucide-react';
import { Button } from '@kit/ui/button';
@@ -11,25 +13,27 @@ import {
CardHeader,
CardTitle,
} from '@kit/ui/card';
import { Trans } from '@kit/ui/trans';
import { formatCurrency } from '@/packages/shared/src/utils';
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
import { cn } from '@kit/ui/lib/utils';
import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
import { Trans } from '@kit/ui/trans';
import { getAccountBalanceSummary } from '../_lib/server/balance-actions';
import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
export default async function DashboardCards() {
const { language } = await createI18nServerInstance();
const { account } = await loadCurrentUserAccount();
const balanceSummary = account ? await getAccountBalanceSummary(account.id) : null;
const balanceSummary = account
? await getAccountBalanceSummary(account.id)
: null;
return (
<div
className={cn(
'grid grid-cols-1 gap-4',
'md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
)}>
)}
>
<Card
variant="gradient-success"
className="xs:w-1/2 flex w-full flex-col justify-between sm:w-auto"
@@ -79,7 +83,7 @@ export default async function DashboardCards() {
<Trans
i18nKey="dashboard:heroCard.benefits.validUntil"
values={{ date: '31.12.2025' }}
/>
/>
</CardDescription>
</CardContent>
</Card>

View File

@@ -14,7 +14,10 @@ import {
User,
} from 'lucide-react';
import type { AccountWithParams, BmiThresholds } from '@kit/accounts/types/accounts';
import type {
AccountWithParams,
BmiThresholds,
} from '@kit/accounts/types/accounts';
import { pathsConfig } from '@kit/shared/config';
import { Button } from '@kit/ui/button';
import {

View File

@@ -9,8 +9,8 @@ import { useTranslation } from 'react-i18next';
import { Trans } from '@kit/ui/trans';
const PaymentProviderIds = {
COMPANY_BENEFITS: "pp_company-benefits_company-benefits",
MONTONIO: "pp_montonio_montonio",
COMPANY_BENEFITS: 'pp_company-benefits_company-benefits',
MONTONIO: 'pp_montonio_montonio',
};
export default function CartTotals({
@@ -30,10 +30,12 @@ export default function CartTotals({
payment_collections,
} = medusaOrder;
const montonioPayment = payment_collections?.[0]?.payments
?.find(({ provider_id }) => provider_id === PaymentProviderIds.MONTONIO);
const companyBenefitsPayment = payment_collections?.[0]?.payments
?.find(({ provider_id }) => provider_id === PaymentProviderIds.COMPANY_BENEFITS);
const montonioPayment = payment_collections?.[0]?.payments?.find(
({ provider_id }) => provider_id === PaymentProviderIds.MONTONIO,
);
const companyBenefitsPayment = payment_collections?.[0]?.payments?.find(
({ provider_id }) => provider_id === PaymentProviderIds.COMPANY_BENEFITS,
);
return (
<div>
@@ -96,7 +98,6 @@ export default function CartTotals({
</span>
</div>
)}
</div>
<div className="my-4 h-px w-full border-b border-gray-200" />
@@ -126,7 +127,10 @@ export default function CartTotals({
<span className="flex items-center gap-x-1">
<Trans i18nKey="cart:order.benefitsTotal" />
</span>
<span data-testid="cart-subtotal" data-value={companyBenefitsPayment.amount || 0}>
<span
data-testid="cart-subtotal"
data-value={companyBenefitsPayment.amount || 0}
>
-{' '}
{formatCurrency({
value: companyBenefitsPayment.amount ?? 0,
@@ -142,7 +146,10 @@ export default function CartTotals({
<span className="flex items-center gap-x-1">
<Trans i18nKey="cart:order.montonioTotal" />
</span>
<span data-testid="cart-subtotal" data-value={montonioPayment.amount || 0}>
<span
data-testid="cart-subtotal"
data-value={montonioPayment.amount || 0}
>
-{' '}
{formatCurrency({
value: montonioPayment.amount ?? 0,