feat(MED-98): prettier fix
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
database.types.ts
|
||||
playwright-report
|
||||
*.hbs
|
||||
*.hbs
|
||||
.history
|
||||
node_modules
|
||||
|
||||
@@ -3,26 +3,22 @@
|
||||
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||
import { StoreCart, StoreCartLineItem } from '@medusajs/types';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { Card, CardContent, CardHeader } from '@kit/ui/card';
|
||||
import { Checkbox } from '@kit/ui/checkbox';
|
||||
import { FormControl, FormField, FormItem, FormLabel } from '@kit/ui/form';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { cn } from '~/lib/utils';
|
||||
|
||||
import AnalysisLocation from './analysis-location';
|
||||
import CartItems from './cart-items';
|
||||
import CartServiceItems from './cart-service-items';
|
||||
import DiscountCode from './discount-code';
|
||||
import { EnrichedCartItem, GetBalanceSummarySelection } from './types';
|
||||
import {
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
} from '@kit/ui/form';
|
||||
import { Checkbox } from '@kit/ui/checkbox';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
import { cn } from '~/lib/utils';
|
||||
|
||||
const IS_DISCOUNT_SHOWN = true as boolean;
|
||||
|
||||
@@ -54,7 +50,8 @@ export default function CartFormContent({
|
||||
const useCompanyBenefits = watch('useCompanyBenefits');
|
||||
const balanceSummary = getBalanceSummarySelection({ useCompanyBenefits });
|
||||
|
||||
const { benefitsAmount, benefitsAmountTotal, montonioAmount } = balanceSummary;
|
||||
const { benefitsAmount, benefitsAmountTotal, montonioAmount } =
|
||||
balanceSummary;
|
||||
|
||||
const hasBenefitsApplied = benefitsAmountTotal > 0 && !!useCompanyBenefits;
|
||||
|
||||
@@ -91,9 +88,14 @@ export default function CartFormContent({
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className={cn("flex gap-x-4 px-4 pt-2 sm:justify-end sm:px-6 sm:pt-4", {
|
||||
"py-2 sm:py-4": !hasBenefitsApplied,
|
||||
})}>
|
||||
<div
|
||||
className={cn(
|
||||
'flex gap-x-4 px-4 pt-2 sm:justify-end sm:px-6 sm:pt-4',
|
||||
{
|
||||
'py-2 sm:py-4': !hasBenefitsApplied,
|
||||
},
|
||||
)}
|
||||
>
|
||||
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||
<p className="text-muted-foreground ml-0 text-sm font-bold">
|
||||
<Trans i18nKey="cart:order.promotionsTotal" />
|
||||
@@ -148,7 +150,7 @@ export default function CartFormContent({
|
||||
<FormField
|
||||
name="useCompanyBenefits"
|
||||
render={({ field }) => (
|
||||
<FormItem className='mt-8'>
|
||||
<FormItem className="mt-8">
|
||||
<div className="flex flex-row items-center gap-2 pb-1">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
@@ -199,11 +201,7 @@ export default function CartFormContent({
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button
|
||||
className="h-10"
|
||||
type="submit"
|
||||
disabled={isInitiatingSession}
|
||||
>
|
||||
<Button className="h-10" type="submit" disabled={isInitiatingSession}>
|
||||
{isInitiatingSession && (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import { z } from 'zod';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import type { StoreCart } from '@medusajs/types';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Form } from '@kit/ui/form';
|
||||
|
||||
@@ -13,7 +13,9 @@ const CartFormSchema = z.object({
|
||||
useCompanyBenefits: z.boolean(),
|
||||
});
|
||||
|
||||
export type CartFormOnSubmit = (data: z.infer<typeof CartFormSchema>) => Promise<void>;
|
||||
export type CartFormOnSubmit = (
|
||||
data: z.infer<typeof CartFormSchema>,
|
||||
) => Promise<void>;
|
||||
|
||||
export default function CartForm({
|
||||
children,
|
||||
@@ -44,4 +46,4 @@ export default function CartForm({
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
|
||||
import { convertToLocale } from '@lib/util/money';
|
||||
import { StoreCart, StorePromotion } from '@medusajs/types';
|
||||
import { Badge, Text } from '@medusajs/ui';
|
||||
import Trash from '@modules/common/icons/trash';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -15,7 +15,10 @@ import { Input } from '@kit/ui/input';
|
||||
import { toast } from '@kit/ui/sonner';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { addPromotionCodeAction, removePromotionCodeAction } from './discount-code-actions';
|
||||
import {
|
||||
addPromotionCodeAction,
|
||||
removePromotionCodeAction,
|
||||
} from './discount-code-actions';
|
||||
|
||||
export default function DiscountCode({
|
||||
cart,
|
||||
@@ -128,17 +131,17 @@ export default function DiscountCode({
|
||||
(
|
||||
{promotion.application_method?.value !== undefined &&
|
||||
promotion.application_method.currency_code !==
|
||||
undefined && (
|
||||
undefined && (
|
||||
<>
|
||||
{promotion.application_method.type === 'percentage'
|
||||
? `${promotion.application_method.value}%`
|
||||
: convertToLocale({
|
||||
amount: Number(
|
||||
promotion.application_method.value,
|
||||
),
|
||||
currency_code:
|
||||
promotion.application_method.currency_code,
|
||||
})}
|
||||
amount: Number(
|
||||
promotion.application_method.value,
|
||||
),
|
||||
currency_code:
|
||||
promotion.application_method.currency_code,
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
)
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
'use client';
|
||||
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import { StoreCart, StoreCartLineItem } from '@medusajs/types';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
import { AccountBalanceSummary } from '@kit/accounts/services/account-balance.service';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { initiatePayment } from '../../_lib/server/cart-actions';
|
||||
import { EnrichedCartItem } from './types';
|
||||
import CartForm, { CartFormOnSubmit } from './cart-form';
|
||||
import CartFormContent from './cart-form-content';
|
||||
import { EnrichedCartItem } from './types';
|
||||
|
||||
export default function Cart({
|
||||
accountId,
|
||||
@@ -35,43 +37,46 @@ export default function Cart({
|
||||
const [unavailableLineItemIds, setUnavailableLineItemIds] =
|
||||
useState<string[]>();
|
||||
|
||||
const getBalanceSummarySelection = useCallback(({ useCompanyBenefits }: {
|
||||
useCompanyBenefits: boolean;
|
||||
}): {
|
||||
benefitsAmount: number;
|
||||
benefitsAmountTotal: number;
|
||||
montonioAmount: number;
|
||||
} => {
|
||||
if (!cart) {
|
||||
return {
|
||||
benefitsAmount: 0,
|
||||
benefitsAmountTotal: 0,
|
||||
montonioAmount: 0,
|
||||
};
|
||||
}
|
||||
const getBalanceSummarySelection = useCallback(
|
||||
({
|
||||
useCompanyBenefits,
|
||||
}: {
|
||||
useCompanyBenefits: boolean;
|
||||
}): {
|
||||
benefitsAmount: number;
|
||||
benefitsAmountTotal: number;
|
||||
montonioAmount: number;
|
||||
} => {
|
||||
if (!cart) {
|
||||
return {
|
||||
benefitsAmount: 0,
|
||||
benefitsAmountTotal: 0,
|
||||
montonioAmount: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const benefitsAmountTotal = balanceSummary?.totalBalance ?? 0;
|
||||
const cartTotal = cart.total;
|
||||
if (!useCompanyBenefits) {
|
||||
const benefitsAmountTotal = balanceSummary?.totalBalance ?? 0;
|
||||
const cartTotal = cart.total;
|
||||
if (!useCompanyBenefits) {
|
||||
return {
|
||||
benefitsAmount: 0,
|
||||
benefitsAmountTotal,
|
||||
montonioAmount: cartTotal,
|
||||
};
|
||||
}
|
||||
|
||||
const benefitsAmount =
|
||||
benefitsAmountTotal > cartTotal ? cartTotal : benefitsAmountTotal;
|
||||
const montonioAmount =
|
||||
benefitsAmount > 0 ? cartTotal - benefitsAmount : cartTotal;
|
||||
return {
|
||||
benefitsAmount: 0,
|
||||
benefitsAmount,
|
||||
benefitsAmountTotal,
|
||||
montonioAmount: cartTotal,
|
||||
montonioAmount,
|
||||
};
|
||||
}
|
||||
|
||||
const benefitsAmount = benefitsAmountTotal > cartTotal
|
||||
? cartTotal
|
||||
: benefitsAmountTotal;
|
||||
const montonioAmount = benefitsAmount > 0
|
||||
? cartTotal - benefitsAmount
|
||||
: cartTotal;
|
||||
return {
|
||||
benefitsAmount,
|
||||
benefitsAmountTotal,
|
||||
montonioAmount,
|
||||
};
|
||||
}, [balanceSummary, cart]);
|
||||
},
|
||||
[balanceSummary, cart],
|
||||
);
|
||||
|
||||
const items = cart?.items ?? [];
|
||||
const hasCartItems = cart && Array.isArray(items) && items.length > 0;
|
||||
@@ -100,13 +105,16 @@ export default function Cart({
|
||||
setIsInitiatingSession(true);
|
||||
|
||||
try {
|
||||
const { benefitsAmount } = getBalanceSummarySelection({ useCompanyBenefits });
|
||||
const { url, isFullyPaidByBenefits, orderId, unavailableLineItemIds } = await initiatePayment({
|
||||
accountId,
|
||||
benefitsAmount,
|
||||
cart: cart!,
|
||||
language,
|
||||
const { benefitsAmount } = getBalanceSummarySelection({
|
||||
useCompanyBenefits,
|
||||
});
|
||||
const { url, isFullyPaidByBenefits, orderId, unavailableLineItemIds } =
|
||||
await initiatePayment({
|
||||
accountId,
|
||||
benefitsAmount,
|
||||
cart: cart!,
|
||||
language,
|
||||
});
|
||||
if (unavailableLineItemIds) {
|
||||
setUnavailableLineItemIds(unavailableLineItemIds);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,9 @@ export enum CartItemType {
|
||||
|
||||
export type EnrichedCartItem = StoreCartLineItem & { reservation: Reservation };
|
||||
|
||||
export type GetBalanceSummarySelection = ({ useCompanyBenefits }: {
|
||||
export type GetBalanceSummarySelection = ({
|
||||
useCompanyBenefits,
|
||||
}: {
|
||||
useCompanyBenefits: boolean;
|
||||
}) => {
|
||||
benefitsAmount: number;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
'use server';
|
||||
|
||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||
import { createNotificationsApi } from '@/packages/features/notifications/src/server/api';
|
||||
import { getSupabaseServerAdminClient } from '@/packages/supabase/src/clients/server-admin-client';
|
||||
import { listProductTypes } from '@lib/data';
|
||||
import { initiateMultiPaymentSession, placeOrder } from '@lib/data/cart';
|
||||
import type { StoreCart, StoreOrder } from '@medusajs/types';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { initiateMultiPaymentSession, placeOrder } from "@lib/data/cart";
|
||||
import { listProductTypes } from "@lib/data";
|
||||
import { AccountWithParams } from "@/packages/features/accounts/src/types/accounts";
|
||||
import { getSupabaseServerAdminClient } from "@/packages/supabase/src/clients/server-admin-client";
|
||||
import { createNotificationsApi } from "@/packages/features/notifications/src/server/api";
|
||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||
import { bookAppointment } from '~/lib/services/connected-online.service';
|
||||
import { sendOrderToMedipost } from '~/lib/services/medipost/medipostPrivateMessage.service';
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
import { useRevalidatePersonalAccountDataQuery } from '@kit/accounts/hooks/use-personal-account-data';
|
||||
import type { AccountWithParams } from '@kit/accounts/types/accounts';
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -12,6 +11,7 @@ import { Form } from '@kit/ui/form';
|
||||
import { LanguageSelector } from '@kit/ui/language-selector';
|
||||
import { toast } from '@kit/ui/sonner';
|
||||
import { Switch } from '@kit/ui/switch';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import {
|
||||
AccountPreferences,
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
import { useRevalidatePersonalAccountDataQuery } from '@kit/accounts/hooks/use-personal-account-data';
|
||||
import type { AccountWithParams } from '@kit/accounts/types/accounts';
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -24,6 +23,7 @@ import {
|
||||
SelectValue,
|
||||
} from '@kit/ui/select';
|
||||
import { toast } from '@kit/ui/sonner';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import {
|
||||
AccountSettings,
|
||||
|
||||
@@ -31,8 +31,10 @@ const env = () =>
|
||||
.min(1),
|
||||
})
|
||||
.parse({
|
||||
medusaBackendPublicUrl: (process.env.DEV_MONTONIO_CALLBACK_URL || process.env.MEDUSA_BACKEND_PUBLIC_URL)!,
|
||||
siteUrl: (process.env.DEV_MONTONIO_CALLBACK_URL || process.env.NEXT_PUBLIC_SITE_URL)!,
|
||||
medusaBackendPublicUrl: (process.env.DEV_MONTONIO_CALLBACK_URL ||
|
||||
process.env.MEDUSA_BACKEND_PUBLIC_URL)!,
|
||||
siteUrl: (process.env.DEV_MONTONIO_CALLBACK_URL ||
|
||||
process.env.NEXT_PUBLIC_SITE_URL)!,
|
||||
});
|
||||
|
||||
export async function handleAddToCart({
|
||||
|
||||
Reference in New Issue
Block a user