Merge pull request #1010 from automatisch/remove-stripe-remainings

feat(UsageAlert): use new plan upgrade page
This commit is contained in:
Ömer Faruk Aydın
2023-03-22 22:47:19 +03:00
committed by GitHub
4 changed files with 18 additions and 41 deletions

View File

@@ -1,4 +1,5 @@
import * as React from 'react';
import { Link } from 'react-router-dom';
import Alert from '@mui/material/Alert';
import Snackbar from '@mui/material/Snackbar';
import Typography from '@mui/material/Typography';
@@ -34,8 +35,9 @@ export default function UsageAlert() {
</Typography>
<Button
component={Link}
size="small"
href={usageAlert.url}
to={usageAlert.url}
sx={{ minWidth: 100 }}
>
{formatMessage('usageAlert.viewPlans')}

View File

@@ -1,10 +0,0 @@
import { gql } from '@apollo/client';
export const GET_PAYMENT_PORTAL_URL = gql`
query GetPaymentPortalUrl {
getPaymentPortalUrl {
url
}
}
`;

View File

@@ -1,16 +0,0 @@
import { useQuery } from '@apollo/client';
import { GET_PAYMENT_PORTAL_URL } from 'graphql/queries/get-payment-portal-url.ee';
type UsePaymentPortalUrlReturn = {
url: string;
loading: boolean;
};
export default function usePaymentPortalUrl(): UsePaymentPortalUrlReturn {
const { data, loading } = useQuery(GET_PAYMENT_PORTAL_URL);
return {
url: data?.getPaymentPortalUrl?.url,
loading
};
}

View File

@@ -1,33 +1,34 @@
import * as URLS from 'config/urls';
import useFormatMessage from './useFormatMessage';
import useUsageData from './useUsageData.ee';
import usePaymentPortalUrl from './usePaymentPortalUrl.ee';
type UseUsageAlertReturn = {
showAlert: boolean;
hasExceededLimit?: boolean;
alertMessage?: string;
url?: string;
consumptionPercentage?: number;
showAlert: true;
hasExceededLimit: boolean;
alertMessage: string;
url: string;
consumptionPercentage: number;
};
export default function useUsageAlert(): UseUsageAlertReturn {
const { url, loading: paymentPortalUrlLoading } = usePaymentPortalUrl();
type UseUsageNoAlertReturn = {
showAlert: false;
};
export default function useUsageAlert(): UseUsageAlertReturn | UseUsageNoAlertReturn {
const {
allowedTaskCount,
consumedTaskCount,
nextResetAt,
loading: usageDataLoading
loading
} = useUsageData();
const formatMessage = useFormatMessage();
if (paymentPortalUrlLoading || usageDataLoading) {
if (loading) {
return { showAlert: false };
}
const hasLoaded = !paymentPortalUrlLoading || usageDataLoading;
const withinUsageThreshold = consumedTaskCount > allowedTaskCount * 0.7;
const consumptionPercentage = consumedTaskCount / allowedTaskCount * 100;
const showAlert = hasLoaded && withinUsageThreshold;
const hasExceededLimit = consumedTaskCount >= allowedTaskCount;
const alertMessage = formatMessage('usageAlert.informationText', {
@@ -37,10 +38,10 @@ export default function useUsageAlert(): UseUsageAlertReturn {
});
return {
showAlert,
showAlert: withinUsageThreshold,
hasExceededLimit,
alertMessage,
consumptionPercentage,
url,
url: URLS.SETTINGS_PLAN_UPGRADE,
};
}