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