Files
formbricks/apps/web/modules/ee/billing/components/trial-alert.tsx
T
Matti Nannt ce96cb0b89 feat: replace hosted stripe pricing table (#7486)
Co-authored-by: Johannes <johannes@formbricks.com>
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com>
2026-03-16 10:11:40 +00:00

45 lines
1.2 KiB
TypeScript

"use client";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { Alert, AlertTitle } from "@/modules/ui/components/alert";
type TrialAlertVariant = "error" | "warning" | "info" | "success";
const getTrialVariant = (daysRemaining: number): TrialAlertVariant => {
if (daysRemaining <= 3) return "error";
if (daysRemaining <= 7) return "warning";
return "info";
};
interface TrialAlertProps {
trialDaysRemaining: number;
size?: "small";
hasPaymentMethod?: boolean;
children?: React.ReactNode;
}
export const TrialAlert = ({
trialDaysRemaining,
size,
hasPaymentMethod = false,
children,
}: TrialAlertProps) => {
const { t } = useTranslation();
const title = useMemo(() => {
if (trialDaysRemaining <= 0) return t("common.trial_expired");
if (trialDaysRemaining === 1) return t("common.trial_one_day_remaining");
return t("common.trial_days_remaining", { count: trialDaysRemaining });
}, [trialDaysRemaining, t]);
const variant = hasPaymentMethod ? "success" : getTrialVariant(trialDaysRemaining);
return (
<Alert variant={variant} size={size} className="max-w-4xl">
<AlertTitle>{title}</AlertTitle>
{children}
</Alert>
);
};