mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-08 02:43:06 -05:00
ce96cb0b89
Co-authored-by: Johannes <johannes@formbricks.com> Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com> Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com>
45 lines
1.2 KiB
TypeScript
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>
|
|
);
|
|
};
|