DocSpace-buildtools/packages/common/components/Article/sub-components/article-payment-alert.js

110 lines
3.0 KiB
JavaScript
Raw Normal View History

2022-09-14 06:55:22 +00:00
import React, { useEffect } from "react";
import { inject, observer } from "mobx-react";
import { withRouter } from "react-router";
import { useTranslation, Trans } from "react-i18next";
import Text from "@docspace/components/text";
import ArrowRightIcon from "@docspace/client/public/images/arrow.right.react.svg";
import { StyledArticlePaymentAlert } from "../styled-article";
import styled from "styled-components";
import AppServerConfig from "@docspace/common/constants/AppServerConfig";
import { combineUrl } from "@docspace/common/utils";
import history from "@docspace/common/history";
import Loaders from "../../Loaders";
const StyledArrowRightIcon = styled(ArrowRightIcon)`
margin: auto 0;
path {
fill: ${(props) => props.color};
}
`;
const PROXY_BASE_URL = combineUrl(AppServerConfig.proxyURL, "/portal-settings");
const ArticlePaymentAlert = ({
pricePerManager,
isFreeTariff,
theme,
currencySymbol,
2022-09-14 06:55:22 +00:00
setPortalPaymentQuotas,
2022-09-14 14:17:40 +00:00
currentTariffPlanTitle,
2022-11-23 09:45:22 +00:00
toggleArticleOpen,
}) => {
const { t, ready } = useTranslation("Payments");
2022-09-14 06:55:22 +00:00
useEffect(() => {
isFreeTariff && setPortalPaymentQuotas();
}, []);
const onClick = () => {
const paymentPageUrl = combineUrl(
PROXY_BASE_URL,
"/payments/portal-payments"
);
history.push(paymentPageUrl);
2022-11-23 09:45:22 +00:00
toggleArticleOpen();
};
2022-09-14 06:55:22 +00:00
const isShowLoader = !ready;
return isShowLoader ? (
<Loaders.Rectangle width="210px" height="88px" />
) : (
<StyledArticlePaymentAlert
onClick={onClick}
isFreeTariff={isFreeTariff}
theme={theme}
id="document_catalog-payment-alert"
>
<div>
<Text className="article-payment_border">
2022-09-14 14:17:40 +00:00
{isFreeTariff ? (
<Trans t={t} i18nKey="FreeStartupPlan" ns="Payments">
{{ planName: currentTariffPlanTitle }}
</Trans>
) : (
t("LatePayment")
)}
</Text>
<Text fontWeight={600}>
{isFreeTariff ? t("ActivateBusinessPlan") : t("GracePeriodActivated")}
</Text>
<Text noSelect fontSize={"12px"}>
{isFreeTariff ? (
2022-09-14 06:55:22 +00:00
<>
{pricePerManager ? (
2022-10-05 08:55:15 +00:00
<Trans t={t} i18nKey="PerUserMonth" ns="Payments">
From {{ currencySymbol }}
{{ price: pricePerManager }} per admin/month
2022-09-14 06:55:22 +00:00
</Trans>
) : (
<></>
)}
</>
) : (
t("PayBeforeTheEndGracePeriod")
)}
</Text>
</div>
<StyledArrowRightIcon />
</StyledArticlePaymentAlert>
);
};
export default withRouter(
inject(({ auth }) => {
2022-09-14 14:17:40 +00:00
const { paymentQuotasStore, currentQuotaStore, settingsStore } = auth;
const { currentTariffPlanTitle } = currentQuotaStore;
const { theme } = auth;
2022-09-14 06:55:22 +00:00
const { setPortalPaymentQuotas, planCost } = paymentQuotasStore;
2022-08-29 14:46:43 +00:00
return {
2022-09-14 06:55:22 +00:00
setPortalPaymentQuotas,
pricePerManager: planCost.value,
2022-08-29 14:46:43 +00:00
theme,
2022-09-14 06:55:22 +00:00
currencySymbol: planCost.currencySymbol,
2022-09-14 14:17:40 +00:00
currentTariffPlanTitle,
2022-08-29 14:46:43 +00:00
};
})(observer(ArticlePaymentAlert))
);