Skip to content

Commit df8b2f6

Browse files
committed
Fix enum lint warning in dashboard (#5234)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR refactors the code to replace the usage of `AccountStatus` and `AccountPlan` enums with `accountStatus` and `accountPlan` constants, improving consistency and clarity throughout the codebase. ### Detailed summary - Replaced `AccountStatus` enum with `accountStatus` constant object. - Replaced `AccountPlan` enum with `accountPlan` constant object. - Updated all references to use `accountStatus` and `accountPlan` instead of enums. - Adjusted conditions and logic to align with the new structure. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 950ce60 commit df8b2f6

File tree

24 files changed

+133
-129
lines changed

24 files changed

+133
-129
lines changed

apps/dashboard/src/@3rdweb-sdk/react/hooks/useApi.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@ import { useLoggedInUser } from "./useLoggedInUser";
1212

1313
// FIXME: We keep repeating types, API server should provide them
1414

15-
export enum AccountStatus {
16-
NoCustomer = "noCustomer",
17-
NoPayment = "noPayment",
18-
PaymentVerification = "paymentVerification",
19-
ValidPayment = "validPayment",
20-
InvalidPayment = "invalidPayment",
21-
InvalidPaymentMethod = "invalidPaymentMethod",
22-
}
23-
24-
export enum AccountPlan {
25-
Free = "free",
26-
Growth = "growth",
27-
Pro = "pro",
28-
Enterprise = "enterprise",
29-
}
15+
export const accountStatus = {
16+
noCustomer: "noCustomer",
17+
noPayment: "noPayment",
18+
paymentVerification: "paymentVerification",
19+
validPayment: "validPayment",
20+
invalidPayment: "invalidPayment",
21+
invalidPaymentMethod: "invalidPaymentMethod",
22+
} as const;
23+
24+
export const accountPlan = {
25+
free: "free",
26+
growth: "growth",
27+
pro: "pro",
28+
enterprise: "enterprise",
29+
} as const;
30+
31+
export type AccountStatus = (typeof accountStatus)[keyof typeof accountStatus];
32+
export type AccountPlan = (typeof accountPlan)[keyof typeof accountPlan];
3033

3134
export type AuthorizedWallet = {
3235
id: string;

apps/dashboard/src/app/(dashboard)/dashboard/connect/account-abstraction/[clientId]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AccountStatus } from "@3rdweb-sdk/react/hooks/useApi";
1+
import { accountStatus } from "@3rdweb-sdk/react/hooks/useApi";
22
import { SmartWalletsBillingAlert } from "components/settings/ApiKeys/Alerts";
33
import { ConnectSDKCard } from "components/shared/ConnectSDKCard";
44
import { SmartWallets } from "components/smart-wallets";
@@ -38,7 +38,7 @@ export default async function Page(props: {
3838
const hasSmartWalletsWithoutBilling = apiKeys.find((k) =>
3939
k.services?.find(
4040
(s) =>
41-
dashboardAccount.status !== AccountStatus.ValidPayment &&
41+
dashboardAccount.status !== accountStatus.validPayment &&
4242
s.name === "bundler",
4343
),
4444
);

apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/create/components/client/create-ecosystem-form.client.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Input } from "@/components/ui/input";
1616
import { RadioGroup, RadioGroupItemButton } from "@/components/ui/radio-group";
1717
import { ToolTipLabel } from "@/components/ui/tooltip";
1818
import { useDashboardRouter } from "@/lib/DashboardRouter";
19-
import { AccountStatus, useAccount } from "@3rdweb-sdk/react/hooks/useApi";
19+
import { accountStatus, useAccount } from "@3rdweb-sdk/react/hooks/useApi";
2020
import { zodResolver } from "@hookform/resolvers/zod";
2121
import { Loader2 } from "lucide-react";
2222
import Link from "next/link";
@@ -164,7 +164,7 @@ export function CreateEcosystemForm(props: {
164164
)}
165165
/>
166166
</div>
167-
{billingAccountInfo?.status !== AccountStatus.ValidPayment ? (
167+
{billingAccountInfo?.status !== accountStatus.validPayment ? (
168168
<ToolTipLabel label="Please update your payment method to create an ecosystem">
169169
{/* Allows the button to be disabled but the tooltip still works */}
170170
<div className="w-full">

apps/dashboard/src/app/team/[team_slug]/(team)/~/settings/billing/BillingSettingsPage.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
"use client";
22

33
import { Spinner } from "@/components/ui/Spinner/Spinner";
4-
import { AccountStatus, useAccount } from "@3rdweb-sdk/react/hooks/useApi";
4+
import { accountStatus, useAccount } from "@3rdweb-sdk/react/hooks/useApi";
55
import { Billing } from "components/settings/Account/Billing";
66

77
export const SettingsBillingPage = (props: {
88
teamId: string | undefined;
99
}) => {
1010
const meQuery = useAccount({
11-
refetchInterval: (query) =>
12-
[
13-
AccountStatus.InvalidPayment,
14-
AccountStatus.InvalidPaymentMethod,
15-
].includes(query.state?.status as AccountStatus)
16-
? 1000
17-
: false,
11+
refetchInterval: (query) => {
12+
const status = query.state?.status as string;
13+
const isInvalidPayment =
14+
status === accountStatus.invalidPayment ||
15+
status === accountStatus.invalidPaymentMethod;
16+
17+
return isInvalidPayment ? 1000 : false;
18+
},
1819
});
1920

2021
const { data: account } = meQuery;

apps/dashboard/src/app/team/[team_slug]/[project_slug]/connect/account-abstraction/AccountAbstractionPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Spinner } from "@/components/ui/Spinner/Spinner";
44
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
55
import { TrackedLinkTW } from "@/components/ui/tracked-link";
66
import {
7-
AccountStatus,
87
type ApiKeyService,
8+
accountStatus,
99
useAccount,
1010
} from "@3rdweb-sdk/react/hooks/useApi";
1111
import { useLoggedInUser } from "@3rdweb-sdk/react/hooks/useLoggedInUser";
@@ -40,7 +40,7 @@ export function AccountAbstractionPage(props: {
4040

4141
return apiKeyServices.find(
4242
(s) =>
43-
accountQuery.data.status !== AccountStatus.ValidPayment &&
43+
accountQuery.data.status !== accountStatus.validPayment &&
4444
s.name === "bundler",
4545
);
4646
}, [apiKeyServices, accountQuery.data]);

apps/dashboard/src/components/engine/create/CreateEnginePage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { useDashboardRouter } from "@/lib/DashboardRouter";
4-
import { AccountStatus, useAccount } from "@3rdweb-sdk/react/hooks/useApi";
4+
import { accountStatus, useAccount } from "@3rdweb-sdk/react/hooks/useApi";
55
import { useState } from "react";
66
import { toast } from "sonner";
77
import { ConfirmEngineTierDialog } from "../../../components/engine/create/ConfirmEngineTierDialog";
@@ -79,7 +79,7 @@ export const CreateEnginePage = () => {
7979
setIsConfirmationDialogOpen(false);
8080

8181
// If Payment is already setup, deploy the Engine
82-
if (accountQuery.data?.status === AccountStatus.ValidPayment) {
82+
if (accountQuery.data?.status === accountStatus.validPayment) {
8383
await createEngineInstance(selectedTier);
8484
} else {
8585
trackEvent({

apps/dashboard/src/components/homepage/sections/PricingCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AccountPlan } from "@3rdweb-sdk/react/hooks/useApi";
1+
import { type AccountPlan, accountPlan } from "@3rdweb-sdk/react/hooks/useApi";
22
import { Box, type CardProps, Flex } from "@chakra-ui/react";
33
import {
44
Badge,
@@ -133,7 +133,7 @@ export const PricingCard: React.FC<PricingCardProps> = ({
133133
<FeatureItem key={Array.isArray(f) ? f[0] : f} text={f} />
134134
))}
135135
</Flex>
136-
{name === AccountPlan.Growth && onDashboard ? (
136+
{name === accountPlan.growth && onDashboard ? (
137137
<UpgradeModal
138138
name={name}
139139
ctaProps={ctaProps}

apps/dashboard/src/components/homepage/sections/PricingSection.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AccountPlan } from "@3rdweb-sdk/react/hooks/useApi";
1+
import { accountPlan } from "@3rdweb-sdk/react/hooks/useApi";
22
import { Box, Container, Flex, SimpleGrid } from "@chakra-ui/react";
33
import { Heading, Text, TrackedLink } from "tw-components";
44
import { CONTACT_US_URL } from "utils/pricing";
@@ -48,7 +48,7 @@ export const PricingSection: React.FC<PricingSectionProps> = ({
4848

4949
<SimpleGrid columns={{ base: 1, xl: 3 }} gap={{ base: 6, xl: 8 }}>
5050
<PricingCard
51-
name={AccountPlan.Free}
51+
name={accountPlan.free}
5252
ctaTitle="Get started for free"
5353
ctaProps={{
5454
category: trackingCategory,
@@ -61,7 +61,7 @@ export const PricingSection: React.FC<PricingSectionProps> = ({
6161
ctaTitle={
6262
canTrialGrowth ? "Claim your 1-month free" : "Get started"
6363
}
64-
name={AccountPlan.Growth}
64+
name={accountPlan.growth}
6565
ctaHint={
6666
canTrialGrowth
6767
? "Your free trial will end after 30 days."
@@ -82,7 +82,7 @@ export const PricingSection: React.FC<PricingSectionProps> = ({
8282
/>
8383

8484
<PricingCard
85-
name={AccountPlan.Pro}
85+
name={accountPlan.pro}
8686
ctaTitle="Contact us"
8787
ctaProps={{
8888
category: trackingCategory,

apps/dashboard/src/components/homepage/sections/UpgradeModal.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { AccountPlan, useAccount } from "@3rdweb-sdk/react/hooks/useApi";
1+
import {
2+
type AccountPlan,
3+
accountPlan,
4+
useAccount,
5+
} from "@3rdweb-sdk/react/hooks/useApi";
26
import {
37
Flex,
48
Modal,
@@ -44,7 +48,7 @@ export const UpgradeModal: React.FC<UpgradeModalProps> = ({
4448
// FIXME: this needs to be re-worked
4549
// eslint-disable-next-line no-restricted-syntax
4650
useEffect(() => {
47-
if (account.data?.plan === AccountPlan.Growth) {
51+
if (account.data?.plan === accountPlan.growth) {
4852
onClose();
4953
}
5054
}, [account.data?.plan, onClose]);

apps/dashboard/src/components/onboarding/ApplyForOpCreditsForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AccountPlan, useAccount } from "@3rdweb-sdk/react/hooks/useApi";
1+
import { accountPlan, useAccount } from "@3rdweb-sdk/react/hooks/useApi";
22
import { Flex, FormControl, Input, Textarea } from "@chakra-ui/react";
33
import { Select as ChakraSelect } from "chakra-react-select";
44
import { ChakraNextImage } from "components/Image";
@@ -41,7 +41,7 @@ export const ApplyForOpCreditsForm: React.FC<ApplyForOpCreditsFormProps> = ({
4141
firstname: "",
4242
lastname: "",
4343
thirdweb_account_id: account?.id || "",
44-
plan_type: PlanToCreditsRecord[account?.plan || AccountPlan.Free].title,
44+
plan_type: PlanToCreditsRecord[account?.plan || accountPlan.free].title,
4545
email: account?.email || "",
4646
company: "",
4747
website: "",

0 commit comments

Comments
 (0)