chore: remove UsageAlert
This commit is contained in:
@@ -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