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.
225 lines
7.6 KiB
TypeScript
225 lines
7.6 KiB
TypeScript
import { Card, Text, Group, Badge, Stack, Tooltip, ActionIcon } from "@mantine/core";
|
|
import GroupIcon from "@mui/icons-material/Group";
|
|
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";
|
|
import { Z_INDEX_OVER_CONFIG_MODAL } from "@app/styles/zIndex";
|
|
|
|
interface TeamData {
|
|
teamId: number;
|
|
name: string;
|
|
isPersonal: boolean;
|
|
isLeader: boolean;
|
|
seatsUsed: number;
|
|
}
|
|
|
|
interface ActiveSubscriptionCardProps {
|
|
tier: BillingStatus["tier"];
|
|
subscription: BillingStatus["subscription"];
|
|
usage: BillingStatus["meterUsage"];
|
|
isTrialing: boolean;
|
|
price?: number;
|
|
currency?: string;
|
|
currentTeam?: TeamData | null;
|
|
isTeamLeader?: boolean;
|
|
isPersonalTeam?: boolean;
|
|
}
|
|
|
|
export function ActiveSubscriptionCard({
|
|
tier,
|
|
subscription,
|
|
usage,
|
|
isTrialing,
|
|
price,
|
|
currency,
|
|
currentTeam,
|
|
isTeamLeader = false,
|
|
isPersonalTeam = true,
|
|
}: ActiveSubscriptionCardProps) {
|
|
const { t } = useTranslation();
|
|
|
|
// Format timestamp to readable date
|
|
const formatDate = (timestamp: number): string => {
|
|
return new Date(timestamp * 1000).toLocaleDateString(undefined, {
|
|
year: "numeric",
|
|
month: "long",
|
|
day: "numeric",
|
|
});
|
|
};
|
|
|
|
// Get tier display name
|
|
const getTierName = (): string => {
|
|
switch (tier) {
|
|
case "free":
|
|
return t("settings.planBilling.tier.free", "Free Plan");
|
|
case "team":
|
|
return t("settings.planBilling.tier.team", "Team Plan");
|
|
case "enterprise":
|
|
return t("settings.planBilling.tier.enterprise", "Enterprise Plan");
|
|
default:
|
|
return tier;
|
|
}
|
|
};
|
|
|
|
// Get price display
|
|
const getPriceDisplay = (): string => {
|
|
if (tier === "free") {
|
|
return "$0/month";
|
|
}
|
|
// Use actual price from Stripe if available
|
|
if (price !== undefined && currency) {
|
|
return `${currency}${price}/month`;
|
|
}
|
|
// Fallback to default pricing
|
|
return "$10/month";
|
|
};
|
|
|
|
// Get description
|
|
const getDescription = (): string => {
|
|
if (tier === "free") {
|
|
return t("settings.planBilling.tier.freeDescription", "50 credits per month");
|
|
}
|
|
return t(
|
|
"settings.planBilling.tier.teamDescription",
|
|
"500 credits/month included, automatic overage billing for uninterrupted service",
|
|
);
|
|
};
|
|
|
|
// Format overage cost
|
|
const formatOverageCost = (cents: number, credits: number): string => {
|
|
return t("settings.planBilling.billing.overageCost", {
|
|
amount: `$${(cents / 100).toFixed(2)}`,
|
|
credits,
|
|
defaultValue: `Current overage cost: $${(cents / 100).toFixed(2)} (${credits} credits)`,
|
|
});
|
|
};
|
|
|
|
// Pro/Team card
|
|
if (tier === "team" || tier === "enterprise") {
|
|
return (
|
|
<Card padding="lg" radius="md" withBorder>
|
|
<Stack gap="sm">
|
|
<Group justify="space-between" align="flex-start">
|
|
{/* Left side: Name, badges, description */}
|
|
<div style={{ flex: 1 }}>
|
|
<Group gap="xs" mb="xs">
|
|
<Text size="lg" fw={600}>
|
|
{!isPersonalTeam && isTeamLeader ? t("settings.planBilling.tier.team", "Team Plan") : getTierName()}
|
|
</Text>
|
|
{!isPersonalTeam && (
|
|
<Badge color="violet" variant="light" leftSection={<GroupIcon sx={{ fontSize: 12 }} />}>
|
|
{t("settings.planBilling.tier.teamBadge", "Team")}
|
|
</Badge>
|
|
)}
|
|
<Tooltip
|
|
label={
|
|
<div style={{ maxWidth: 300 }}>
|
|
<Text size="sm" mb="xs">
|
|
{t("settings.planBilling.tier.teamTooltipCredits", {
|
|
credits: BILLING_CONFIG.INCLUDED_CREDITS_PER_MONTH,
|
|
defaultValue: `Team plan includes ${BILLING_CONFIG.INCLUDED_CREDITS_PER_MONTH} credits/month.`,
|
|
})}
|
|
</Text>
|
|
<Text size="sm" mb="xs">
|
|
{t("settings.planBilling.tier.teamTooltipOverage", {
|
|
price: getFormattedOveragePrice(),
|
|
defaultValue: `Automatic overage billing at ${getFormattedOveragePrice()}/credit ensures uninterrupted service.`,
|
|
})}
|
|
</Text>
|
|
<Text size="sm">
|
|
{t(
|
|
"settings.planBilling.tier.teamTooltipFineprint",
|
|
"Only pay for what you use beyond included credits.",
|
|
)}
|
|
</Text>
|
|
</div>
|
|
}
|
|
multiline
|
|
withArrow
|
|
position="right"
|
|
zIndex={Z_INDEX_OVER_CONFIG_MODAL}
|
|
>
|
|
<ActionIcon variant="subtle" color="gray" size="sm">
|
|
<InfoOutlinedIcon style={{ fontSize: 18 }} />
|
|
</ActionIcon>
|
|
</Tooltip>
|
|
{isTrialing && (
|
|
<Badge color="blue" variant="light">
|
|
{t("settings.planBilling.status.trial", "Trial")}
|
|
</Badge>
|
|
)}
|
|
</Group>
|
|
{!isPersonalTeam && !isTeamLeader && (
|
|
<Text size="sm" c="dimmed" mb="xs">
|
|
{t("settings.planBilling.team.managedByTeam", "Managed by team")}
|
|
</Text>
|
|
)}
|
|
{!isPersonalTeam && isTeamLeader && currentTeam && (
|
|
<Text size="sm" c="dimmed" mb="xs">
|
|
{t("settings.planBilling.team.memberCount", "{{count}} team members", { count: currentTeam.seatsUsed })}
|
|
</Text>
|
|
)}
|
|
<Text size="sm" c="dimmed" mb="xs">
|
|
{getDescription()}
|
|
</Text>
|
|
{/* Show overage cost if applicable */}
|
|
{usage && usage.currentPeriodCredits > 0 && (
|
|
<Text size="sm" c="orange" fw={500}>
|
|
{formatOverageCost(usage.estimatedCost, usage.currentPeriodCredits)}
|
|
</Text>
|
|
)}
|
|
</div>
|
|
|
|
{/* Right side: Price */}
|
|
<div style={{ textAlign: "right" }}>
|
|
{!isPersonalTeam && !isTeamLeader ? (
|
|
<Text size="lg" c="dimmed">
|
|
{t("settings.planBilling.team.managedByTeam", "Managed by team")}
|
|
</Text>
|
|
) : (
|
|
<Text size="xl" fw={700}>
|
|
{getPriceDisplay()}
|
|
</Text>
|
|
)}
|
|
</div>
|
|
</Group>
|
|
|
|
{/* Next billing date at bottom */}
|
|
{subscription?.currentPeriodEnd && (
|
|
<Group gap="xs" mt="xs">
|
|
<Text size="sm" c="dimmed">
|
|
{t("settings.planBilling.billing.nextBillingDate", "Next billing date:")}{" "}
|
|
{formatDate(subscription.currentPeriodEnd)}
|
|
</Text>
|
|
</Group>
|
|
)}
|
|
</Stack>
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
// Free plan card
|
|
return (
|
|
<Card padding="lg" radius="md" withBorder>
|
|
<Group justify="space-between" align="center">
|
|
<div>
|
|
<Group gap="xs">
|
|
<Text size="lg" fw={600}>
|
|
{getTierName()}
|
|
</Text>
|
|
</Group>
|
|
<Text size="sm" c="dimmed">
|
|
{getDescription()}
|
|
</Text>
|
|
</div>
|
|
<div style={{ textAlign: "right" }}>
|
|
<Text size="xl" fw={700}>
|
|
{getPriceDisplay()}
|
|
</Text>
|
|
</div>
|
|
</Group>
|
|
</Card>
|
|
);
|
|
}
|