From e1f47ef40ebcc99edbc468d3b403032d0d23053d Mon Sep 17 00:00:00 2001 From: Lauris Skraucis Date: Fri, 29 Sep 2023 22:19:04 +0200 Subject: [PATCH] refactor: Paypal App UI & UX (#11528) * refactor(ui): price input margin * refactor(ui): price input border * refactor(ui): inputs spacing * fix: Use USD as the default currency * fix: dynamic currency symbols * undo * apply same styles for stripe app * type fixes --------- Co-authored-by: Alan --- .../components/EventTypeAppCardInterface.tsx | 41 ++++++++++----- .../app-store/paypal/lib/currencyOptions.ts | 36 ++++++++++++- .../components/EventTypeAppCardInterface.tsx | 51 +++++++++++-------- 3 files changed, 92 insertions(+), 36 deletions(-) diff --git a/packages/app-store/paypal/components/EventTypeAppCardInterface.tsx b/packages/app-store/paypal/components/EventTypeAppCardInterface.tsx index c8951f3a5e..536d159652 100644 --- a/packages/app-store/paypal/components/EventTypeAppCardInterface.tsx +++ b/packages/app-store/paypal/components/EventTypeAppCardInterface.tsx @@ -1,9 +1,13 @@ import { useRouter } from "next/router"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import { useAppContextWithSchema } from "@calcom/app-store/EventTypeAppContext"; import AppCard from "@calcom/app-store/_components/AppCard"; -import { currencyOptions } from "@calcom/app-store/paypal/lib/currencyOptions"; +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"; @@ -18,12 +22,11 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ const { asPath } = useRouter(); const { getAppData, setAppData } = useAppContextWithSchema(); const price = getAppData("price"); + const currency = getAppData("currency"); - const [selectedCurrency, setSelectedCurrency] = useState( - currencyOptions.find((c) => c.value === currency) || { - label: currencyOptions[0].label, - value: 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"); @@ -36,6 +39,17 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ 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); + } + } + }, []); + return ( { setAppData("price", Number(e.target.value) * 100); @@ -73,7 +87,7 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ />
-
-
- {selectedCurrency.value ? getCurrencySymbol("en", selectedCurrency.value) : ""} - } - 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} - /> +
+ defaultValue={ paymentOptionSelectValue @@ -128,6 +134,7 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ isDisabled={seatsEnabled || disabled} />
+ {seatsEnabled && paymentOption === "HOLD" && ( )}