import { useState, useEffect } from "react"; import { currencyOptions } from "@calcom/app-store/alby/lib/currencyOptions"; import type { EventTypeAppSettingsComponent } from "@calcom/app-store/types"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Alert } from "@calcom/ui/components/alert"; import { Select } from "@calcom/ui/components/form"; import { TextField } from "@calcom/ui/components/form"; import { SatSymbol } from "@calcom/ui/components/icon"; import { PaypalPaymentOptions as paymentOptions } from "../zod"; type Option = { value: string; label: string }; const EventTypeAppSettingsInterface: EventTypeAppSettingsComponent = ({ eventType, getAppData, setAppData, }) => { const { t } = useLocale(); const price = getAppData("price"); const currency = getAppData("currency"); const [selectedCurrency, setSelectedCurrency] = useState( currencyOptions.find((c) => c.value === currency) || currencyOptions[0] ); 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] = useState(getAppData("enabled")); const recurringEventDefined = eventType.recurringEvent?.count !== undefined; // make sure a currency is selected useEffect(() => { if (!currency && requirePayment) { setAppData("currency", selectedCurrency.value); } }, [currency, selectedCurrency, setAppData, requirePayment]); return ( <> {recurringEventDefined ? ( ) : ( requirePayment && ( <>
} addOnSuffix={selectedCurrency.unit || selectedCurrency.value} type="number" required className="block w-full rounded-sm border-gray-300 pl-2 pr-12 text-sm" placeholder="Price" onChange={(e) => { setAppData("price", Number(e.target.value)); if (currency) { setAppData("currency", currency); } }} value={price && price > 0 ? price : undefined} />