Merge pull request #978 from automatisch/expose-payment-portal
feat: show payment portal information
This commit is contained in:
28
packages/web/src/components/PaymentInformation/index.ee.tsx
Normal file
28
packages/web/src/components/PaymentInformation/index.ee.tsx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
|
||||||
|
import PageTitle from 'components/PageTitle';
|
||||||
|
import { generateExternalLink } from 'helpers/translation-values';
|
||||||
|
import usePaymentPortalUrl from 'hooks/usePaymentPortalUrl.ee';
|
||||||
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
|
|
||||||
|
export default function PaymentInformation() {
|
||||||
|
const paymentPortal = usePaymentPortalUrl();
|
||||||
|
const formatMessage = useFormatMessage();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<PageTitle
|
||||||
|
gutterBottom
|
||||||
|
>
|
||||||
|
{formatMessage('billingAndUsageSettings.paymentInformation')}
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<Typography>
|
||||||
|
{formatMessage(
|
||||||
|
'billingAndUsageSettings.paymentPortalInformation',
|
||||||
|
{ link: generateExternalLink(paymentPortal.url) })}
|
||||||
|
</Typography>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
@@ -20,15 +20,16 @@ export const AutomatischInfoProvider = (
|
|||||||
props: AutomatischInfoProviderProps
|
props: AutomatischInfoProviderProps
|
||||||
): React.ReactElement => {
|
): React.ReactElement => {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
const { data } = useQuery(GET_AUTOMATISCH_INFO);
|
const { data, loading } = useQuery(GET_AUTOMATISCH_INFO);
|
||||||
|
|
||||||
const isCloud = data?.getAutomatischInfo?.isCloud || false;
|
const isCloud = data?.getAutomatischInfo?.isCloud;
|
||||||
|
|
||||||
const value = React.useMemo(() => {
|
const value = React.useMemo(() => {
|
||||||
return {
|
return {
|
||||||
isCloud,
|
isCloud,
|
||||||
|
loading
|
||||||
};
|
};
|
||||||
}, [isCloud]);
|
}, [isCloud, loading]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AutomatischInfoContext.Provider value={value}>
|
<AutomatischInfoContext.Provider value={value}>
|
||||||
|
@@ -0,0 +1,10 @@
|
|||||||
|
import { gql } from '@apollo/client';
|
||||||
|
|
||||||
|
export const GET_PAYMENT_PORTAL_URL = gql`
|
||||||
|
query GetPaymentPortalUrl {
|
||||||
|
getPaymentPortalUrl {
|
||||||
|
url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
@@ -1,6 +1,8 @@
|
|||||||
|
import Link from '@mui/material/Link';
|
||||||
|
|
||||||
export const generateExternalLink = (link: string) => (str: string) =>
|
export const generateExternalLink = (link: string) => (str: string) =>
|
||||||
(
|
(
|
||||||
<a href={link} target="_blank">
|
<Link href={link} target="_blank">
|
||||||
{str}
|
{str}
|
||||||
</a>
|
</Link>
|
||||||
);
|
);
|
||||||
|
16
packages/web/src/hooks/usePaymentPortalUrl.ee.ts
Normal file
16
packages/web/src/hooks/usePaymentPortalUrl.ee.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { useQuery } from '@apollo/client';
|
||||||
|
import { GET_PAYMENT_PORTAL_URL } from 'graphql/queries/get-payment-portal-url.ee';
|
||||||
|
|
||||||
|
type UsePaymentPortalUrlReturn = {
|
||||||
|
url: string;
|
||||||
|
loading: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function usePaymentPortalUrl(): UsePaymentPortalUrlReturn {
|
||||||
|
const { data, loading } = useQuery(GET_PAYMENT_PORTAL_URL);
|
||||||
|
|
||||||
|
return {
|
||||||
|
url: data?.getPaymentPortalUrl?.url,
|
||||||
|
loading
|
||||||
|
};
|
||||||
|
}
|
@@ -98,6 +98,8 @@
|
|||||||
"profileSettings.deleteAccountResult3": "All your connections",
|
"profileSettings.deleteAccountResult3": "All your connections",
|
||||||
"profileSettings.deleteAccountResult4": "All execution history",
|
"profileSettings.deleteAccountResult4": "All execution history",
|
||||||
"billingAndUsageSettings.title": "Billing and usage",
|
"billingAndUsageSettings.title": "Billing and usage",
|
||||||
|
"billingAndUsageSettings.paymentInformation": "Payment information",
|
||||||
|
"billingAndUsageSettings.paymentPortalInformation": "To manage your subscription, click <link>here</link> to go to the payment portal.",
|
||||||
"deleteAccountDialog.title": "Delete account?",
|
"deleteAccountDialog.title": "Delete account?",
|
||||||
"deleteAccountDialog.description": "This will permanently delete your account and all the associated data with it.",
|
"deleteAccountDialog.description": "This will permanently delete your account and all the associated data with it.",
|
||||||
"deleteAccountDialog.cancel": "Cancel?",
|
"deleteAccountDialog.cancel": "Cancel?",
|
||||||
|
@@ -3,6 +3,7 @@ import { Navigate } from 'react-router-dom';
|
|||||||
import Grid from '@mui/material/Grid';
|
import Grid from '@mui/material/Grid';
|
||||||
|
|
||||||
import * as URLS from 'config/urls'
|
import * as URLS from 'config/urls'
|
||||||
|
import PaymentInformation from 'components/PaymentInformation/index.ee';
|
||||||
import PageTitle from 'components/PageTitle';
|
import PageTitle from 'components/PageTitle';
|
||||||
import Container from 'components/Container';
|
import Container from 'components/Container';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
@@ -12,10 +13,15 @@ function BillingAndUsageSettings() {
|
|||||||
const isCloud = useCloud();
|
const isCloud = useCloud();
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
|
|
||||||
if (!isCloud) {
|
// redirect to the initial settings page
|
||||||
|
if (isCloud === false) {
|
||||||
return (<Navigate to={URLS.SETTINGS} replace={true} />)
|
return (<Navigate to={URLS.SETTINGS} replace={true} />)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// render nothing until we know if it's cloud or not
|
||||||
|
// here, `isCloud` is not `false`, but `undefined`
|
||||||
|
if (!isCloud) return <React.Fragment />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container sx={{ py: 3, display: 'flex', justifyContent: 'center' }}>
|
<Container sx={{ py: 3, display: 'flex', justifyContent: 'center' }}>
|
||||||
<Grid container item xs={12} sm={9} md={8} lg={6}>
|
<Grid container item xs={12} sm={9} md={8} lg={6}>
|
||||||
@@ -23,7 +29,8 @@ function BillingAndUsageSettings() {
|
|||||||
<PageTitle>{formatMessage('billingAndUsageSettings.title')}</PageTitle>
|
<PageTitle>{formatMessage('billingAndUsageSettings.title')}</PageTitle>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid item xs={12} justifyContent="flex-end" sx={{pt: 5 }}>
|
<Grid item xs={12} justifyContent="flex-end" sx={{ mt: 2 }}>
|
||||||
|
<PaymentInformation />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Container>
|
</Container>
|
||||||
|
Reference in New Issue
Block a user