Merge pull request #1010 from automatisch/remove-stripe-remainings
feat(UsageAlert): use new plan upgrade page
This commit is contained in:
@@ -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')}
|
||||
|
@@ -1,10 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const GET_PAYMENT_PORTAL_URL = gql`
|
||||
query GetPaymentPortalUrl {
|
||||
getPaymentPortalUrl {
|
||||
url
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
@@ -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
|
||||
};
|
||||
}
|
@@ -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,
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user