chore: remove UsageAlert
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
import appConfig from '../../config/app';
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
// TODO: remove as getBillingAndUsageData query has been introduced
|
||||
const getUsageData = async (
|
||||
_parent: unknown,
|
||||
_params: unknown,
|
||||
context: Context
|
||||
) => {
|
||||
if (!appConfig.isCloud) return;
|
||||
|
||||
const usageData = await context.currentUser
|
||||
.$relatedQuery('currentUsageData')
|
||||
.throwIfNotFound();
|
||||
|
||||
const subscription = await usageData
|
||||
.$relatedQuery('subscription')
|
||||
.throwIfNotFound();
|
||||
|
||||
const plan = subscription.plan;
|
||||
|
||||
const computedUsageData = {
|
||||
name: plan.name,
|
||||
allowedTaskCount: plan.quota,
|
||||
consumedTaskCount: usageData.consumedTaskCount,
|
||||
remainingTaskCount: plan.quota - usageData.consumedTaskCount,
|
||||
nextResetAt: usageData.nextResetAt,
|
||||
};
|
||||
|
||||
return computedUsageData;
|
||||
};
|
||||
|
||||
export default getUsageData;
|
@@ -11,7 +11,6 @@ import getExecutionSteps from './queries/get-execution-steps';
|
||||
import getDynamicData from './queries/get-dynamic-data';
|
||||
import getDynamicFields from './queries/get-dynamic-fields';
|
||||
import getCurrentUser from './queries/get-current-user';
|
||||
import getUsageData from './queries/get-usage-data.ee';
|
||||
import getPaymentPlans from './queries/get-payment-plans.ee';
|
||||
import getPaddleInfo from './queries/get-paddle-info.ee';
|
||||
import getBillingAndUsage from './queries/get-billing-and-usage.ee';
|
||||
@@ -35,7 +34,6 @@ const queryResolvers = {
|
||||
getDynamicData,
|
||||
getDynamicFields,
|
||||
getCurrentUser,
|
||||
getUsageData,
|
||||
getPaymentPlans,
|
||||
getPaddleInfo,
|
||||
getBillingAndUsage,
|
||||
|
@@ -34,7 +34,6 @@ type Query {
|
||||
parameters: JSONObject
|
||||
): [SubstepArgument]
|
||||
getCurrentUser: User
|
||||
getUsageData: GetUsageData
|
||||
getPaymentPlans: [PaymentPlan]
|
||||
getPaddleInfo: GetPaddleInfo
|
||||
getBillingAndUsage: GetBillingAndUsage
|
||||
@@ -529,14 +528,6 @@ type Usage {
|
||||
task: Int
|
||||
}
|
||||
|
||||
type GetUsageData {
|
||||
name: String
|
||||
allowedTaskCount: Int
|
||||
consumedTaskCount: Int
|
||||
remainingTaskCount: Int
|
||||
nextResetAt: String
|
||||
}
|
||||
|
||||
type GetPaddleInfo {
|
||||
sandbox: Boolean
|
||||
vendorId: Int
|
||||
|
@@ -1,54 +0,0 @@
|
||||
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';
|
||||
import Stack from '@mui/material/Stack';
|
||||
import Button from '@mui/material/Button';
|
||||
import LinearProgress from '@mui/material/LinearProgress';
|
||||
|
||||
import useFormatMessage from 'hooks/useFormatMessage';
|
||||
import useUsageAlert from 'hooks/useUsageAlert.ee';
|
||||
|
||||
export default function UsageAlert() {
|
||||
const formatMessage = useFormatMessage();
|
||||
const usageAlert = useUsageAlert();
|
||||
|
||||
if (!usageAlert.showAlert) return (<React.Fragment />);
|
||||
|
||||
return (
|
||||
<Snackbar
|
||||
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||
open
|
||||
>
|
||||
<Alert
|
||||
icon={false}
|
||||
sx={{ fontWeight: 500, minWidth: 410 }}
|
||||
severity={usageAlert.hasExceededLimit ? 'error' : 'warning'}
|
||||
>
|
||||
<Stack direction="row" gap={4} mb={1}>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
sx={{ display: 'flex', alignItems: 'center' }}
|
||||
>
|
||||
{usageAlert.alertMessage}
|
||||
</Typography>
|
||||
|
||||
<Button
|
||||
component={Link}
|
||||
size="small"
|
||||
to={usageAlert.url}
|
||||
sx={{ minWidth: 100 }}
|
||||
>
|
||||
{formatMessage('usageAlert.viewPlans')}
|
||||
</Button>
|
||||
</Stack>
|
||||
|
||||
<LinearProgress
|
||||
variant="determinate"
|
||||
value={usageAlert.consumptionPercentage}
|
||||
/>
|
||||
</Alert>
|
||||
</Snackbar>
|
||||
);
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const GET_USAGE_DATA = gql`
|
||||
query GetUsageData {
|
||||
getUsageData {
|
||||
name
|
||||
allowedTaskCount
|
||||
consumedTaskCount
|
||||
remainingTaskCount
|
||||
nextResetAt
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
@@ -1,47 +0,0 @@
|
||||
import * as URLS from 'config/urls';
|
||||
import useFormatMessage from './useFormatMessage';
|
||||
import useUsageData from './useUsageData.ee';
|
||||
|
||||
type UseUsageAlertReturn = {
|
||||
showAlert: true;
|
||||
hasExceededLimit: boolean;
|
||||
alertMessage: string;
|
||||
url: string;
|
||||
consumptionPercentage: number;
|
||||
};
|
||||
|
||||
type UseUsageNoAlertReturn = {
|
||||
showAlert: false;
|
||||
};
|
||||
|
||||
export default function useUsageAlert(): UseUsageAlertReturn | UseUsageNoAlertReturn {
|
||||
const {
|
||||
allowedTaskCount,
|
||||
consumedTaskCount,
|
||||
nextResetAt,
|
||||
loading
|
||||
} = useUsageData();
|
||||
const formatMessage = useFormatMessage();
|
||||
|
||||
if (loading) {
|
||||
return { showAlert: false };
|
||||
}
|
||||
|
||||
const withinUsageThreshold = consumedTaskCount > allowedTaskCount * 0.7;
|
||||
const consumptionPercentage = consumedTaskCount / allowedTaskCount * 100;
|
||||
const hasExceededLimit = consumedTaskCount >= allowedTaskCount;
|
||||
|
||||
const alertMessage = formatMessage('usageAlert.informationText', {
|
||||
allowedTaskCount,
|
||||
consumedTaskCount,
|
||||
relativeResetDate: nextResetAt?.toRelative(),
|
||||
});
|
||||
|
||||
return {
|
||||
showAlert: withinUsageThreshold,
|
||||
hasExceededLimit,
|
||||
alertMessage,
|
||||
consumptionPercentage,
|
||||
url: URLS.SETTINGS_PLAN_UPGRADE,
|
||||
};
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { GET_USAGE_DATA } from 'graphql/queries/get-usage-data.ee';
|
||||
|
||||
type UseUsageDataReturn = {
|
||||
name: string;
|
||||
allowedTaskCount: number;
|
||||
consumedTaskCount: number;
|
||||
remainingTaskCount: number;
|
||||
nextResetAt: DateTime;
|
||||
loading: boolean;
|
||||
};
|
||||
|
||||
export default function useUsageData(): UseUsageDataReturn {
|
||||
const { data, loading } = useQuery(GET_USAGE_DATA);
|
||||
|
||||
const usageData = data?.getUsageData;
|
||||
const nextResetAt = usageData?.nextResetAt;
|
||||
const nextResetAtDateTimeObject = nextResetAt && DateTime.fromMillis(Number(nextResetAt));
|
||||
|
||||
return {
|
||||
name: usageData?.name,
|
||||
allowedTaskCount: usageData?.allowedTaskCount,
|
||||
consumedTaskCount: usageData?.consumedTaskCount,
|
||||
remainingTaskCount: usageData?.remainingTaskCount,
|
||||
nextResetAt: nextResetAtDateTimeObject,
|
||||
loading
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user