From 6e76819c2ccee73eb4f687f326a790b44f79beb3 Mon Sep 17 00:00:00 2001 From: Pascal van Leeuwen Date: Tue, 3 Sep 2024 17:06:01 +0100 Subject: [PATCH 1/5] feat: add update for monthly user limit to UI --- app/models/portal/queries.graphqls | 1 + .../view.tsx | 25 +++++++- .../components/AccountForm/AccountForm.tsx | 60 +++++++++++++++---- .../account_.$accountId.update/route.tsx | 25 +++++--- 4 files changed, 90 insertions(+), 21 deletions(-) diff --git a/app/models/portal/queries.graphqls b/app/models/portal/queries.graphqls index 2c97f87cb..216f8e52a 100644 --- a/app/models/portal/queries.graphqls +++ b/app/models/portal/queries.graphqls @@ -50,6 +50,7 @@ query getUserAccount( name planType enterpriseLimit + monthlyUserLimit notifications { notificationType notificationSettings { diff --git a/app/routes/account.$accountId.settings._index/view.tsx b/app/routes/account.$accountId.settings._index/view.tsx index cb4c58c96..439b3169d 100644 --- a/app/routes/account.$accountId.settings._index/view.tsx +++ b/app/routes/account.$accountId.settings._index/view.tsx @@ -12,6 +12,8 @@ import { Link } from "@remix-run/react" import { Identicon } from "~/components/Identicon" import { Account, RoleName } from "~/models/portal/sdk" import { AnalyticActions, AnalyticCategories, trackEvent } from "~/utils/analytics" +import { commify } from "~/utils/formattingUtils" +import { isUnlimitedPlan } from "~/utils/planUtils" type AccountSettingsViewProps = { account: Account @@ -34,12 +36,29 @@ export const AccountSettingsView = ({ account, userRole }: AccountSettingsViewPr A unique image representing your account. + {isUnlimitedPlan(account.planType) && ( + <> + + + Monthly Relay Limit + + {account.monthlyUserLimit === 0 + ? "You have no monthly relay limit. You may set a monthly relay limit in Account Settings." + : `You have a monthly relay limit of ${commify( + account.monthlyUserLimit, + )} relays. Once you hit this limit, your account will stop working until the start of the next calendar month. You may increase this limit in Account Settings.`} + + + + + + )} {userRole !== RoleName.Member && ( <> - Account Name - Modify your account name here. + Account Settings + Modify your account settings here. diff --git a/app/routes/account_.$accountId.update/components/AccountForm/AccountForm.tsx b/app/routes/account_.$accountId.update/components/AccountForm/AccountForm.tsx index e05cf6b06..2452fb40b 100644 --- a/app/routes/account_.$accountId.update/components/AccountForm/AccountForm.tsx +++ b/app/routes/account_.$accountId.update/components/AccountForm/AccountForm.tsx @@ -1,9 +1,11 @@ -import { Button, Divider, Group, Stack, TextInput } from "@mantine/core" +import { Button, Divider, Group, Stack, NumberInput, TextInput } from "@mantine/core" import { Form, NavLink, useParams } from "@remix-run/react" import { useState } from "react" import RouteModal from "~/components/RouteModal" import { Account } from "~/models/portal/sdk" import { AnalyticActions, AnalyticCategories, trackEvent } from "~/utils/analytics" +import { commify } from "~/utils/formattingUtils" +import { isUnlimitedPlan } from "~/utils/planUtils" type AccountFormProps = { account: Account @@ -11,10 +13,20 @@ type AccountFormProps = { onSubmit: (formData: FormData) => void } +function EnableUpdate(name: string, monthlyRelayLimit: number, account: Account) { + return ( + (name !== "" && name !== account.name) || + monthlyRelayLimit !== account.monthlyUserLimit + ) +} + const AccountForm = ({ account, redirectTo, onSubmit }: AccountFormProps) => { const { accountId } = useParams() const closeButtonRedirect = redirectTo ?? `/account/${accountId}/settings` const [name, setName] = useState(account?.name ?? "") + const [monthlyRelayLimit, setMonthlyRelayLimit] = useState( + account?.monthlyUserLimit ?? 0, + ) const handleSubmit: React.FormEventHandler = (event) => { event.preventDefault() @@ -24,15 +36,14 @@ const AccountForm = ({ account, redirectTo, onSubmit }: AccountFormProps) => { return ( - -
- + + { onChange={(e) => setName(e.target.value)} /> - + + {isUnlimitedPlan(account.planType) && ( + <> + + + setMonthlyRelayLimit(Number(value))} + /> + + + + )}