import * as RadioGroup from "@radix-ui/react-radio-group"; import { useState, useEffect } from "react"; import type { EventTypeAppSettingsComponent } from "@calcom/app-store/types"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { RefundPolicy } from "@calcom/lib/payment/types"; import classNames from "@calcom/ui/classNames"; import { Alert } from "@calcom/ui/components/alert"; import { Select } from "@calcom/ui/components/form"; import { TextField } from "@calcom/ui/components/form"; import { RadioField } from "@calcom/ui/components/radio"; import { convertToSmallestCurrencyUnit, convertFromSmallestToPresentableCurrencyUnit, } from "../../_utils/payments/currencyConversions"; import { paymentOptions } from "../lib/constants"; import { currencyOptions } from "../lib/currencyOptions"; type Option = { value: string; label: string }; const EventTypeAppSettingsInterface: EventTypeAppSettingsComponent = ({ getAppData, setAppData, disabled, eventType, }) => { const price = getAppData("price"); const currency = getAppData("currency") || currencyOptions[0].value; const [selectedCurrency, setSelectedCurrency] = useState( currencyOptions.find((c) => c.value === currency) || { label: currencyOptions[0].label, value: currencyOptions[0].value, } ); const paymentOption = getAppData("paymentOption"); const paymentOptionSelectValue = paymentOptions.find((option) => paymentOption === option.value); const requirePayment = getAppData("enabled"); const getSelectedOption = () => options.find((opt) => opt.value === (getAppData("refundCountCalendarDays") === true ? 1 : 0)); const { t } = useLocale(); const recurringEventDefined = eventType.recurringEvent?.count !== undefined; const seatsEnabled = !!eventType.seatsPerTimeSlot; const getCurrencySymbol = (locale: string, currency: string) => (0) .toLocaleString(locale, { style: "currency", currency, minimumFractionDigits: 0, maximumFractionDigits: 0, }) .replace(/\d/g, "") .trim(); useEffect(() => { if (requirePayment) { if (!getAppData("currency")) { setAppData("currency", currencyOptions[0].value); } if (!getAppData("paymentOption")) { setAppData("paymentOption", paymentOptions[0].value); } } if (!getAppData("refundPolicy")) { setAppData("refundPolicy", RefundPolicy.NEVER); } }, [requirePayment, getAppData, setAppData]); const options = [ { value: 0, label: t("business_days") }, { value: 1, label: t("calendar_days") }, ]; return ( <> {recurringEventDefined && ( )} {!recurringEventDefined && requirePayment && ( <>
{selectedCurrency.value ? getCurrencySymbol("en", selectedCurrency.value) : ""} } addOnSuffix={currency.toUpperCase()} addOnClassname="h-[38px]" step="0.01" min="0.5" type="number" required placeholder="Price" disabled={disabled} onChange={(e) => { setAppData("price", convertToSmallestCurrencyUnit(Number(e.target.value), currency)); }} value={price > 0 ? convertFromSmallestToPresentableCurrencyUnit(price, currency) : undefined} />
setAppData("refundCountCalendarDays", option?.value === 1)} value={getSelectedOption()} defaultValue={getSelectedOption()} />  {t("before")}
)} )} ); }; export default EventTypeAppSettingsInterface;