## Before  ## After <img width="1056" alt="image" src="https://github.com/user-attachments/assets/4a51b7c7-898b-485f-95e8-97911292f2b1" /> <img width="1299" alt="image" src="https://github.com/user-attachments/assets/44e5e545-a660-455a-91be-3b139ccb9f30" /> <img width="1180" alt="image" src="https://github.com/user-attachments/assets/0ca765a7-1d9a-473a-b7d2-c6f9b1a72417" /> <img width="963" alt="image" src="https://github.com/user-attachments/assets/b620fd8a-61c9-4dd3-a3b1-e4ba940371e4" /> <img width="863" alt="image" src="https://github.com/user-attachments/assets/a0d2dcb5-19e5-4f83-80d4-ad5a715f1e5f" /> --------- Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
import { SettingsBillingLabelValueItem } from '@/billing/components/SettingsBillingLabelValueItem';
|
|
import { useGetWorkflowNodeExecutionUsage } from '@/billing/hooks/useGetWorkflowNodeExecutionUsage';
|
|
import { useSubscriptionStatus } from '@/workspace/hooks/useSubscriptionStatus';
|
|
import styled from '@emotion/styled';
|
|
import { t } from '@lingui/core/macro';
|
|
import { H2Title } from 'twenty-ui/display';
|
|
import { ProgressBar } from 'twenty-ui/feedback';
|
|
import { Section } from 'twenty-ui/layout';
|
|
import { BACKGROUND_LIGHT, COLOR } from 'twenty-ui/theme';
|
|
import { SubscriptionStatus } from '~/generated/graphql';
|
|
import { formatAmount } from '~/utils/format/formatAmount';
|
|
import { formatNumber } from '~/utils/format/number';
|
|
import { SubscriptionInfoContainer } from '@/billing/components/SubscriptionInfoContainer';
|
|
|
|
const StyledLineSeparator = styled.div`
|
|
width: 100%;
|
|
height: 1px;
|
|
background-color: ${({ theme }) => theme.background.tertiary};
|
|
`;
|
|
|
|
export const SettingsBillingMonthlyCreditsSection = () => {
|
|
const subscriptionStatus = useSubscriptionStatus();
|
|
|
|
const isTrialing = subscriptionStatus === SubscriptionStatus.Trialing;
|
|
|
|
const {
|
|
freeUsageQuantity,
|
|
includedFreeQuantity,
|
|
paidUsageQuantity,
|
|
unitPriceCents,
|
|
totalCostCents,
|
|
} = useGetWorkflowNodeExecutionUsage();
|
|
|
|
const isFreeCreditProgressBarCompleted =
|
|
freeUsageQuantity === includedFreeQuantity;
|
|
|
|
const progressBarValue = (freeUsageQuantity / includedFreeQuantity) * 100;
|
|
|
|
const formattedFreeUsageQuantity = isFreeCreditProgressBarCompleted
|
|
? formatAmount(freeUsageQuantity)
|
|
: formatNumber(freeUsageQuantity);
|
|
|
|
return (
|
|
<Section>
|
|
<H2Title
|
|
title={t`Monthly Credits`}
|
|
description={t`Track your monthly workflow credit consumption.`}
|
|
/>
|
|
<SubscriptionInfoContainer>
|
|
<SettingsBillingLabelValueItem
|
|
label={t`Free Credits Used`}
|
|
value={`${formattedFreeUsageQuantity}/${formatAmount(includedFreeQuantity)}`}
|
|
/>
|
|
<ProgressBar
|
|
value={progressBarValue}
|
|
barColor={
|
|
isFreeCreditProgressBarCompleted
|
|
? BACKGROUND_LIGHT.quaternary
|
|
: COLOR.blue
|
|
}
|
|
backgroundColor={BACKGROUND_LIGHT.tertiary}
|
|
withBorderRadius={true}
|
|
/>
|
|
|
|
<StyledLineSeparator />
|
|
{!isTrialing && (
|
|
<SettingsBillingLabelValueItem
|
|
label={t`Extra Credits Used`}
|
|
value={`${formatNumber(paidUsageQuantity)}`}
|
|
/>
|
|
)}
|
|
<SettingsBillingLabelValueItem
|
|
label={t`Cost per 1k Extra Credits`}
|
|
value={`$${formatNumber((unitPriceCents / 100) * 1000, 2)}`}
|
|
/>
|
|
{!isTrialing && (
|
|
<SettingsBillingLabelValueItem
|
|
label={t`Cost`}
|
|
isValueInPrimaryColor={true}
|
|
value={`$${formatNumber(totalCostCents / 100, 2)}`}
|
|
/>
|
|
)}
|
|
</SubscriptionInfoContainer>
|
|
</Section>
|
|
);
|
|
};
|