mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-05-06 05:48:41 +00:00
107 lines
2.9 KiB
TypeScript
107 lines
2.9 KiB
TypeScript
import { useTranslation } from "react-i18next";
|
|
import {
|
|
cn,
|
|
getDaysBetweenDatesWithAutoRenewal,
|
|
type PublicNoteData,
|
|
} from "@/lib/utils";
|
|
|
|
import RemainPercentBar from "./RemainPercentBar";
|
|
|
|
export default function BillingInfo({
|
|
parsedData,
|
|
}: {
|
|
parsedData: PublicNoteData;
|
|
}) {
|
|
const { t } = useTranslation();
|
|
if (!parsedData || !parsedData.billingDataMod) {
|
|
return null;
|
|
}
|
|
|
|
let isNeverExpire = false;
|
|
let daysLeftObject = {
|
|
days: 0,
|
|
cycleLabel: "",
|
|
remainingPercentage: 0,
|
|
};
|
|
const hasBillingDates =
|
|
Boolean(parsedData.billingDataMod.startDate) ||
|
|
Boolean(parsedData.billingDataMod.endDate);
|
|
|
|
if (parsedData?.billingDataMod?.endDate) {
|
|
if (parsedData.billingDataMod.endDate.startsWith("0000-00-00")) {
|
|
isNeverExpire = true;
|
|
} else {
|
|
try {
|
|
daysLeftObject = getDaysBetweenDatesWithAutoRenewal(
|
|
parsedData.billingDataMod,
|
|
);
|
|
} catch (error) {
|
|
console.error(error);
|
|
return (
|
|
<div className={cn("text-[10px] text-muted-foreground text-red-600")}>
|
|
{t("billingInfo.remaining")}: {t("billingInfo.error")}
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
return daysLeftObject.days >= 0 ? (
|
|
<>
|
|
{parsedData.billingDataMod.amount &&
|
|
parsedData.billingDataMod.amount !== "0" &&
|
|
parsedData.billingDataMod.amount !== "-1" ? (
|
|
<p className={cn("text-[10px] text-muted-foreground ")}>
|
|
{t("billingInfo.price")}: {parsedData.billingDataMod.amount}/
|
|
{parsedData.billingDataMod.cycle}
|
|
</p>
|
|
) : parsedData.billingDataMod.amount === "0" ? (
|
|
<p className={cn("text-[10px] text-green-600 ")}>
|
|
{t("billingInfo.free")}
|
|
</p>
|
|
) : parsedData.billingDataMod.amount === "-1" ? (
|
|
<p className={cn("text-[10px] text-pink-600 ")}>
|
|
{t("billingInfo.usage-baseed")}
|
|
</p>
|
|
) : null}
|
|
{hasBillingDates && (
|
|
<div className={cn("text-[10px] text-muted-foreground")}>
|
|
{t("billingInfo.remaining")}:{" "}
|
|
{isNeverExpire
|
|
? t("billingInfo.indefinite")
|
|
: `${daysLeftObject.days} ${t("billingInfo.days")}`}
|
|
</div>
|
|
)}
|
|
{hasBillingDates && !isNeverExpire && (
|
|
<RemainPercentBar
|
|
className="mt-0.5"
|
|
value={daysLeftObject.remainingPercentage * 100}
|
|
/>
|
|
)}
|
|
</>
|
|
) : (
|
|
<>
|
|
{parsedData.billingDataMod.amount &&
|
|
parsedData.billingDataMod.amount !== "0" &&
|
|
parsedData.billingDataMod.amount !== "-1" ? (
|
|
<p className={cn("text-[10px] text-muted-foreground ")}>
|
|
{t("billingInfo.price")}: {parsedData.billingDataMod.amount}/
|
|
{parsedData.billingDataMod.cycle}
|
|
</p>
|
|
) : parsedData.billingDataMod.amount === "0" ? (
|
|
<p className={cn("text-[10px] text-green-600 ")}>
|
|
{t("billingInfo.free")}
|
|
</p>
|
|
) : parsedData.billingDataMod.amount === "-1" ? (
|
|
<p className={cn("text-[10px] text-pink-600 ")}>
|
|
{t("billingInfo.usage-baseed")}
|
|
</p>
|
|
) : null}
|
|
<p className={cn("text-[10px] text-muted-foreground text-red-600")}>
|
|
{t("billingInfo.expired")}: {daysLeftObject.days * -1}{" "}
|
|
{t("billingInfo.days")}
|
|
</p>
|
|
</>
|
|
);
|
|
}
|