Skip to content

Commit 1adbc62

Browse files
committed
Migrate Engine Overview page to shadcn/tailwind - Part1 (#4926)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on refactoring the `CreateBackendWalletButton` and `ImportBackendWalletButton` components to use a new dialog system, enhancing the user interface and improving code structure. It also introduces tooltips and updates form handling for better user experience. ### Detailed summary - Replaced `Modal` with `Dialog` for `CreateBackendWalletButton` and `ImportBackendWalletButton`. - Added `tooltip` prop in `FormFieldSetup`. - Updated form handling for better state management and error display. - Enhanced UI elements with improved styling and layout. - Refactored wallet import and creation logic for clarity and maintainability. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 87c8854 commit 1adbc62

File tree

8 files changed

+375
-285
lines changed

8 files changed

+375
-285
lines changed

apps/dashboard/src/@/components/blocks/FormFieldSetup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function FormFieldSetup(props: {
77
label: string;
88
errorMessage: React.ReactNode | undefined;
99
children: React.ReactNode;
10-
tooltip: React.ReactNode | undefined;
10+
tooltip?: React.ReactNode;
1111
isRequired: boolean;
1212
}) {
1313
return (

apps/dashboard/src/@/components/ui/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
1111
<input
1212
type={type}
1313
className={cn(
14-
"flex h-10 w-full rounded-md border border-input bg-card px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:font-medium file:text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
14+
"flex h-10 w-full rounded-md border border-input bg-card px-3 py-2 text-sm ring-offset-background selection:bg-foreground selection:text-background file:border-0 file:bg-transparent file:font-medium file:text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
1515
className,
1616
)}
1717
ref={ref}

apps/dashboard/src/components/configure-networks/ConfigureNetworkForm.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
259259
htmlFor="name"
260260
label="Name"
261261
errorMessage={networkNameErrorMessage}
262-
tooltip={undefined}
263262
isRequired
264263
>
265264
<Input
@@ -301,7 +300,6 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
301300
isRequired
302301
label="Currency Symbol"
303302
errorMessage={form.formState.errors.currencySymbol?.message}
304-
tooltip={undefined}
305303
htmlFor="currency-symbol"
306304
>
307305
<Input
@@ -366,7 +364,6 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
366364
errorMessage={form.formState.errors.icon?.message}
367365
htmlFor="network-icon"
368366
label="Icon"
369-
tooltip={undefined}
370367
>
371368
<div className="flex items-center gap-1">
372369
<ChainIcon size={20} ipfsSrc={form.watch("icon")} />

apps/dashboard/src/components/configure-networks/Form/ChainIdInput.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const ChainIdInput: React.FC<{
1717
? form.formState.errors.chainId?.message
1818
: undefined
1919
}
20-
tooltip={undefined}
2120
>
2221
<Input
2322
disabled={disabled}

apps/dashboard/src/components/configure-networks/Form/RpcInput.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export const RpcInput: React.FC<{
2525
isRequired
2626
errorMessage={form.formState.errors.rpcUrl?.message}
2727
htmlFor="rpc-url"
28-
tooltip={undefined}
2928
label="RPC URL"
3029
>
3130
<Input
Lines changed: 67 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,41 @@
1+
"use client";
2+
3+
import { FormFieldSetup } from "@/components/blocks/FormFieldSetup";
4+
import { Spinner } from "@/components/ui/Spinner/Spinner";
5+
import { Badge } from "@/components/ui/badge";
6+
import { Button } from "@/components/ui/button";
7+
import {
8+
Dialog,
9+
DialogContent,
10+
DialogFooter,
11+
DialogHeader,
12+
DialogTitle,
13+
} from "@/components/ui/dialog";
14+
import { Input } from "@/components/ui/input";
115
import {
216
type CreateBackendWalletInput,
317
useEngineCreateBackendWallet,
418
useEngineWalletConfig,
519
} from "@3rdweb-sdk/react/hooks/useEngine";
6-
import {
7-
Flex,
8-
FormControl,
9-
Input,
10-
Modal,
11-
ModalBody,
12-
ModalCloseButton,
13-
ModalContent,
14-
ModalFooter,
15-
ModalHeader,
16-
ModalOverlay,
17-
useDisclosure,
18-
} from "@chakra-ui/react";
1920
import { useTrack } from "hooks/analytics/useTrack";
20-
import { useTxNotifications } from "hooks/useTxNotifications";
21+
import { useState } from "react";
2122
import { useForm } from "react-hook-form";
22-
import { Button, FormLabel, Text } from "tw-components";
23+
import { toast } from "sonner";
2324

24-
interface CreateBackendWalletButtonProps {
25+
export function CreateBackendWalletButton(props: {
2526
instanceUrl: string;
26-
}
27-
28-
export const CreateBackendWalletButton: React.FC<
29-
CreateBackendWalletButtonProps
30-
> = ({ instanceUrl }) => {
31-
const { isOpen, onOpen, onClose } = useDisclosure();
27+
}) {
28+
const { instanceUrl } = props;
29+
const [isOpen, setIsOpen] = useState(false);
3230
const { data: walletConfig } = useEngineWalletConfig(instanceUrl);
33-
const { mutate: createBackendWallet } =
34-
useEngineCreateBackendWallet(instanceUrl);
35-
const { onSuccess, onError } = useTxNotifications(
36-
"Wallet created successfully.",
37-
"Failed to create wallet.",
38-
);
31+
const createWallet = useEngineCreateBackendWallet(instanceUrl);
3932
const trackEvent = useTrack();
4033
const form = useForm<CreateBackendWalletInput>();
4134

4235
const onSubmit = async (data: CreateBackendWalletInput) => {
43-
createBackendWallet(data, {
36+
const promise = createWallet.mutateAsync(data, {
4437
onSuccess: () => {
45-
onSuccess();
46-
onClose();
38+
setIsOpen(false);
4739
trackEvent({
4840
category: "engine",
4941
action: "create-backend-wallet",
@@ -52,7 +44,6 @@ export const CreateBackendWalletButton: React.FC<
5244
});
5345
},
5446
onError: (error) => {
55-
onError(error);
5647
trackEvent({
5748
category: "engine",
5849
action: "create-backend-wallet",
@@ -62,6 +53,11 @@ export const CreateBackendWalletButton: React.FC<
6253
});
6354
},
6455
});
56+
57+
toast.promise(promise, {
58+
success: "Wallet created successfully",
59+
error: "Failed to create wallet",
60+
});
6561
};
6662

6763
const walletType =
@@ -73,43 +69,58 @@ export const CreateBackendWalletButton: React.FC<
7369

7470
return (
7571
<>
76-
<Button onClick={onOpen} colorScheme="primary">
77-
Create
78-
</Button>
79-
<Modal isOpen={isOpen} onClose={onClose} isCentered>
80-
<ModalOverlay />
81-
<ModalContent className="!bg-background rounded-lg border border-border">
72+
<Button onClick={() => setIsOpen(true)}>Create</Button>
73+
<Dialog open={isOpen} onOpenChange={setIsOpen}>
74+
<DialogContent
75+
className="z-[10001] p-0"
76+
dialogOverlayClassName="z-[10000]"
77+
>
8278
<form onSubmit={form.handleSubmit(onSubmit)}>
83-
<ModalHeader>Create {walletType} wallet</ModalHeader>
84-
<ModalCloseButton />
85-
<ModalBody>
79+
<div className="p-6">
80+
<DialogHeader className="mb-4">
81+
<DialogTitle className="font-semibold text-2xl tracking-tight">
82+
Create {walletType} wallet
83+
</DialogTitle>
84+
</DialogHeader>
85+
8686
<div className="flex flex-col gap-4">
87-
<FormControl>
88-
<FormLabel>Wallet Type</FormLabel>
89-
<Text>{walletType}</Text>
90-
</FormControl>
91-
<FormControl>
92-
<FormLabel>Label</FormLabel>
87+
<div>
88+
<p className="mb-1 text-sm">Wallet Type</p>
89+
<Badge className="text-sm" variant="outline">
90+
{walletType}
91+
</Badge>
92+
</div>
93+
94+
<FormFieldSetup
95+
label="Label"
96+
errorMessage={
97+
form.getFieldState("label", form.formState).error?.message
98+
}
99+
htmlFor="wallet-label"
100+
isRequired={false}
101+
>
93102
<Input
103+
id="wallet-label"
94104
type="text"
95105
placeholder="Enter a descriptive label"
96106
{...form.register("label")}
97107
/>
98-
</FormControl>
108+
</FormFieldSetup>
99109
</div>
100-
</ModalBody>
110+
</div>
101111

102-
<ModalFooter as={Flex} gap={3}>
103-
<Button onClick={onClose} variant="ghost">
112+
<DialogFooter className="!flex-row !justify-end mt-4 gap-3 border-border border-t bg-muted/50 p-6">
113+
<Button onClick={() => setIsOpen(false)} variant="outline">
104114
Cancel
105115
</Button>
106-
<Button type="submit" colorScheme="primary">
116+
<Button type="submit" className="min-w-28 gap-2">
117+
{createWallet.isPending && <Spinner className="size-4" />}
107118
Create
108119
</Button>
109-
</ModalFooter>
120+
</DialogFooter>
110121
</form>
111-
</ModalContent>
112-
</Modal>
122+
</DialogContent>
123+
</Dialog>
113124
</>
114125
);
115-
};
126+
}

0 commit comments

Comments
 (0)