1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

fix: pro flow stripe integration refinements (#1149)

This commit is contained in:
Nuno Góis 2022-07-26 08:50:27 +01:00 committed by GitHub
parent 23b9cbaf03
commit 65c0580519
5 changed files with 27 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import AdminMenu from '../menu/AdminMenu'; import AdminMenu from '../menu/AdminMenu';
import { PageContent } from 'component/common/PageContent/PageContent'; import { PageContent } from 'component/common/PageContent/PageContent';
import { useContext } from 'react'; import { useContext, useEffect } from 'react';
import { ADMIN } from 'component/providers/AccessProvider/permissions'; import { ADMIN } from 'component/providers/AccessProvider/permissions';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import AccessContext from 'contexts/AccessContext'; import AccessContext from 'contexts/AccessContext';
@ -12,14 +12,28 @@ import { BillingHistory } from './BillingHistory/BillingHistory';
import useInvoices from 'hooks/api/getters/useInvoices/useInvoices'; import useInvoices from 'hooks/api/getters/useInvoices/useInvoices';
export const Billing = () => { export const Billing = () => {
const { instanceStatus, isBilling } = useInstanceStatus(); const {
instanceStatus,
isBilling,
refetchInstanceStatus,
refresh,
loading,
} = useInstanceStatus();
const { invoices } = useInvoices(); const { invoices } = useInvoices();
const { hasAccess } = useContext(AccessContext); const { hasAccess } = useContext(AccessContext);
useEffect(() => {
const hardRefresh = async () => {
await refresh();
refetchInstanceStatus();
};
hardRefresh();
}, [refetchInstanceStatus, refresh]);
return ( return (
<div> <div>
<AdminMenu /> <AdminMenu />
<PageContent header="Billing"> <PageContent header="Billing" isLoading={loading}>
<ConditionallyRender <ConditionallyRender
condition={isBilling} condition={isBilling}
show={ show={

View File

@ -40,7 +40,7 @@ export const BillingInformation: FC<IBillingInformationProps> = ({
return ( return (
<Grid item xs={12} md={5}> <Grid item xs={12} md={5}>
<StyledInfoBox> <StyledInfoBox>
<StyledTitle variant="body1">Billing Information</StyledTitle> <StyledTitle variant="body1">Billing information</StyledTitle>
<ConditionallyRender <ConditionallyRender
condition={inactive} condition={inactive}
show={ show={
@ -54,7 +54,7 @@ export const BillingInformation: FC<IBillingInformationProps> = ({
<StyledInfoLabel> <StyledInfoLabel>
{inactive {inactive
? 'Once we have received your billing information we will upgrade your trial within 1 business day' ? 'Once we have received your billing information we will upgrade your trial within 1 business day'
: 'These changes may take up to 1 business day and they will be visible on your next invoice'} : 'Update your credit card and business information and change which email address we send invoices to'}
</StyledInfoLabel> </StyledInfoLabel>
<StyledDivider /> <StyledDivider />
<StyledInfoLabel> <StyledInfoLabel>

View File

@ -480,7 +480,7 @@ exports[`returns all baseRoutes 1`] = `
}, },
"parent": "/admin", "parent": "/admin",
"path": "/admin-invoices", "path": "/admin-invoices",
"title": "Invoices", "title": "Billing & invoices",
"type": "protected", "type": "protected",
}, },
{ {

View File

@ -518,7 +518,7 @@ export const routes: IRoute[] = [
{ {
path: '/admin-invoices', path: '/admin-invoices',
parent: '/admin', parent: '/admin',
title: 'Invoices', title: 'Billing & invoices',
component: FlaggedBillingRedirect, component: FlaggedBillingRedirect,
type: 'protected', type: 'protected',
menu: { adminSettings: true, isEnterprise: true }, menu: { adminSettings: true, isEnterprise: true },

View File

@ -7,6 +7,7 @@ import { useEffect } from 'react';
export interface IUseInstanceStatusOutput { export interface IUseInstanceStatusOutput {
instanceStatus?: IInstanceStatus; instanceStatus?: IInstanceStatus;
refetchInstanceStatus: () => void; refetchInstanceStatus: () => void;
refresh: () => Promise<void>;
isBilling: boolean; isBilling: boolean;
loading: boolean; loading: boolean;
error?: Error; error?: Error;
@ -33,9 +34,14 @@ export const useInstanceStatus = (): IUseInstanceStatusOutput => {
InstancePlan.TEAM, InstancePlan.TEAM,
]; ];
const refresh = async (): Promise<void> => {
await fetch(formatApiPath('api/instance/refresh'));
};
return { return {
instanceStatus: data, instanceStatus: data,
refetchInstanceStatus: refetch, refetchInstanceStatus: refetch,
refresh,
isBilling: billingPlans.includes(data?.plan ?? InstancePlan.UNKNOWN), isBilling: billingPlans.includes(data?.plan ?? InstancePlan.UNKNOWN),
loading, loading,
error, error,