mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 11:00:47 +02:00
# Description of Changes Changes the strategy for autoformatting to reject PRs if they are not formatted correctly instead of allowing them to merge and then spawning a new PR to fix the formatting. The old strategy just caused more work for us because we'd have to manually approve the followup PR and get it merged, which required 2 reviewers so in practice it rarely got done and just meant everyone's PRs ended up containing reformatting for unrelated files, which makes code review unnecessarily difficult. If the PR's code is not formatted correctly after this PR, a comment will be added automatically to tell the author how to run the formatter script to fix their code so it can go in. This also enables autoformatting for the frontend code, using Prettier. I've enabled it for pretty much everything in the frontend folder, other than 3rd party files and files it doesn't make sense for. I also excluded Markdown because it sounds likely to be more annoying to have to autoformat the Markdown in the frontend folder but nowhere else. Open to changing this though if people disagree. > [!note] > > Advice to reviewers: The first commit contains all of the actual logic I've introduced (CI changes, Prettier config, etc.) > The second commit is just the reformatting of the entire frontend folder. > The first commit needs proper review, the second one just give it a spot-check that it's doing what you'd expect.
117 lines
4.3 KiB
TypeScript
117 lines
4.3 KiB
TypeScript
import React from "react";
|
|
import { Card, Text, Stack, Group, Progress, Alert } from "@mantine/core";
|
|
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
|
import { useTranslation } from "react-i18next";
|
|
import type { BillingStatus } from "@app/services/saasBillingService";
|
|
import { BILLING_CONFIG, getFormattedOveragePrice } from "@app/config/billing";
|
|
|
|
interface UsageDisplayProps {
|
|
tier: BillingStatus["tier"];
|
|
usage: BillingStatus["meterUsage"];
|
|
}
|
|
|
|
export function UsageDisplay({ tier, usage }: UsageDisplayProps) {
|
|
const { t } = useTranslation();
|
|
|
|
// Credits per month based on tier
|
|
const getMonthlyCredits = (): number => {
|
|
switch (tier) {
|
|
case "free":
|
|
return BILLING_CONFIG.FREE_CREDITS_PER_MONTH;
|
|
case "team":
|
|
return BILLING_CONFIG.INCLUDED_CREDITS_PER_MONTH;
|
|
case "enterprise":
|
|
return 1000; // Placeholder — enterprise credits are custom
|
|
default:
|
|
return BILLING_CONFIG.FREE_CREDITS_PER_MONTH;
|
|
}
|
|
};
|
|
|
|
const monthlyCredits = getMonthlyCredits();
|
|
|
|
// Format currency
|
|
const formatCurrency = (cents: number): string => {
|
|
return `$${(cents / 100).toFixed(2)}`;
|
|
};
|
|
|
|
return (
|
|
<Card shadow="sm" padding="lg" radius="md" withBorder>
|
|
<Stack gap="md">
|
|
{/* Header */}
|
|
<Text size="lg" fw={600}>
|
|
{t("settings.planBilling.credits.title", "Credit Usage")}
|
|
</Text>
|
|
|
|
{/* Monthly credits info */}
|
|
<Group justify="space-between">
|
|
<Text size="sm" c="dimmed">
|
|
{t("settings.planBilling.credits.included", {
|
|
count: monthlyCredits,
|
|
defaultValue: `${monthlyCredits} credits/month (included)`,
|
|
})}
|
|
</Text>
|
|
</Group>
|
|
|
|
{/* Overage credits (if metered billing enabled) */}
|
|
{usage && usage.currentPeriodCredits > 0 && (
|
|
<>
|
|
<Stack gap="xs">
|
|
<Group justify="space-between">
|
|
<Text size="sm" c="dimmed">
|
|
{t("settings.planBilling.credits.overage", {
|
|
count: usage.currentPeriodCredits,
|
|
defaultValue: `+ ${usage.currentPeriodCredits} overage`,
|
|
})}
|
|
</Text>
|
|
<Text size="sm" fw={500} c="orange">
|
|
{t("settings.planBilling.credits.estimatedCost", {
|
|
amount: formatCurrency(usage.estimatedCost),
|
|
defaultValue: `Estimated cost: ${formatCurrency(usage.estimatedCost)}`,
|
|
})}
|
|
</Text>
|
|
</Group>
|
|
|
|
{/* Progress bar for overage usage */}
|
|
<Progress value={100} color="orange" size="sm" radius="xl" striped animated />
|
|
</Stack>
|
|
|
|
<Alert color="blue" variant="light" icon={<InfoOutlinedIcon sx={{ fontSize: 16 }} />}>
|
|
<Text size="xs">
|
|
{t("settings.planBilling.credits.overageInfo", {
|
|
price: getFormattedOveragePrice(),
|
|
defaultValue: `Overage credits are billed at ${getFormattedOveragePrice()} per credit. You'll only pay for what you use beyond your monthly allowance.`,
|
|
})}
|
|
</Text>
|
|
</Alert>
|
|
</>
|
|
)}
|
|
|
|
{/* No overage message */}
|
|
{(!usage || usage.currentPeriodCredits === 0) && tier !== "free" && (
|
|
<Alert color="green" variant="light">
|
|
<Text size="sm">
|
|
{t("settings.planBilling.credits.noOverage", {
|
|
count: monthlyCredits,
|
|
defaultValue: `No overage charges this month. You're using your included ${monthlyCredits} credits.`,
|
|
})}
|
|
</Text>
|
|
</Alert>
|
|
)}
|
|
|
|
{/* Free tier message */}
|
|
{tier === "free" && (
|
|
<Alert color="blue" variant="light">
|
|
<Text size="sm">
|
|
{t("settings.planBilling.credits.freeTierInfo", {
|
|
freeCredits: BILLING_CONFIG.FREE_CREDITS_PER_MONTH,
|
|
teamCredits: BILLING_CONFIG.INCLUDED_CREDITS_PER_MONTH,
|
|
defaultValue: `Free plan includes ${BILLING_CONFIG.FREE_CREDITS_PER_MONTH} credits per month. Upgrade to Team for ${BILLING_CONFIG.INCLUDED_CREDITS_PER_MONTH} credits/month and pay-as-you-go overage billing.`,
|
|
})}
|
|
</Text>
|
|
</Alert>
|
|
)}
|
|
</Stack>
|
|
</Card>
|
|
);
|
|
}
|