feat: finalize TrialOverAlert on billing page
This commit is contained in:
32
packages/web/src/components/TrialOverAlert/index.ee.tsx
Normal file
32
packages/web/src/components/TrialOverAlert/index.ee.tsx
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
|
||||||
|
import * as URLS from 'config/urls';
|
||||||
|
import { generateInternalLink } from 'helpers/translation-values';
|
||||||
|
import useTrialStatus from 'hooks/useTrialStatus.ee';
|
||||||
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
|
|
||||||
|
|
||||||
|
export default function TrialOverAlert() {
|
||||||
|
const formatMessage = useFormatMessage();
|
||||||
|
const trialStatus = useTrialStatus();
|
||||||
|
|
||||||
|
if (!trialStatus || !trialStatus.over) return <React.Fragment />;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
severity="error"
|
||||||
|
sx={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography variant="subtitle2" sx={{ lineHeight: 1.5 }}>
|
||||||
|
{formatMessage('trialOverAlert.text', {
|
||||||
|
link: generateInternalLink(URLS.SETTINGS_PLAN_UPGRADE)
|
||||||
|
})}
|
||||||
|
</Typography>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
@@ -13,6 +13,7 @@ import Grid from '@mui/material/Grid';
|
|||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
|
|
||||||
import { TBillingCardAction } from '@automatisch/types';
|
import { TBillingCardAction } from '@automatisch/types';
|
||||||
|
import TrialOverAlert from 'components/TrialOverAlert/index.ee';
|
||||||
import * as URLS from 'config/urls';
|
import * as URLS from 'config/urls';
|
||||||
import useBillingAndUsageData from 'hooks/useBillingAndUsageData.ee';
|
import useBillingAndUsageData from 'hooks/useBillingAndUsageData.ee';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
@@ -96,19 +97,7 @@ export default function UsageDataInformation() {
|
|||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Stack sx={{ width: '100%', mb: 2 }} spacing={2}>
|
<Stack sx={{ width: '100%', mb: 2 }} spacing={2}>
|
||||||
<Alert
|
<TrialOverAlert />
|
||||||
severity="error"
|
|
||||||
sx={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography variant="subtitle2">
|
|
||||||
Your free trial is over. Please{' '}
|
|
||||||
<Link to={URLS.SETTINGS_PLAN_UPGRADE}>upgrade </Link>
|
|
||||||
your plan to continue using Automatisch.
|
|
||||||
</Typography>
|
|
||||||
</Alert>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
<Card sx={{ mb: 3, p: 2 }}>
|
<Card sx={{ mb: 3, p: 2 }}>
|
||||||
<CardContent sx={{ display: 'flex', flexDirection: 'column' }}>
|
<CardContent sx={{ display: 'flex', flexDirection: 'column' }}>
|
||||||
|
@@ -1,5 +1,13 @@
|
|||||||
|
import { Link as RouterLink } from 'react-router-dom';
|
||||||
import Link from '@mui/material/Link';
|
import Link from '@mui/material/Link';
|
||||||
|
|
||||||
|
export const generateInternalLink = (link: string) => (str: string) =>
|
||||||
|
(
|
||||||
|
<Link component={RouterLink} to={link}>
|
||||||
|
{str}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
|
||||||
export const generateExternalLink = (link: string) => (str: string) =>
|
export const generateExternalLink = (link: string) => (str: string) =>
|
||||||
(
|
(
|
||||||
<Link href={link} target="_blank">
|
<Link href={link} target="_blank">
|
||||||
|
@@ -7,6 +7,7 @@ import useFormatMessage from './useFormatMessage';
|
|||||||
type UseTrialStatusReturn = {
|
type UseTrialStatusReturn = {
|
||||||
expireAt: DateTime;
|
expireAt: DateTime;
|
||||||
message: string;
|
message: string;
|
||||||
|
over: boolean;
|
||||||
status: 'error' | 'warning';
|
status: 'error' | 'warning';
|
||||||
} | null;
|
} | null;
|
||||||
|
|
||||||
@@ -25,11 +26,13 @@ function getFeedbackPayload(date: DateTime) {
|
|||||||
return {
|
return {
|
||||||
translationEntryId: 'trialBadge.over',
|
translationEntryId: 'trialBadge.over',
|
||||||
status: 'error' as const,
|
status: 'error' as const,
|
||||||
|
over: true,
|
||||||
};
|
};
|
||||||
} else if (diffInDays <= 0) {
|
} else if (diffInDays <= 0) {
|
||||||
return {
|
return {
|
||||||
translationEntryId: 'trialBadge.endsToday',
|
translationEntryId: 'trialBadge.endsToday',
|
||||||
status: 'warning' as const,
|
status: 'warning' as const,
|
||||||
|
over: false,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
@@ -38,6 +41,7 @@ function getFeedbackPayload(date: DateTime) {
|
|||||||
remainingDays: diffInDays
|
remainingDays: diffInDays
|
||||||
},
|
},
|
||||||
status: 'warning' as const,
|
status: 'warning' as const,
|
||||||
|
over: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,11 +58,13 @@ export default function useTrialStatus(): UseTrialStatusReturn {
|
|||||||
translationEntryId,
|
translationEntryId,
|
||||||
translationEntryValues,
|
translationEntryValues,
|
||||||
status,
|
status,
|
||||||
|
over,
|
||||||
} = getFeedbackPayload(expireAt);
|
} = getFeedbackPayload(expireAt);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: formatMessage(translationEntryId, translationEntryValues),
|
message: formatMessage(translationEntryId, translationEntryValues),
|
||||||
expireAt,
|
expireAt,
|
||||||
|
over,
|
||||||
status
|
status
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -155,5 +155,6 @@
|
|||||||
"invoices.link": "Link",
|
"invoices.link": "Link",
|
||||||
"trialBadge.xDaysLeft": "{remainingDays} trial {remainingDays, plural, one {day} other {days}} left",
|
"trialBadge.xDaysLeft": "{remainingDays} trial {remainingDays, plural, one {day} other {days}} left",
|
||||||
"trialBadge.endsToday": "Trial ends today",
|
"trialBadge.endsToday": "Trial ends today",
|
||||||
"trialBadge.over": "Trial is over"
|
"trialBadge.over": "Trial is over",
|
||||||
|
"trialOverAlert.text": "Your free trial is over. Please <link>upgrade</link> your plan to continue using Automatisch."
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user