Web: PortalSettings: Payments: Added disable button for free tariff.

This commit is contained in:
Tatiana Lopaeva 2023-04-06 17:25:15 +03:00
parent d0a2097f9d
commit dc8abb2392
2 changed files with 21 additions and 12 deletions

View File

@ -30,8 +30,9 @@ const UpdatePlanButtonContainer = ({
isLessCountThanAcceptable, isLessCountThanAcceptable,
currentTariffPlanTitle, currentTariffPlanTitle,
t, t,
canPayTariff,
}) => { }) => {
const updateMethod = async () => { const onUpdateTariff = async () => {
try { try {
timerId = setTimeout(() => { timerId = setTimeout(() => {
setIsLoading(true); setIsLoading(true);
@ -105,12 +106,7 @@ const UpdatePlanButtonContainer = ({
}, 2000); }, 2000);
}; };
const onUpdateTariff = () => { const goToStripePortal = () => {
if (isAlreadyPaid) {
updateMethod();
return;
}
paymentLink paymentLink
? window.open(paymentLink, "_blank") ? window.open(paymentLink, "_blank")
: toastr.error(t("ErrorNotification")); : toastr.error(t("ErrorNotification"));
@ -126,18 +122,20 @@ const UpdatePlanButtonContainer = ({
}; };
}, []); }, []);
const switchPlanButton = ( const payTariffButton = (
<Button <Button
label={t("UpgradeNow")} label={t("UpgradeNow")}
size={"medium"} size={"medium"}
primary primary
isDisabled={isLessCountThanAcceptable || isLoading || isDisabled} isDisabled={
onClick={onUpdateTariff} isLessCountThanAcceptable || !canPayTariff || isLoading || isDisabled
}
onClick={goToStripePortal}
isLoading={isLoading} isLoading={isLoading}
/> />
); );
const updatingPlanButton = () => { const updatingCurrentTariffButton = () => {
const isDowngradePlan = managersCount < maxCountManagersByQuota; const isDowngradePlan = managersCount < maxCountManagersByQuota;
const isTheSameCount = managersCount === maxCountManagersByQuota; const isTheSameCount = managersCount === maxCountManagersByQuota;
@ -163,7 +161,7 @@ const UpdatePlanButtonContainer = ({
return ( return (
<StyledBody> <StyledBody>
{isAlreadyPaid ? updatingPlanButton() : switchPlanButton} {isAlreadyPaid ? updatingCurrentTariffButton() : payTariffButton}
</StyledBody> </StyledBody>
); );
}; };
@ -187,9 +185,11 @@ export default inject(({ auth, payments }) => {
isLessCountThanAcceptable, isLessCountThanAcceptable,
accountLink, accountLink,
isAlreadyPaid, isAlreadyPaid,
canPayTariff,
} = payments; } = payments;
return { return {
canPayTariff,
isAlreadyPaid, isAlreadyPaid,
setIsLoading, setIsLoading,
paymentLink, paymentLink,

View File

@ -305,6 +305,15 @@ class PaymentStore {
return this.isPayer; return this.isPayer;
} }
get canPayTariff() {
const { currentQuotaStore } = authStore;
const { addedManagersCount } = currentQuotaStore;
if (this.managersCount >= addedManagersCount) return true;
return false;
}
setRangeStepByQuota = () => { setRangeStepByQuota = () => {
const { paymentQuotasStore } = authStore; const { paymentQuotasStore } = authStore;
const { const {