2023-01-10 09:40:46 +13:00
|
|
|
import * as React from "react";
|
2023-01-31 07:10:45 +13:00
|
|
|
import { useContext, useEffect, useState } from "react";
|
2023-01-10 09:40:46 +13:00
|
|
|
import Dialog from "@mui/material/Dialog";
|
|
|
|
import DialogContent from "@mui/material/DialogContent";
|
|
|
|
import DialogTitle from "@mui/material/DialogTitle";
|
2023-03-01 08:38:31 +13:00
|
|
|
import { Alert, CardActionArea, CardContent, Chip, Link, ListItem, Switch, useMediaQuery } from "@mui/material";
|
2023-01-10 09:40:46 +13:00
|
|
|
import theme from "./theme";
|
2023-01-15 00:43:44 +13:00
|
|
|
import Button from "@mui/material/Button";
|
2023-02-22 16:44:30 +13:00
|
|
|
import accountApi, { SubscriptionInterval } from "../app/AccountApi";
|
2023-01-15 00:43:44 +13:00
|
|
|
import session from "../app/Session";
|
|
|
|
import routes from "./routes";
|
|
|
|
import Card from "@mui/material/Card";
|
|
|
|
import Typography from "@mui/material/Typography";
|
|
|
|
import { AccountContext } from "./App";
|
2023-02-22 16:44:30 +13:00
|
|
|
import { formatBytes, formatNumber, formatPrice, formatShortDate } from "../app/utils";
|
2023-01-18 13:40:03 +13:00
|
|
|
import { Trans, useTranslation } from "react-i18next";
|
|
|
|
import List from "@mui/material/List";
|
2023-02-22 16:44:30 +13:00
|
|
|
import { Check, Close } from "@mui/icons-material";
|
2023-01-18 13:40:03 +13:00
|
|
|
import ListItemIcon from "@mui/material/ListItemIcon";
|
|
|
|
import ListItemText from "@mui/material/ListItemText";
|
2023-01-18 14:21:19 +13:00
|
|
|
import Box from "@mui/material/Box";
|
2023-01-21 16:47:37 +13:00
|
|
|
import { NavLink } from "react-router-dom";
|
2023-02-03 09:19:37 +13:00
|
|
|
import { UnauthorizedError } from "../app/errors";
|
2023-03-01 08:38:31 +13:00
|
|
|
import DialogContentText from "@mui/material/DialogContentText";
|
|
|
|
import DialogActions from "@mui/material/DialogActions";
|
2023-01-10 09:40:46 +13:00
|
|
|
|
|
|
|
const UpgradeDialog = (props) => {
|
2023-01-17 10:35:37 +13:00
|
|
|
const { t } = useTranslation();
|
2023-01-19 07:46:40 +13:00
|
|
|
const { account } = useContext(AccountContext); // May be undefined!
|
2023-02-03 09:19:37 +13:00
|
|
|
const [error, setError] = useState("");
|
2023-01-18 04:09:37 +13:00
|
|
|
const [tiers, setTiers] = useState(null);
|
2023-02-22 16:44:30 +13:00
|
|
|
const [interval, setInterval] = useState(account?.billing?.interval || SubscriptionInterval.YEAR);
|
2023-01-21 16:47:37 +13:00
|
|
|
const [newTierCode, setNewTierCode] = useState(account?.tier?.code); // May be undefined
|
2023-01-18 14:21:19 +13:00
|
|
|
const [loading, setLoading] = useState(false);
|
2023-02-03 09:19:37 +13:00
|
|
|
const fullScreen = useMediaQuery(theme.breakpoints.down("sm"));
|
2023-01-10 09:40:46 +13:00
|
|
|
|
2023-01-18 04:09:37 +13:00
|
|
|
useEffect(() => {
|
2023-02-12 14:38:13 +13:00
|
|
|
const fetchTiers = async () => {
|
|
|
|
setTiers(await accountApi.billingTiers());
|
|
|
|
};
|
|
|
|
fetchTiers(); // Dangle
|
2023-01-18 04:09:37 +13:00
|
|
|
}, []);
|
|
|
|
|
2023-01-19 07:46:40 +13:00
|
|
|
if (!tiers) {
|
2023-01-17 10:35:37 +13:00
|
|
|
return <></>;
|
|
|
|
}
|
|
|
|
|
2023-01-21 16:47:37 +13:00
|
|
|
const tiersMap = Object.assign(...tiers.map((tier) => ({ [tier.code]: tier })));
|
|
|
|
const newTier = tiersMap[newTierCode]; // May be undefined
|
|
|
|
const currentTier = account?.tier; // May be undefined
|
2023-02-22 16:44:30 +13:00
|
|
|
const currentInterval = account?.billing?.interval; // May be undefined
|
2023-01-21 16:47:37 +13:00
|
|
|
const currentTierCode = currentTier?.code; // May be undefined
|
|
|
|
|
|
|
|
// Figure out buttons, labels and the submit action
|
|
|
|
let submitAction, submitButtonLabel, banner;
|
2023-01-19 07:46:40 +13:00
|
|
|
if (!account) {
|
|
|
|
submitButtonLabel = t("account_upgrade_dialog_button_redirect_signup");
|
2023-01-21 16:47:37 +13:00
|
|
|
submitAction = Action.REDIRECT_SIGNUP;
|
|
|
|
banner = null;
|
2023-02-26 16:24:04 +13:00
|
|
|
} else if (currentTierCode === newTierCode && (currentInterval === undefined || currentInterval === interval)) {
|
2023-01-18 13:40:03 +13:00
|
|
|
submitButtonLabel = t("account_upgrade_dialog_button_update_subscription");
|
2023-01-21 16:47:37 +13:00
|
|
|
submitAction = null;
|
|
|
|
banner = currentTierCode ? Banner.PRORATION_INFO : null;
|
|
|
|
} else if (!currentTierCode) {
|
2023-01-18 13:40:03 +13:00
|
|
|
submitButtonLabel = t("account_upgrade_dialog_button_pay_now");
|
2023-01-21 16:47:37 +13:00
|
|
|
submitAction = Action.CREATE_SUBSCRIPTION;
|
|
|
|
banner = null;
|
|
|
|
} else if (!newTierCode) {
|
2023-01-18 13:40:03 +13:00
|
|
|
submitButtonLabel = t("account_upgrade_dialog_button_cancel_subscription");
|
2023-01-21 16:47:37 +13:00
|
|
|
submitAction = Action.CANCEL_SUBSCRIPTION;
|
|
|
|
banner = Banner.CANCEL_WARNING;
|
2023-01-17 10:35:37 +13:00
|
|
|
} else {
|
2023-01-18 13:40:03 +13:00
|
|
|
submitButtonLabel = t("account_upgrade_dialog_button_update_subscription");
|
2023-01-21 16:47:37 +13:00
|
|
|
submitAction = Action.UPDATE_SUBSCRIPTION;
|
|
|
|
banner = Banner.PRORATION_INFO;
|
2023-01-17 10:35:37 +13:00
|
|
|
}
|
|
|
|
|
2023-01-21 16:47:37 +13:00
|
|
|
// Exceptional conditions
|
2023-01-18 14:21:19 +13:00
|
|
|
if (loading) {
|
2023-01-21 16:47:37 +13:00
|
|
|
submitAction = null;
|
2023-01-22 02:55:31 +13:00
|
|
|
} else if (newTier?.code && account?.reservations?.length > newTier?.limits?.reservations) {
|
2023-01-21 16:47:37 +13:00
|
|
|
submitAction = null;
|
|
|
|
banner = Banner.RESERVATIONS_WARNING;
|
2023-01-18 14:21:19 +13:00
|
|
|
}
|
|
|
|
|
2023-01-17 10:35:37 +13:00
|
|
|
const handleSubmit = async () => {
|
2023-01-21 16:47:37 +13:00
|
|
|
if (submitAction === Action.REDIRECT_SIGNUP) {
|
2023-01-17 10:35:37 +13:00
|
|
|
window.location.href = routes.signup;
|
2023-01-15 00:43:44 +13:00
|
|
|
return;
|
2023-01-10 09:40:46 +13:00
|
|
|
}
|
2023-05-24 07:13:01 +12:00
|
|
|
try {
|
2023-01-18 14:21:19 +13:00
|
|
|
setLoading(true);
|
2023-01-21 16:47:37 +13:00
|
|
|
if (submitAction === Action.CREATE_SUBSCRIPTION) {
|
2023-02-22 16:44:30 +13:00
|
|
|
const response = await accountApi.createBillingSubscription(newTierCode, interval);
|
2023-01-19 07:46:40 +13:00
|
|
|
window.location.href = response.redirect_url;
|
2023-01-21 16:47:37 +13:00
|
|
|
} else if (submitAction === Action.UPDATE_SUBSCRIPTION) {
|
2023-02-22 16:44:30 +13:00
|
|
|
await accountApi.updateBillingSubscription(newTierCode, interval);
|
2023-01-21 16:47:37 +13:00
|
|
|
} else if (submitAction === Action.CANCEL_SUBSCRIPTION) {
|
2023-01-16 17:29:46 +13:00
|
|
|
await accountApi.deleteBillingSubscription();
|
2023-05-24 07:13:01 +12:00
|
|
|
}
|
2023-01-17 10:35:37 +13:00
|
|
|
props.onCancel();
|
2023-01-15 00:43:44 +13:00
|
|
|
} catch (e) {
|
2023-01-17 10:35:37 +13:00
|
|
|
console.log(`[UpgradeDialog] Error changing billing subscription`, e);
|
2023-02-03 09:19:37 +13:00
|
|
|
if (e instanceof UnauthorizedError) {
|
2023-01-15 00:43:44 +13:00
|
|
|
session.resetAndRedirect(routes.login);
|
2023-05-24 07:13:01 +12:00
|
|
|
} else {
|
2023-02-03 09:19:37 +13:00
|
|
|
setError(e.message);
|
2023-05-24 07:13:01 +12:00
|
|
|
}
|
2023-01-18 14:21:19 +13:00
|
|
|
} finally {
|
|
|
|
setLoading(false);
|
2023-05-24 07:13:01 +12:00
|
|
|
}
|
|
|
|
};
|
2023-01-10 09:40:46 +13:00
|
|
|
|
2023-02-22 16:44:30 +13:00
|
|
|
// Figure out discount
|
2023-02-23 08:21:23 +13:00
|
|
|
let discount = 0,
|
|
|
|
upto = false;
|
2023-02-22 16:44:30 +13:00
|
|
|
if (newTier?.prices) {
|
|
|
|
discount = Math.round(((newTier.prices.month * 12) / newTier.prices.year - 1) * 100);
|
|
|
|
} else {
|
2023-02-23 08:21:23 +13:00
|
|
|
let n = 0;
|
2023-02-22 16:44:30 +13:00
|
|
|
for (const t of tiers) {
|
|
|
|
if (t.prices) {
|
2023-02-23 08:21:23 +13:00
|
|
|
const tierDiscount = Math.round(((t.prices.month * 12) / t.prices.year - 1) * 100);
|
|
|
|
if (tierDiscount > discount) {
|
|
|
|
discount = tierDiscount;
|
|
|
|
n++;
|
2023-02-22 16:44:30 +13:00
|
|
|
}
|
2023-05-24 07:13:01 +12:00
|
|
|
}
|
2023-02-22 16:44:30 +13:00
|
|
|
}
|
2023-02-23 08:21:23 +13:00
|
|
|
upto = n > 1;
|
2023-05-24 07:13:01 +12:00
|
|
|
}
|
2023-02-22 16:44:30 +13:00
|
|
|
|
2023-01-10 09:40:46 +13:00
|
|
|
return (
|
2023-01-18 13:40:03 +13:00
|
|
|
<Dialog open={props.open} onClose={props.onCancel} maxWidth="lg" fullScreen={fullScreen}>
|
2023-02-22 16:44:30 +13:00
|
|
|
<DialogTitle>
|
|
|
|
<div style={{ display: "flex", flexDirection: "row" }}>
|
|
|
|
<div style={{ flexGrow: 1 }}>{t("account_upgrade_dialog_title")}</div>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "row",
|
|
|
|
alignItems: "center",
|
|
|
|
marginTop: "4px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Typography component="span" variant="subtitle1">
|
2023-02-23 08:21:23 +13:00
|
|
|
{t("account_upgrade_dialog_interval_monthly")}
|
|
|
|
</Typography>
|
2023-05-24 07:13:01 +12:00
|
|
|
<Switch
|
2023-02-23 08:21:23 +13:00
|
|
|
checked={interval === SubscriptionInterval.YEAR}
|
|
|
|
onChange={(ev) => setInterval(ev.target.checked ? SubscriptionInterval.YEAR : SubscriptionInterval.MONTH)}
|
2023-01-18 04:09:37 +13:00
|
|
|
/>
|
2023-02-22 16:44:30 +13:00
|
|
|
<Typography component="span" variant="subtitle1">
|
|
|
|
{t("account_upgrade_dialog_interval_yearly")}
|
|
|
|
</Typography>
|
|
|
|
{discount > 0 && (
|
2023-05-24 07:13:01 +12:00
|
|
|
<Chip
|
2023-02-22 16:44:30 +13:00
|
|
|
label={
|
2023-05-24 07:13:01 +12:00
|
|
|
upto
|
2023-02-22 16:44:30 +13:00
|
|
|
? t("account_upgrade_dialog_interval_yearly_discount_save_up_to", { discount: discount })
|
2023-01-18 13:40:03 +13:00
|
|
|
: t("account_upgrade_dialog_interval_yearly_discount_save", { discount: discount })
|
2023-01-18 04:09:37 +13:00
|
|
|
}
|
2023-02-23 08:21:23 +13:00
|
|
|
color="primary"
|
|
|
|
size="small"
|
2023-01-21 16:47:37 +13:00
|
|
|
variant={interval === SubscriptionInterval.YEAR ? "filled" : "outlined"}
|
2023-02-23 08:21:23 +13:00
|
|
|
sx={{ marginLeft: "5px" }}
|
2023-05-24 07:13:01 +12:00
|
|
|
/>
|
|
|
|
)}
|
2023-01-10 09:40:46 +13:00
|
|
|
</div>
|
2023-05-24 07:13:01 +12:00
|
|
|
</div>
|
2023-02-22 16:44:30 +13:00
|
|
|
</DialogTitle>
|
2023-01-10 09:40:46 +13:00
|
|
|
<DialogContent>
|
2023-03-01 08:38:31 +13:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "row",
|
|
|
|
marginBottom: "8px",
|
2023-01-18 04:09:37 +13:00
|
|
|
width: "100%",
|
2023-05-24 07:13:01 +12:00
|
|
|
}}
|
|
|
|
>
|
2023-01-18 04:09:37 +13:00
|
|
|
{tiers.map((tier) => (
|
|
|
|
<TierCard
|
2023-01-18 13:40:03 +13:00
|
|
|
key={`tierCard${tier.code || "_free"}`}
|
|
|
|
tier={tier}
|
2023-01-21 16:47:37 +13:00
|
|
|
current={currentTierCode === tier.code} // tier.code or currentTierCode may be undefined!
|
|
|
|
selected={newTierCode === tier.code} // tier.code may be undefined!
|
2023-02-22 16:44:30 +13:00
|
|
|
interval={interval}
|
2023-01-21 16:47:37 +13:00
|
|
|
onClick={() => setNewTierCode(tier.code)} // tier.code may be undefined!
|
2023-05-24 07:13:01 +12:00
|
|
|
/>
|
|
|
|
))}
|
2023-03-01 08:38:31 +13:00
|
|
|
</div>
|
|
|
|
{banner === Banner.CANCEL_WARNING && (
|
|
|
|
<Alert severity="warning" sx={{ fontSize: "1rem" }}>
|
2023-05-24 07:13:01 +12:00
|
|
|
<Trans
|
2023-01-21 16:47:37 +13:00
|
|
|
i18nKey="account_upgrade_dialog_cancel_warning"
|
2023-05-24 07:13:01 +12:00
|
|
|
values={{
|
2023-01-19 07:46:40 +13:00
|
|
|
date: formatShortDate(account?.billing?.paid_until || 0),
|
2023-05-24 07:13:01 +12:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Alert>
|
|
|
|
)}
|
2023-01-21 16:47:37 +13:00
|
|
|
{banner === Banner.PRORATION_INFO && (
|
2023-03-01 08:38:31 +13:00
|
|
|
<Alert severity="info" sx={{ fontSize: "1rem" }}>
|
2023-01-18 13:40:03 +13:00
|
|
|
<Trans i18nKey="account_upgrade_dialog_proration_info" />
|
2023-05-24 07:13:01 +12:00
|
|
|
</Alert>
|
|
|
|
)}
|
2023-01-21 16:47:37 +13:00
|
|
|
{banner === Banner.RESERVATIONS_WARNING && (
|
2023-02-22 16:44:30 +13:00
|
|
|
<Alert severity="warning" sx={{ fontSize: "1rem" }}>
|
2023-05-24 07:13:01 +12:00
|
|
|
<Trans
|
2023-01-21 16:47:37 +13:00
|
|
|
i18nKey="account_upgrade_dialog_reservations_warning"
|
|
|
|
count={account?.reservations.length - newTier?.limits.reservations}
|
|
|
|
components={{
|
2023-03-01 08:38:31 +13:00
|
|
|
Link: <NavLink to={routes.settings} />,
|
2023-05-24 07:13:01 +12:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Alert>
|
|
|
|
)}
|
2023-03-01 08:38:31 +13:00
|
|
|
</DialogContent>
|
2023-05-24 07:13:01 +12:00
|
|
|
<Box
|
|
|
|
sx={{
|
2023-03-01 08:38:31 +13:00
|
|
|
display: "flex",
|
2023-01-18 04:09:37 +13:00
|
|
|
flexDirection: "row",
|
2023-03-01 08:38:31 +13:00
|
|
|
justifyContent: "space-between",
|
|
|
|
paddingLeft: "24px",
|
2023-01-18 04:09:37 +13:00
|
|
|
paddingBottom: "8px",
|
2023-05-24 07:13:01 +12:00
|
|
|
}}
|
|
|
|
>
|
2023-03-01 08:38:31 +13:00
|
|
|
<DialogContentText
|
|
|
|
component="div"
|
|
|
|
aria-live="polite"
|
|
|
|
sx={{
|
|
|
|
margin: "0px",
|
|
|
|
paddingTop: "12px",
|
|
|
|
paddingBottom: "4px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{config.billing_contact.indexOf("@") !== -1 && (
|
|
|
|
<>
|
|
|
|
<Trans
|
|
|
|
i18nKey="account_upgrade_dialog_billing_contact_email"
|
|
|
|
components={{
|
|
|
|
Link: <Link href={`mailto:${config.billing_contact}`} />,
|
|
|
|
}}
|
|
|
|
/>{" "}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{config.billing_contact.match(`^http?s://`) && (
|
|
|
|
<>
|
|
|
|
<Trans
|
|
|
|
i18nKey="account_upgrade_dialog_billing_contact_website"
|
|
|
|
components={{
|
|
|
|
Link: <Link href={config.billing_contact} target="_blank" />,
|
|
|
|
}}
|
|
|
|
/>{" "}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{error}
|
|
|
|
</DialogContentText>
|
|
|
|
<DialogActions sx={{ paddingRight: 2 }}>
|
|
|
|
<Button onClick={props.onCancel}>{t("account_upgrade_dialog_button_cancel")}</Button>
|
|
|
|
<Button onClick={handleSubmit} disabled={!submitAction}>
|
|
|
|
{submitButtonLabel}
|
2023-05-24 07:13:01 +12:00
|
|
|
</Button>
|
2023-03-01 08:38:31 +13:00
|
|
|
</DialogActions>
|
|
|
|
</Box>
|
2023-01-10 09:40:46 +13:00
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-01-15 00:43:44 +13:00
|
|
|
const TierCard = (props) => {
|
2023-01-18 13:40:03 +13:00
|
|
|
const { t } = useTranslation();
|
|
|
|
const tier = props.tier;
|
2023-02-22 16:44:30 +13:00
|
|
|
|
2023-01-21 16:47:37 +13:00
|
|
|
let cardStyle, labelStyle, labelText;
|
|
|
|
if (props.selected) {
|
2023-02-22 16:44:30 +13:00
|
|
|
cardStyle = { background: "#eee", border: "3px solid #338574" };
|
2023-01-21 16:47:37 +13:00
|
|
|
labelStyle = { background: "#338574", color: "white" };
|
|
|
|
labelText = t("account_upgrade_dialog_tier_selected_label");
|
|
|
|
} else if (props.current) {
|
2023-02-22 16:44:30 +13:00
|
|
|
cardStyle = { border: "3px solid #eee" };
|
2023-01-21 16:47:37 +13:00
|
|
|
labelStyle = { background: "#eee", color: "black" };
|
|
|
|
labelText = t("account_upgrade_dialog_tier_current_label");
|
|
|
|
} else {
|
2023-02-22 16:44:30 +13:00
|
|
|
cardStyle = { border: "3px solid transparent" };
|
|
|
|
}
|
|
|
|
|
|
|
|
let monthlyPrice;
|
|
|
|
if (!tier.prices) {
|
2023-01-19 07:46:40 +13:00
|
|
|
monthlyPrice = 0;
|
2023-01-18 14:21:19 +13:00
|
|
|
} else if (props.interval === SubscriptionInterval.YEAR) {
|
2023-02-22 16:44:30 +13:00
|
|
|
monthlyPrice = tier.prices.year / 12;
|
|
|
|
} else if (props.interval === SubscriptionInterval.MONTH) {
|
|
|
|
monthlyPrice = tier.prices.month;
|
2023-01-18 14:21:19 +13:00
|
|
|
}
|
|
|
|
|
2023-05-24 07:13:01 +12:00
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
sx={{
|
2023-01-18 14:21:19 +13:00
|
|
|
m: "7px",
|
2023-02-22 16:44:30 +13:00
|
|
|
minWidth: "240px",
|
2023-01-18 13:40:03 +13:00
|
|
|
flexGrow: 1,
|
|
|
|
flexShrink: 1,
|
|
|
|
flexBasis: 0,
|
2023-02-22 16:44:30 +13:00
|
|
|
borderRadius: "5px",
|
2023-01-19 07:46:40 +13:00
|
|
|
"&:first-of-type": { ml: 0 },
|
|
|
|
"&:last-of-type": { mr: 0 },
|
2023-01-18 04:09:37 +13:00
|
|
|
...cardStyle,
|
2023-05-24 07:13:01 +12:00
|
|
|
}}
|
|
|
|
>
|
2023-01-18 14:21:19 +13:00
|
|
|
<Card sx={{ height: "100%" }}>
|
|
|
|
<CardActionArea sx={{ height: "100%" }}>
|
|
|
|
<CardContent onClick={props.onClick} sx={{ height: "100%" }}>
|
2023-01-21 16:47:37 +13:00
|
|
|
{labelStyle && (
|
2023-05-24 07:13:01 +12:00
|
|
|
<div
|
|
|
|
style={{
|
2023-01-18 14:21:19 +13:00
|
|
|
position: "absolute",
|
|
|
|
top: "0",
|
|
|
|
right: "15px",
|
|
|
|
padding: "2px 10px",
|
|
|
|
borderRadius: "3px",
|
2023-01-21 16:47:37 +13:00
|
|
|
...labelStyle,
|
2023-05-24 07:13:01 +12:00
|
|
|
}}
|
|
|
|
>
|
2023-01-21 16:47:37 +13:00
|
|
|
{labelText}
|
2023-05-24 07:13:01 +12:00
|
|
|
</div>
|
|
|
|
)}
|
2023-02-22 16:44:30 +13:00
|
|
|
<Typography variant="subtitle1" component="div">
|
2023-02-10 09:24:12 +13:00
|
|
|
{tier.name || t("account_basics_tier_free")}
|
2023-01-18 13:40:03 +13:00
|
|
|
</Typography>
|
2023-05-24 07:13:01 +12:00
|
|
|
<div>
|
2023-02-22 16:44:30 +13:00
|
|
|
<Typography component="span" variant="h4" sx={{ fontWeight: 500, marginRight: "3px" }}>
|
|
|
|
{formatPrice(monthlyPrice)}
|
2023-01-18 13:40:03 +13:00
|
|
|
</Typography>
|
2023-02-22 16:44:30 +13:00
|
|
|
{monthlyPrice > 0 && <>/ {t("account_upgrade_dialog_tier_price_per_month")}</>}
|
2023-05-24 07:13:01 +12:00
|
|
|
</div>
|
2023-01-18 14:21:19 +13:00
|
|
|
<List dense>
|
2023-03-21 20:49:02 +13:00
|
|
|
{tier.limits.reservations > 0 && (
|
2023-02-22 16:44:30 +13:00
|
|
|
<Feature>
|
2023-03-21 20:49:02 +13:00
|
|
|
{t("account_upgrade_dialog_tier_features_reservations", {
|
|
|
|
reservations: tier.limits.reservations,
|
|
|
|
count: tier.limits.reservations,
|
2023-05-24 07:13:01 +12:00
|
|
|
})}
|
2023-02-22 16:44:30 +13:00
|
|
|
</Feature>
|
2023-05-24 07:13:01 +12:00
|
|
|
)}
|
2023-02-22 16:44:30 +13:00
|
|
|
<Feature>
|
2023-03-21 20:49:02 +13:00
|
|
|
{t("account_upgrade_dialog_tier_features_messages", {
|
|
|
|
messages: formatNumber(tier.limits.messages),
|
|
|
|
count: tier.limits.messages,
|
2023-05-24 07:13:01 +12:00
|
|
|
})}
|
2023-02-22 16:44:30 +13:00
|
|
|
</Feature>
|
|
|
|
<Feature>
|
2023-03-21 20:49:02 +13:00
|
|
|
{t("account_upgrade_dialog_tier_features_emails", {
|
|
|
|
emails: formatNumber(tier.limits.emails),
|
|
|
|
count: tier.limits.emails,
|
2023-05-24 07:13:01 +12:00
|
|
|
})}
|
2023-02-22 16:44:30 +13:00
|
|
|
</Feature>
|
2023-05-08 14:28:07 +12:00
|
|
|
{tier.limits.calls > 0 && (
|
2023-02-22 16:44:30 +13:00
|
|
|
<Feature>
|
2023-05-08 14:28:07 +12:00
|
|
|
{t("account_upgrade_dialog_tier_features_calls", {
|
|
|
|
calls: formatNumber(tier.limits.calls),
|
|
|
|
count: tier.limits.calls,
|
2023-05-24 07:13:01 +12:00
|
|
|
})}
|
2023-02-22 16:44:30 +13:00
|
|
|
</Feature>
|
2023-05-24 07:13:01 +12:00
|
|
|
)}
|
2023-02-22 16:44:30 +13:00
|
|
|
<Feature>
|
|
|
|
{t("account_upgrade_dialog_tier_features_attachment_file_size", {
|
|
|
|
filesize: formatBytes(tier.limits.attachment_file_size, 0),
|
|
|
|
})}
|
|
|
|
</Feature>
|
2023-05-08 14:28:07 +12:00
|
|
|
{tier.limits.reservations === 0 && <NoFeature>{t("account_upgrade_dialog_tier_features_no_reservations")}</NoFeature>}
|
|
|
|
{tier.limits.calls === 0 && <NoFeature>{t("account_upgrade_dialog_tier_features_no_calls")}</NoFeature>}
|
2023-05-24 07:13:01 +12:00
|
|
|
</List>
|
2023-02-22 16:44:30 +13:00
|
|
|
{tier.prices && props.interval === SubscriptionInterval.MONTH && (
|
|
|
|
<Typography variant="body2" color="gray">
|
|
|
|
{t("account_upgrade_dialog_tier_price_billed_monthly", {
|
|
|
|
price: formatPrice(tier.prices.month * 12),
|
2023-05-24 07:13:01 +12:00
|
|
|
})}
|
2023-01-18 13:40:03 +13:00
|
|
|
</Typography>
|
2023-05-24 07:13:01 +12:00
|
|
|
)}
|
2023-02-22 16:44:30 +13:00
|
|
|
{tier.prices && props.interval === SubscriptionInterval.YEAR && (
|
|
|
|
<Typography variant="body2" color="gray">
|
|
|
|
{t("account_upgrade_dialog_tier_price_billed_yearly", {
|
|
|
|
price: formatPrice(tier.prices.year),
|
|
|
|
save: formatPrice(tier.prices.month * 12 - tier.prices.year),
|
2023-05-24 07:13:01 +12:00
|
|
|
})}
|
2023-01-18 13:40:03 +13:00
|
|
|
</Typography>
|
2023-05-24 07:13:01 +12:00
|
|
|
)}
|
2023-01-18 14:21:19 +13:00
|
|
|
</CardContent>
|
|
|
|
</CardActionArea>
|
2023-05-24 07:13:01 +12:00
|
|
|
</Card>
|
|
|
|
</Box>
|
2023-01-15 00:43:44 +13:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-02-22 16:44:30 +13:00
|
|
|
const Feature = (props) => {
|
|
|
|
return <FeatureItem feature={true}>{props.children}</FeatureItem>;
|
|
|
|
};
|
|
|
|
|
|
|
|
const NoFeature = (props) => {
|
|
|
|
return <FeatureItem feature={false}>{props.children}</FeatureItem>;
|
|
|
|
};
|
|
|
|
|
2023-01-18 13:40:03 +13:00
|
|
|
const FeatureItem = (props) => {
|
|
|
|
return (
|
|
|
|
<ListItem disableGutters sx={{ m: 0, p: 0 }}>
|
|
|
|
<ListItemIcon sx={{ minWidth: "24px" }}>
|
2023-02-22 16:44:30 +13:00
|
|
|
{props.feature && <Check fontSize="small" sx={{ color: "#338574" }} />}
|
|
|
|
{!props.feature && <Close fontSize="small" sx={{ color: "gray" }} />}
|
2023-01-18 13:40:03 +13:00
|
|
|
</ListItemIcon>
|
2023-02-22 16:44:30 +13:00
|
|
|
<ListItemText sx={{ mt: "2px", mb: "2px" }} primary={<Typography variant="body1">{props.children}</Typography>} />
|
2023-01-18 13:40:03 +13:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-01-17 10:35:37 +13:00
|
|
|
const Action = {
|
2023-01-21 16:47:37 +13:00
|
|
|
REDIRECT_SIGNUP: 1,
|
|
|
|
CREATE_SUBSCRIPTION: 2,
|
|
|
|
UPDATE_SUBSCRIPTION: 3,
|
|
|
|
CANCEL_SUBSCRIPTION: 4,
|
2023-01-17 10:35:37 +13:00
|
|
|
};
|
|
|
|
|
2023-01-21 16:47:37 +13:00
|
|
|
const Banner = {
|
|
|
|
CANCEL_WARNING: 1,
|
|
|
|
PRORATION_INFO: 2,
|
|
|
|
RESERVATIONS_WARNING: 3,
|
|
|
|
};
|
|
|
|
|
2023-01-10 09:40:46 +13:00
|
|
|
export default UpgradeDialog;
|