The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
import { t } from "ttag";
import { ButtonLink } from "metabase/common/components/ExternalLink";
import { useStoreUrl } from "metabase/common/hooks";
import { SettingHeader } from "metabase/settings-components";
import { Alert, Anchor, Box, Icon } from "metabase/ui";
import type { BillingInfo as IBillingInfo } from "metabase-types/api";
import { BillingInfoTable } from "./BillingInfoTable";
interface BillingInfoProps {
isStoreManagedBilling: boolean;
billingInfo?: IBillingInfo | null;
hasToken: boolean;
error: boolean;
}
export function BillingInfo({
isStoreManagedBilling,
billingInfo,
hasToken,
error,
}: BillingInfoProps) {
if (error) {
return <BillingInfoError />;
}
if (!hasToken) {
return <BillingGoToStore />;
}
if (!isStoreManagedBilling) {
return <BillingInfoNotStoreManaged />;
}
if (billingInfo?.content?.length) {
return <BillingInfoTable billingInfo={billingInfo} />;
}
// Store-managed token but no billing content from Store (e.g. `{ "version": "v1" }`)
return <BillingGoToStore />;
}
const BillingInfoError = () => {
return (
<>
<SettingHeader id="billing" title={t`Billing`} />
<Box mt="1rem" data-testid="billing-info-error">
<Alert color="error" icon={<Icon name="warning" />}>
{t`An error occurred while fetching information about your billing.`}
<br />
<strong>{t`Need help?`}</strong> {t`You can ask for billing help at `}
<strong>
{/* eslint-disable i18next/no-literal-string -- untranslated billing address */}
<Anchor href="mailto:[email protected]">
[email protected]
</Anchor>
{/* eslint-enable i18next/no-literal-string */}
</strong>
</Alert>
</Box>
</>
);
};
const BillingGoToStore = () => {
const url = useStoreUrl();
return (
<>
<SettingHeader
id="billing"
title={t`Billing`}
// eslint-disable-next-line metabase/no-literal-metabase-strings -- Metabase settings
description={t`Manage your Cloud account, including billing preferences, in your Metabase Store account.`}
/>
<ButtonLink href={url}>
{/* eslint-disable-next-line metabase/no-literal-metabase-strings -- Metabase settings */}
{t`Go to the Metabase Store`}
<Icon name="external" opacity={0.6} ml="sm" />
</ButtonLink>
</>
);
};
const BillingInfoNotStoreManaged = () => {
return (
<SettingHeader
id="billing"
title={t`Billing`}
description={
<>
{t`To manage your billing preferences, please email `}
{/* eslint-disable i18next/no-literal-string -- untranslated billing address */}
<Anchor href="mailto:[email protected]">
[email protected]
</Anchor>
{/* eslint-enable i18next/no-literal-string */}
</>
}
/>
);
};