diff --git a/packages/client/src/pages/PortalSettings/categories/payments/PriceCalculation.js b/packages/client/src/pages/PortalSettings/categories/payments/PriceCalculation.js index 29159ef1ff..48fed32caf 100644 --- a/packages/client/src/pages/PortalSettings/categories/payments/PriceCalculation.js +++ b/packages/client/src/pages/PortalSettings/categories/payments/PriceCalculation.js @@ -65,11 +65,13 @@ const PriceCalculation = ({ initializeInfo, priceManagerPerMonth, currencySymbol, + isAlreadyPaid, + isFreeAfterPaidPeriod, + setStartPaymentLink, }) => { - const isAlreadyPaid = !isFreeTariff || (isFreeTariff && isNotPaidPeriod); - useEffect(() => { - initializeInfo(isAlreadyPaid); + initializeInfo(); + !isAlreadyPaid && setStartPaymentLink(); return () => { timeout && clearTimeout(timeout); @@ -170,11 +172,13 @@ const PriceCalculation = ({ {...color} className="payment_main-title" > - {!isGracePeriod && !isNotPaidPeriod - ? t("PriceCalculation") - : t("YourPrice")} + {isGracePeriod || isNotPaidPeriod || isFreeAfterPaidPeriod + ? t("YourPrice") + : t("PriceCalculation")} - {!isGracePeriod && !isNotPaidPeriod && ( + {isGracePeriod || isNotPaidPeriod || isFreeAfterPaidPeriod ? ( + <> + ) : ( ); @@ -202,6 +207,7 @@ export default inject(({ auth, payments }) => { setManagersCount, maxAvailableManagersCount, initializeInfo, + setStartPaymentLink, } = payments; const { theme } = auth.settingsStore; const { @@ -216,6 +222,7 @@ export default inject(({ auth, payments }) => { const { user } = userStore; return { + setStartPaymentLink, isFreeTariff, setManagersCount, tariffsInfo, diff --git a/packages/client/src/pages/PortalSettings/categories/payments/index.js b/packages/client/src/pages/PortalSettings/categories/payments/index.js index ece3a5e307..9372178b48 100644 --- a/packages/client/src/pages/PortalSettings/categories/payments/index.js +++ b/packages/client/src/pages/PortalSettings/categories/payments/index.js @@ -26,7 +26,7 @@ const StyledBody = styled.div` .payment-info_grace-period { margin-bottom: 12px; } - + .payment-info { display: grid; grid-template-columns: repeat(2, minmax(100px, 320px)); @@ -51,6 +51,7 @@ const StyledBody = styled.div` `; let paymentTerm, + isValidDelayDueDate, fromDate, byDate, delayDaysCount, @@ -76,11 +77,14 @@ const PaymentsPage = ({ replaceFeaturesValues, portalPaymentQuotasFeatures, currentTariffPlanTitle, + tariffPlanTitle, }) => { const { t, ready } = useTranslation(["Payments", "Settings"]); const [isInitialLoading, setIsInitialLoading] = useState(true); + const isAlreadyPaid = payerEmail.length !== 0 || !isFreeTariff; + useEffect(() => { setDocumentTitle(t("Settings:Payments")); }, [ready]); @@ -103,6 +107,9 @@ const PaymentsPage = ({ paymentTerm = moment( isGracePeriod || isNotPaidPeriod ? delayDueDate : dueDate ).format("LL"); + const paymentTermYear = moment(delayDueDate).year(); + + isValidDelayDueDate = paymentTermYear !== 9999; isGracePeriod && gracePeriodDays(); }; @@ -130,7 +137,7 @@ const PaymentsPage = ({ } try { - if (!isFreeTariff) payerInfo = await getUserByEmail(payerEmail); + if (isAlreadyPaid) payerInfo = await getUserByEmail(payerEmail); } catch (e) { console.error(e); } @@ -160,86 +167,100 @@ const PaymentsPage = ({ ); }; - const textComponent = (elem, className) => { + const currentPlanTitle = () => { + if (isPaidPeriod || isGracePeriod) { + return ( + + + {{ planName: currentTariffPlanTitle }} + + + ); + } + return ( - - {elem} + + + {{ planName: currentTariffPlanTitle }} + ); }; - const currentPlanTitle = () => { - if (isFreeTariff) { - return textComponent( - - {{ planName: currentTariffPlanTitle }} - - ); - } - - if (isPaidPeriod || isGracePeriod) { - return textComponent( - - {{ planName: currentTariffPlanTitle }} - - ); - } - - return; - }; - const expiredTitleSubscriptionWarning = () => { - return textComponent( - - {{ date: paymentTerm }} {{ planName: currentTariffPlanTitle }} - + + {{ date: paymentTerm }} {{ planName: tariffPlanTitle }} + + ); }; const planSuggestion = () => { if (isFreeTariff) { - return textComponent( - - {{ planName: currentTariffPlanTitle }} - , - "payment-info_suggestion" + return ( + + + {{ planName: tariffPlanTitle }} + + ); } if (isPaidPeriod) { - return textComponent( - - {{ planName: currentTariffPlanTitle }} - , - "payment-info_suggestion" + return ( + + + {{ planName: tariffPlanTitle }} + + ); } if (isNotPaidPeriod) { - return textComponent( - - {{ planName: currentTariffPlanTitle }} - , - "payment-info_suggestion" + return ( + + + {{ planName: tariffPlanTitle }} + + ); } if (isGracePeriod) { - return textComponent( - - {{ date: paymentTerm }} {{ planName: currentTariffPlanTitle }} - , - "payment-info_grace-period" + + {{ date: paymentTerm }} {{ planName: currentTariffPlanTitle }} + + ); } @@ -249,13 +270,17 @@ const PaymentsPage = ({ const convertedPrice = `${currencySymbol}${startValue}`; const isPayer = user.email === payerEmail; + const isFreeAfterPaidPeriod = isFreeTariff && payerEmail.length !== 0; + return isInitialLoading || !ready ? ( ) : ( - {isNotPaidPeriod ? expiredTitleSubscriptionWarning() : currentPlanTitle()} + {isNotPaidPeriod && isValidDelayDueDate + ? expiredTitleSubscriptionWarning() + : currentPlanTitle()} - {(!isFreeTariff || (isFreeTariff && isNotPaidPeriod)) && ( + {isAlreadyPaid && ( )} - {isPaidPeriod && ( + {isPaidPeriod && !isFreeAfterPaidPeriod && (
- - {!isGracePeriod && !isNotPaidPeriod && } + + + {isGracePeriod || isNotPaidPeriod || isFreeAfterPaidPeriod ? ( + <> + ) : ( + + )}
@@ -342,6 +377,7 @@ export default inject(({ auth, payments }) => { planCost, replaceFeaturesValues, portalPaymentQuotasFeatures, + tariffPlanTitle, } = paymentQuotasStore; const { organizationName, theme } = auth.settingsStore; @@ -356,7 +392,7 @@ export default inject(({ auth, payments }) => { return { isFreeTariff, - + tariffPlanTitle, language, organizationName, tariffsInfo, diff --git a/packages/client/src/pages/PortalSettings/categories/payments/sub-components/ButtonContainer.js b/packages/client/src/pages/PortalSettings/categories/payments/sub-components/ButtonContainer.js index 6d8c492651..166dd9a47e 100644 --- a/packages/client/src/pages/PortalSettings/categories/payments/sub-components/ButtonContainer.js +++ b/packages/client/src/pages/PortalSettings/categories/payments/sub-components/ButtonContainer.js @@ -1,7 +1,7 @@ import React from "react"; import { inject, observer } from "mobx-react"; import Button from "@docspace/components/button"; -import styled, { css } from "styled-components"; +import styled from "styled-components"; import RequestButtonContainer from "./RequestButtonContainer"; import UpdatePlanButtonContainer from "./UpdatePlanButtonContainer"; @@ -20,6 +20,7 @@ const ButtonContainer = ({ isNotPaidPeriod, isGracePeriod, accountLink, + isFreeAfterPaidPeriod, }) => { const goToStripeAccount = () => { if (accountLink) window.open(accountLink, "_blank"); @@ -27,7 +28,7 @@ const ButtonContainer = ({ return ( - {isNotPaidPeriod || isGracePeriod ? ( + {isNotPaidPeriod || isGracePeriod || isFreeAfterPaidPeriod ? (