import { useState, useEffect } from "react"; 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 "../lib/currencyConversions"; import { paymentOptions, currencyOptions } from "./constants"; 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 requirePayment = getAppData("enabled"); 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); } } }, [requirePayment, getAppData, setAppData]); const disableDecimalPlace = (value: number) => { const nValue = Math.floor(value); const sValue = nValue.toString(); const ret = parseInt(sValue); return ret; }; return ( <> {recurringEventDefined && ( )} {!recurringEventDefined && requirePayment && ( <>
{selectedCurrency.value ? getCurrencySymbol("en", selectedCurrency.value) : ""} } addOnSuffix={currency.toUpperCase()} addOnClassname="h-[38px]" step="1" min="1" type="number" required placeholder="Price" disabled={disabled} onChange={(e) => { setAppData("price", convertToSmallestCurrencyUnit(Number(e.target.value), currency)); }} value={ price > 0 ? disableDecimalPlace(convertFromSmallestToPresentableCurrencyUnit(price, currency)) : undefined } />