diff --git a/server/server.go b/server/server.go index 482b988..b67c354 100644 --- a/server/server.go +++ b/server/server.go @@ -43,7 +43,6 @@ import ( - MEDIUM: Reservation (UI): Ask for confirmation when removing reservation (deadcade) - MEDIUM: Reservation table delete button: dialog "keep or delete messages?" - LOW: UI: Flickering upgrade banner when logging in -- LOW: JS constants */ diff --git a/web/src/app/AccountApi.js b/web/src/app/AccountApi.js index b879a1a..31df0a8 100644 --- a/web/src/app/AccountApi.js +++ b/web/src/app/AccountApi.js @@ -1,21 +1,23 @@ import { + accountBillingPortalUrl, + accountBillingSubscriptionUrl, + accountPasswordUrl, accountReservationSingleUrl, accountReservationUrl, - accountPasswordUrl, accountSettingsUrl, accountSubscriptionSingleUrl, accountSubscriptionUrl, accountTokenUrl, - accountUrl, maybeWithAuth, topicUrl, + accountUrl, + tiersUrl, withBasicAuth, - withBearerAuth, accountBillingSubscriptionUrl, accountBillingPortalUrl, tiersUrl + withBearerAuth } from "./utils"; import session from "./Session"; import subscriptionManager from "./SubscriptionManager"; import i18n from "i18next"; import prefs from "./Prefs"; import routes from "../components/routes"; -import userManager from "./UserManager"; const delayMillis = 45000; // 45 seconds const intervalMillis = 900000; // 15 minutes @@ -441,6 +443,32 @@ class AccountApi { } } +// Maps to user.Role in user/types.go +export const Role = { + ADMIN: "admin", + USER: "user" +}; + +// Maps to server.visitorLimitBasis in server/visitor.go +export const LimitBasis = { + IP: "ip", + TIER: "tier" +}; + +// Maps to stripe.SubscriptionStatus +export const SubscriptionStatus = { + ACTIVE: "active", + PAST_DUE: "past_due" +}; + +// Maps to user.Permission in user/types.go +export const Permission = { + READ_WRITE: "read-write", + READ_ONLY: "read-only", + WRITE_ONLY: "write-only", + DENY_ALL: "deny-all" +}; + export class UsernameTakenError extends Error { constructor(username) { super("Username taken"); diff --git a/web/src/components/Account.js b/web/src/components/Account.js index 5282a21..7cb6d8d 100644 --- a/web/src/components/Account.js +++ b/web/src/components/Account.js @@ -28,7 +28,13 @@ import TextField from "@mui/material/TextField"; import routes from "./routes"; import IconButton from "@mui/material/IconButton"; import {formatBytes, formatShortDate, formatShortDateTime, openUrl, truncateString, validUrl} from "../app/utils"; -import accountApi, {IncorrectPasswordError, UnauthorizedError} from "../app/AccountApi"; +import accountApi, { + IncorrectPasswordError, + LimitBasis, + Role, + SubscriptionStatus, + UnauthorizedError +} from "../app/AccountApi"; import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; import {Pref, PrefGroup} from "./Pref"; import db from "../app/db"; @@ -92,7 +98,7 @@ const Username = () => {
{session.username()} - {account?.role === "admin" + {account?.role === Role.ADMIN ? <>{" "}👑 : ""}
@@ -237,7 +243,7 @@ const AccountType = () => { }; let accountType; - if (account.role === "admin") { + if (account.role === Role.ADMIN) { const tierSuffix = (account.tier) ? `(with ${account.tier.name} tier)` : `(no tier)`; accountType = `${t("account_usage_tier_admin")} ${tierSuffix}`; } else if (!account.tier) { @@ -248,7 +254,7 @@ const AccountType = () => { return ( 0} + alignTop={account.billing?.status === SubscriptionStatus.PAST_DUE || account.billing?.cancel_at > 0} title={t("account_usage_tier_title")} description={t("account_usage_tier_description")} > @@ -259,7 +265,7 @@ const AccountType = () => { } - {config.enable_payments && account.role === "user" && !account.billing?.subscription && + {config.enable_payments && account.role === Role.USER && !account.billing?.subscription && } - {config.enable_payments && account.role === "user" && account.billing?.subscription && + {config.enable_payments && account.role === Role.USER && account.billing?.subscription && } - {config.enable_payments && account.role === "user" && account.billing?.customer && + {config.enable_payments && account.role === Role.USER && account.billing?.customer &&