import { usePathname, useSearchParams } from "next/navigation"; import { useState, useMemo } from "react"; import { useAppContextWithSchema } from "@calcom/app-store/EventTypeAppContext"; import AppCard from "@calcom/app-store/_components/AppCard"; import { currencyOptions, currencySymbols, isAcceptedCurrencyCode, } from "@calcom/app-store/paypal/lib/currencyOptions"; import type { EventTypeAppCardComponent } from "@calcom/app-store/types"; import { WEBAPP_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Select } from "@calcom/ui/components/form"; import { TextField } from "@calcom/ui/components/form"; import { Alert } from "@calcom/ui/components/alert"; import type { appDataSchema } from "../zod"; import { paymentOptions } from "../zod"; type Option = { value: string; label: string }; const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ app, eventType }) { const searchParams = useSearchParams(); /** TODO "pathname" no longer contains square-bracket expressions. Rewrite the code relying on them if required. **/ const pathname = usePathname(); const asPath = useMemo( () => `${pathname}${searchParams ? `?${searchParams.toString()}` : ""}`, [pathname, searchParams] ); const { t } = useLocale(); const { getAppData, setAppData } = useAppContextWithSchema(); const price = getAppData("price"); const currency = getAppData("currency"); const paymentOption = getAppData("paymentOption"); const enable = getAppData("enabled"); const [selectedCurrency, setSelectedCurrency] = useState(currencyOptions.find((c) => c.value === currency)); const [currencySymbol, setCurrencySymbol] = useState( isAcceptedCurrencyCode(currency) ? currencySymbols[currency] : "" ); const [requirePayment, setRequirePayment] = useState(enable); const paymentOptionSelectValue = paymentOptions?.find((option) => paymentOption === option.value) || { label: paymentOptions[0].label, value: paymentOptions[0].value, }; const recurringEventDefined = eventType.recurringEvent?.count !== undefined; return ( { setRequirePayment(enabled); }} description={<>Add a mock payment to your events}> <> {recurringEventDefined ? ( ) : ( requirePayment && ( <>
{ setAppData("price", Number(e.target.value) * 100); if (selectedCurrency) { setAppData("currency", selectedCurrency.value); } }} value={price > 0 ? price / 100 : undefined} />