Skip to content

Commit cf8badb

Browse files
committed
Move Network Configuration Form+Modal to shadcn/tailwind (#4105)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR updates various UI components for consistency and usability. ### Detailed summary - Updated styling for `ClaimConditionsForm`, `CustomChainRenderer`, `ToolTipLabel`, `RpcInput`, `ChainIdInput`, `TooltipBox`, `ConfigureNetworkModal`, `ResetClaimEligibility`, `NetworkIdInput`, `IconUpload`, and `ConfigureNetworks`. - Replaced `TooltipBox` with `ToolTipLabel` and `CircleHelpIcon`. - Added `Input` from `@/components/ui/input`. - Removed unnecessary imports. - Replaced `Modal` components with `Dialog` and `DialogContent`. - Used `toast` for error notifications. - Updated button styling and functionality. > The following files were skipped due to too many changes: `apps/dashboard/src/components/configure-networks/ConfigureNetworks.tsx`, `apps/dashboard/src/pages/[chain_id]/[...paths].tsx`, `apps/dashboard/src/components/configure-networks/ConfigureNetworkForm.tsx` > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 09e4d80 commit cf8badb

File tree

13 files changed

+131
-251
lines changed

13 files changed

+131
-251
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
3131

3232
export function ToolTipLabel(props: {
3333
children: React.ReactNode;
34-
label: string | undefined;
34+
label: React.ReactNode;
3535
rightIcon?: React.ReactNode;
3636
leftIcon?: React.ReactNode;
3737
}) {
@@ -47,7 +47,7 @@ export function ToolTipLabel(props: {
4747
</TooltipTrigger>
4848
<TooltipContent
4949
sideOffset={10}
50-
className="max-w-[300px] leading-relaxed"
50+
className="max-w-[400px] leading-relaxed"
5151
>
5252
<div className="p-2 text-sm flex items-center gap-1.5">
5353
{props.leftIcon}

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

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
import { Button } from "@/components/ui/button";
2+
import { Input } from "@/components/ui/input";
13
import {
24
Alert,
35
AlertIcon,
4-
Flex,
56
FormControl,
6-
Input,
77
Radio,
88
RadioGroup,
9-
SimpleGrid,
10-
Stack,
119
} from "@chakra-ui/react";
1210
import { ChainIcon } from "components/icons/ChainIcon";
1311
import type { StoredChain } from "contexts/configured-chains";
@@ -16,7 +14,7 @@ import { useSupportedChainsNameRecord } from "hooks/chains/configureChains";
1614
import { useRemoveChainModification } from "hooks/chains/useModifyChain";
1715
import { getDashboardChainRpc } from "lib/rpc";
1816
import { useForm } from "react-hook-form";
19-
import { Button, FormErrorMessage, FormLabel, Text } from "tw-components";
17+
import { FormErrorMessage, FormLabel } from "tw-components";
2018
import { ChainIdInput } from "./Form/ChainIdInput";
2119
import { ConfirmationPopover } from "./Form/ConfirmationPopover";
2220
import { IconUpload } from "./Form/IconUpload";
@@ -217,11 +215,7 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
217215

218216
const submitBtn = (
219217
<Button
220-
background="bgBlack"
221-
color="bgWhite"
222-
_hover={{
223-
background: "bgBlack",
224-
}}
218+
variant="primary"
225219
type={disableSubmit ? "submit" : overwritingChain ? "button" : "submit"}
226220
disabled={disableSubmit}
227221
>
@@ -243,9 +237,6 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
243237
<Input
244238
autoComplete="off"
245239
placeholder="e.g. My Network"
246-
_placeholder={{
247-
fontWeight: 500,
248-
}}
249240
type="text"
250241
onChange={(e) => {
251242
const value = e.target.value;
@@ -272,9 +263,9 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
272263
{/* Slug URL */}
273264
<NetworkIDInput form={form} disabled={!isFullyEditable} />
274265

275-
<Flex direction="column" gap={6} mt={6}>
266+
<div className="flex flex-col gap-6 mt-6">
276267
{/* Chain ID + Currency Symbol */}
277-
<SimpleGrid columns={{ md: 2, base: 1 }} gap={4}>
268+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
278269
<ChainIdInput form={form} disabled={!isFullyEditable} />
279270

280271
{/* Currency Symbol */}
@@ -284,33 +275,29 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
284275
disabled={!isFullyEditable}
285276
placeholder="e.g. ETH"
286277
autoComplete="off"
287-
_placeholder={{
288-
fontWeight: 500,
289-
}}
290278
type="text"
291279
{...form.register("currencySymbol", { required: true })}
292280
/>
293281
</FormControl>
294-
</SimpleGrid>
282+
</div>
295283

296-
<SimpleGrid columns={{ md: 2, base: 1 }} gap={4}>
284+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
297285
{/* Testnet / Mainnet */}
298286
<FormControl>
299-
<FormLabel display="flex">
287+
<FormLabel className="!flex gap-1 items-center">
300288
Network type
301289
<TooltipBox
302290
content={
303291
<>
304-
<Text color="heading" display="inline-block" mb={2}>
305-
{" "}
292+
<span className="mb-2 block">
306293
The network type indicates whether it is intended for
307294
production or testing.
308-
</Text>
295+
</span>
309296

310-
<Text color="heading">
297+
<span className="block">
311298
It{`'`}s only used for displaying network type on the
312299
dashboard and does not affect functionality.
313-
</Text>
300+
</span>
314301
</>
315302
}
316303
/>
@@ -324,30 +311,30 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
324311
}}
325312
value={form.watch("type")}
326313
>
327-
<Stack direction="row" gap={4} mt={3}>
314+
<div className="flex gap-4 mt-3">
328315
<Radio value="mainnet">Mainnet</Radio>
329316
<Radio value="testnet">Testnet</Radio>
330-
</Stack>
317+
</div>
331318
</RadioGroup>
332319
</FormControl>
333320

334321
{/* Icon */}
335322
<FormControl isInvalid={!!form.formState.errors.icon}>
336323
<FormLabel>Icon</FormLabel>
337324

338-
<Flex gap={3} alignItems="center">
325+
<div className="flex gap-1 items-center">
339326
<ChainIcon size={24} ipfsSrc={form.watch("icon")} />
340327
<IconUpload
341328
onUpload={(uri) => {
342329
form.setValue("icon", uri, { shouldDirty: true });
343330
}}
344331
/>
345-
</Flex>
332+
</div>
346333
</FormControl>
347-
</SimpleGrid>
334+
</div>
348335

349336
{editingChain?.status === "deprecated" && (
350-
<SimpleGrid columns={{ md: 2, base: 1 }} gap={4}>
337+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
351338
{/* Active / Deprecated */}
352339
<FormControl>
353340
<FormLabel display="flex">Network status</FormLabel>
@@ -360,13 +347,13 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
360347
}}
361348
value={form.watch("status")}
362349
>
363-
<Stack direction="row" gap={4} mt={3}>
350+
<div className="flex mt-3 gap-4">
364351
<Radio value="active">Live</Radio>
365352
<Radio value="deprecated">Deprecated</Radio>
366-
</Stack>
353+
</div>
367354
</RadioGroup>
368355
</FormControl>
369-
</SimpleGrid>
356+
</div>
370357
)}
371358

372359
{/* RPC URL */}
@@ -382,11 +369,7 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
382369
)}
383370

384371
{/* Buttons */}
385-
<Flex
386-
gap={4}
387-
direction={{ base: "column", md: "row" }}
388-
justifyContent={{ base: "center", md: "flex-end" }}
389-
>
372+
<div className="flex gap-4 flex-col md:flex-row justify-end">
390373
{/* Add / Update Button */}
391374
{overwritingChain && !disableSubmit ? (
392375
<ConfirmationPopover
@@ -417,8 +400,8 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
417400
Reset
418401
</Button>
419402
)}
420-
</Flex>
421-
</Flex>
403+
</div>
404+
</div>
422405
</form>
423406
);
424407
};
Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
Modal,
3-
ModalBody,
4-
ModalCloseButton,
5-
ModalContent,
6-
ModalOverlay,
7-
} from "@chakra-ui/react";
1+
import { Dialog, DialogContent } from "@/components/ui/dialog";
82
import type { StoredChain } from "contexts/configured-chains";
93
import { useSetEditChain } from "hooks/networkConfigModal";
104
import { ConfigureNetworks } from "./ConfigureNetworks";
@@ -24,31 +18,26 @@ export const ConfigureNetworkModal: React.FC<AddNetworkModalProps> = (
2418
};
2519

2620
return (
27-
<Modal isOpen={true} onClose={onModalClose} isCentered>
28-
<ModalOverlay />
29-
<ModalContent
30-
borderRadius="xl"
31-
overflow="hidden"
32-
w="500px"
33-
mt={{ base: 8, md: 16 }}
34-
mb={{ base: 0, md: 16 }}
35-
maxW={{ base: "100vw", md: "calc(100vw - 40px)" }}
21+
<Dialog
22+
open={true}
23+
onOpenChange={(v) => {
24+
if (!v) {
25+
onModalClose();
26+
}
27+
}}
28+
>
29+
<DialogContent
30+
className="p-0 z-[10001] max-w-[480px]"
31+
dialogOverlayClassName="z-[10000]"
3632
>
37-
<ModalCloseButton />
38-
<ModalBody
39-
p={0}
40-
_dark={{ background: "backgroundBody" }}
41-
_light={{ background: "white" }}
42-
>
43-
<ConfigureNetworks
44-
onNetworkAdded={(chain) => {
45-
props.onNetworkAdded?.(chain);
46-
onModalClose();
47-
}}
48-
onNetworkConfigured={onModalClose}
49-
/>
50-
</ModalBody>
51-
</ModalContent>
52-
</Modal>
33+
<ConfigureNetworks
34+
onNetworkAdded={(chain) => {
35+
props.onNetworkAdded?.(chain);
36+
onModalClose();
37+
}}
38+
onNetworkConfigured={onModalClose}
39+
/>
40+
</DialogContent>
41+
</Dialog>
5342
);
5443
};
Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { Box, useToast } from "@chakra-ui/react";
21
import type { StoredChain } from "contexts/configured-chains";
32
import { useTrack } from "hooks/analytics/useTrack";
43
import { useAddRecentlyUsedChainId } from "hooks/chains/recentlyUsedChains";
54
import { useModifyChain } from "hooks/chains/useModifyChain";
65
import { useEditChain } from "hooks/networkConfigModal";
7-
import { Heading } from "tw-components";
6+
import { toast } from "sonner";
87
import { ConfigureNetworkForm } from "./ConfigureNetworkForm";
98

109
function useChainConfigTrack() {
@@ -31,17 +30,6 @@ export const ConfigureNetworks: React.FC<ConfigureNetworksProps> = (props) => {
3130
const modifyChain = useModifyChain();
3231
const editChain = useEditChain();
3332

34-
const toast = useToast();
35-
36-
const successToast = (message: string) => {
37-
toast({
38-
title: message,
39-
status: "success",
40-
duration: 3000,
41-
isClosable: true,
42-
});
43-
};
44-
4533
const handleSubmit = (chain: StoredChain) => {
4634
modifyChain(chain);
4735
addRecentlyUsedChainId(chain.chainId);
@@ -52,44 +40,29 @@ export const ConfigureNetworks: React.FC<ConfigureNetworksProps> = (props) => {
5240
}
5341

5442
trackChainConfig("add", chain);
55-
successToast("Network Added Successfully");
43+
toast.success("Network Added Successfully");
5644
} else {
5745
if (props.onNetworkConfigured) {
5846
props.onNetworkConfigured(chain);
5947
}
6048

6149
trackChainConfig("update", chain);
62-
successToast("Network Updated Successfully");
50+
toast.success("Network Updated Successfully");
6351
}
6452
};
6553

6654
return (
67-
<Box
68-
p={{ base: 4, md: 8 }}
69-
minH="600px"
70-
borderTop={{ md: "none", base: "1px solid" }}
71-
marginTop={{ base: 6, md: 0 }}
72-
borderColor="inputBg"
73-
>
74-
<Heading
75-
as={"h3"}
76-
size="label.xl"
77-
mb={8}
78-
display="flex"
79-
gap={2}
80-
alignItems="center"
81-
>
55+
<div className="p-6">
56+
<h3 className="text-2xl font-semibold tracking-tight mb-5">
8257
{editChain ? "Edit Network" : "Add Custom Network"}
83-
</Heading>
58+
</h3>
8459

8560
{/* Modify the given chain */}
8661
{editChain && (
87-
<Box mt={9}>
88-
<ConfigureNetworkForm
89-
editingChain={editChain}
90-
onSubmit={handleSubmit}
91-
/>
92-
</Box>
62+
<ConfigureNetworkForm
63+
editingChain={editChain}
64+
onSubmit={handleSubmit}
65+
/>
9366
)}
9467

9568
{/* Custom chain */}
@@ -100,6 +73,6 @@ export const ConfigureNetworks: React.FC<ConfigureNetworksProps> = (props) => {
10073
onSubmit={handleSubmit}
10174
/>
10275
)}
103-
</Box>
76+
</div>
10477
);
10578
};

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { FormControl, Input } from "@chakra-ui/react";
1+
import { Input } from "@/components/ui/input";
2+
import { FormControl } from "@chakra-ui/react";
23
import type { UseFormReturn } from "react-hook-form";
34
import { FormLabel } from "tw-components";
45
import type { NetworkConfigFormData } from "../ConfigureNetworkForm";
56

67
export const ChainIdInput: React.FC<{
7-
// biome-ignore lint/suspicious/noExplicitAny: FIXME
8-
form: UseFormReturn<NetworkConfigFormData, any>;
8+
form: UseFormReturn<NetworkConfigFormData>;
99
disabled: boolean;
1010
}> = ({ form, disabled }) => {
1111
return (
@@ -18,9 +18,6 @@ export const ChainIdInput: React.FC<{
1818
disabled={disabled}
1919
placeholder="e.g. 152"
2020
autoComplete="off"
21-
_placeholder={{
22-
fontWeight: 500,
23-
}}
2421
onKeyDown={(e) => {
2522
// prevent typing e, +, -
2623
if (e.key === "e" || e.key === "+" || e.key === "-") {

0 commit comments

Comments
 (0)