import { useState, useEffect } from "react"; import { currencyOptions, currencySymbols, isAcceptedCurrencyCode, } from "@calcom/app-store/paypal/lib/currencyOptions"; import type { EventTypeAppSettingsComponent } from "@calcom/app-store/types"; 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 { convertToSmallestCurrencyUnit, convertFromSmallestToPresentableCurrencyUnit, } from "../../_utils/payments/currencyConversions"; import { PaypalPaymentOptions as paymentOptions } from "../zod"; type Option = { value: string; label: string }; const EventTypeAppSettingsInterface: EventTypeAppSettingsComponent = ({ getAppData, setAppData, eventType, }) => { const price = getAppData("price"); const currency = getAppData("currency") || currencyOptions[0].value; const [selectedCurrency, setSelectedCurrency] = useState(currencyOptions.find((c) => c.value === currency)); const [currencySymbol, setCurrencySymbol] = useState( isAcceptedCurrencyCode(currency) ? currencySymbols[currency] : "" ); const paymentOption = getAppData("paymentOption"); const paymentOptionSelectValue = paymentOptions?.find((option) => paymentOption === option.value) || { label: paymentOptions[0].label, value: paymentOptions[0].value, }; const seatsEnabled = !!eventType.seatsPerTimeSlot; const [requirePayment, setRequirePayment] = useState(getAppData("enabled")); const { t } = useLocale(); const recurringEventDefined = eventType.recurringEvent?.count !== undefined; useEffect(() => { if (requirePayment) { if (!getAppData("currency")) { setAppData("currency", currencyOptions[0].value); } if (!getAppData("paymentOption")) { setAppData("paymentOption", paymentOptions[0].value); } } }, []); if (recurringEventDefined) { return ; } if (!requirePayment) { return null; } return ( <>
{ setAppData("price", convertToSmallestCurrencyUnit(Number(e.target.value), currency)); if (selectedCurrency) { setAppData("currency", selectedCurrency.value); } }} value={price > 0 ? convertFromSmallestToPresentableCurrencyUnit(price, currency) : undefined} />