/
BillingPlan.tsx
243 lines (230 loc) · 10.3 KB
/
BillingPlan.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import { FC } from 'react';
import { Alert, Divider, Grid, styled, Typography } from '@mui/material';
import { Link } from 'react-router-dom';
import CheckIcon from '@mui/icons-material/Check';
import { useUsers } from 'hooks/api/getters/useUsers/useUsers';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import {
IInstanceStatus,
InstanceState,
InstancePlan,
} from 'interfaces/instance';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { trialHasExpired, isTrialInstance } from 'utils/instanceTrial';
import { GridRow } from 'component/common/GridRow/GridRow';
import { GridCol } from 'component/common/GridCol/GridCol';
import { Badge } from 'component/common/Badge/Badge';
import { GridColLink } from './GridColLink/GridColLink';
const StyledPlanBox = styled('aside')(({ theme }) => ({
padding: theme.spacing(2.5),
height: '100%',
borderRadius: theme.shape.borderRadiusLarge,
boxShadow: theme.boxShadows.elevated,
[theme.breakpoints.up('md')]: {
padding: theme.spacing(6.5),
},
}));
const StyledInfoLabel = styled(Typography)(({ theme }) => ({
fontSize: theme.fontSizes.smallBody,
color: theme.palette.text.secondary,
}));
const StyledPlanSpan = styled('span')(({ theme }) => ({
fontSize: '3.25rem',
lineHeight: 1,
color: theme.palette.primary.main,
fontWeight: 800,
}));
const StyledTrialSpan = styled('span')(({ theme }) => ({
marginLeft: theme.spacing(1.5),
fontWeight: theme.fontWeight.bold,
}));
const StyledPriceSpan = styled('span')(({ theme }) => ({
color: theme.palette.primary.main,
fontSize: theme.fontSizes.mainHeader,
fontWeight: theme.fontWeight.bold,
}));
const StyledAlert = styled(Alert)(({ theme }) => ({
fontSize: theme.fontSizes.smallerBody,
marginBottom: theme.spacing(3),
marginTop: theme.spacing(-1.5),
[theme.breakpoints.up('md')]: {
marginTop: theme.spacing(-4.5),
},
}));
const StyledCheckIcon = styled(CheckIcon)(({ theme }) => ({
fontSize: '1rem',
marginRight: theme.spacing(1),
}));
const StyledDivider = styled(Divider)(({ theme }) => ({
margin: `${theme.spacing(3)} 0`,
}));
interface IBillingPlanProps {
instanceStatus: IInstanceStatus;
}
export const BillingPlan: FC<IBillingPlanProps> = ({ instanceStatus }) => {
const { users } = useUsers();
const expired = trialHasExpired(instanceStatus);
const { uiConfig } = useUiConfig();
const price = {
[InstancePlan.PRO]: 80,
[InstancePlan.COMPANY]: 0,
[InstancePlan.TEAM]: 0,
[InstancePlan.UNKNOWN]: 0,
user: 15,
};
const planPrice = price[instanceStatus.plan];
const seats = instanceStatus.seats ?? 5;
const freeAssigned = Math.min(users.length, seats);
const paidAssigned = users.length - freeAssigned;
const paidAssignedPrice = price.user * paidAssigned;
const finalPrice = planPrice + paidAssignedPrice;
const inactive = instanceStatus.state !== InstanceState.ACTIVE;
return (
<Grid item xs={12} md={7}>
<StyledPlanBox>
<ConditionallyRender
condition={inactive}
show={
<StyledAlert severity="info">
After you have sent your billing information, your
instance will be upgraded - you don't have to do
anything.{' '}
<a href="mailto:elise@getunleash.ai?subject=PRO plan clarifications">
Get in touch with us
</a>{' '}
for any clarification
</StyledAlert>
}
/>
<Badge color="success">Current plan</Badge>
<Grid container>
<GridRow sx={theme => ({ marginBottom: theme.spacing(3) })}>
<GridCol>
<StyledPlanSpan>
{instanceStatus.plan}
</StyledPlanSpan>
<ConditionallyRender
condition={isTrialInstance(instanceStatus)}
show={
<StyledTrialSpan
sx={theme => ({
color: expired
? theme.palette.error.dark
: theme.palette.warning.dark,
})}
>
{expired
? 'Trial expired'
: instanceStatus.trialExtended
? 'Extended Trial'
: 'Trial'}
</StyledTrialSpan>
}
/>
</GridCol>
<GridCol>
<ConditionallyRender
condition={planPrice > 0}
show={
<StyledPriceSpan>
${planPrice.toFixed(2)}
</StyledPriceSpan>
}
/>
</GridCol>
</GridRow>
</Grid>
<ConditionallyRender
condition={Boolean(
uiConfig?.flags?.proPlanAutoCharge &&
instanceStatus.plan === InstancePlan.PRO
)}
show={
<>
<Grid container>
<GridRow
sx={theme => ({
marginBottom: theme.spacing(1.5),
})}
>
<GridCol>
<Typography>
<strong>{seats}</strong> team
members
<GridColLink>
<Link to="/admin/users">
{freeAssigned} assigned
</Link>
</GridColLink>
</Typography>
</GridCol>
<GridCol>
<StyledCheckIcon />
<Typography variant="body2">
included
</Typography>
</GridCol>
</GridRow>
<GridRow>
<GridCol vertical>
<Typography>
Paid members
<GridColLink>
<Link to="/admin/users">
{paidAssigned} assigned
</Link>
</GridColLink>
</Typography>
<StyledInfoLabel>
Add up to 15 extra paid members - $
{price.user}
/month per member
</StyledInfoLabel>
</GridCol>
<GridCol>
<Typography
sx={theme => ({
fontSize:
theme.fontSizes.mainHeader,
})}
>
${paidAssignedPrice.toFixed(2)}
</Typography>
</GridCol>
</GridRow>
</Grid>
<StyledDivider />
<Grid container>
<GridRow>
<GridCol>
<Typography
sx={theme => ({
fontWeight:
theme.fontWeight.bold,
fontSize:
theme.fontSizes.mainHeader,
})}
>
Total per month
</Typography>
</GridCol>
<GridCol>
<Typography
sx={theme => ({
fontWeight:
theme.fontWeight.bold,
fontSize: '2rem',
})}
>
${finalPrice.toFixed(2)}
</Typography>
</GridCol>
</GridRow>
</Grid>
</>
}
/>
</StyledPlanBox>
</Grid>
);
};