Skip to content

Commit 97b8926

Browse files
committed
[Dashboard] migrate external links form (#7156)
## Summary - refactor contract publish resources inputs - use shadcn/ui Button, Input, and Separator - apply tailwind classes ## Testing - `pnpm biome check --apply apps/dashboard/src/components/contract-components/contract-publish-form/external-links-fieldset.tsx apps/dashboard/src/components/contract-components/contract-publish-form/external-links-input.tsx` - `pnpm test` *(fails: spawn anvil ENOENT)* <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on updating the UI components in the `ExternalLinksFieldset` and `ExternalLinksInput` files to improve the styling and structure using custom components instead of those from `tw-components` and `@chakra-ui/react`. ### Detailed summary - Replaced `Heading` and `Text` with custom HTML elements in `ExternalLinksFieldset`. - Updated button styles in `ExternalLinksFieldset` to use `variant="outline"` and added a `className`. - Refactored `ExternalLinksInput` to use custom components (`Button`, `Input`, `Label`, `Separator`) instead of Chakra UI components. - Changed layout structure in `ExternalLinksInput` to use `div` elements with flexbox for better styling. - Added error message handling below input fields in `ExternalLinksInput`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Style** - Updated form and button components to use new UI primitives and Tailwind CSS classes for a refreshed appearance. - Improved accessibility by linking input labels and error messages with appropriate HTML attributes. - **Refactor** - Replaced Chakra UI components with custom or alternative UI components, maintaining existing functionality and validation logic. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 655df03 commit 97b8926

File tree

2 files changed

+57
-55
lines changed

2 files changed

+57
-55
lines changed

apps/dashboard/src/components/contract-components/contract-publish-form/external-links-fieldset.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { Button } from "@/components/ui/button";
12
import { PlusIcon } from "lucide-react";
23
import { useEffect } from "react";
34
import { useFieldArray, useFormContext } from "react-hook-form";
4-
import { Button, Heading, Text } from "tw-components";
55
import { ExternalLinksInput } from "./external-links-input";
66

77
export const ExternalLinksFieldset = () => {
@@ -29,8 +29,10 @@ export const ExternalLinksFieldset = () => {
2929
return (
3030
<fieldset className="flex flex-col gap-8">
3131
<div className="flex flex-col gap-2">
32-
<Heading size="title.md">Resources</Heading>
33-
<Text>Provide links to docs, usage guides etc. for the contract.</Text>
32+
<h3 className="font-semibold text-xl tracking-tight">Resources</h3>
33+
<p className="text-muted-foreground">
34+
Provide links to docs, usage guides etc. for the contract.
35+
</p>
3436
</div>
3537
<div className="flex flex-col gap-4">
3638
{fields.map((item, index) => (
@@ -40,16 +42,16 @@ export const ExternalLinksFieldset = () => {
4042
<Button
4143
type="button"
4244
size="sm"
43-
colorScheme="primary"
44-
borderRadius="md"
45-
leftIcon={<PlusIcon className="size-5" />}
45+
variant="outline"
46+
className="gap-2"
4647
onClick={() =>
4748
append({
4849
name: "",
4950
url: "",
5051
})
5152
}
5253
>
54+
<PlusIcon className="size-5" />
5355
Add Resource
5456
</Button>
5557
</div>
Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import {
2-
Divider,
3-
Flex,
4-
FormControl,
5-
IconButton,
6-
Input,
7-
} from "@chakra-ui/react";
1+
import { Button } from "@/components/ui/button";
2+
import { Input } from "@/components/ui/input";
3+
import { Label } from "@/components/ui/label";
4+
import { Separator } from "@/components/ui/separator";
85
import { TrashIcon } from "lucide-react";
96
import { useFormContext } from "react-hook-form";
10-
import { FormErrorMessage, FormLabel } from "tw-components";
117

128
interface ExternalLinksInputProps {
139
index: number;
@@ -21,38 +17,35 @@ export const ExternalLinksInput: React.FC<ExternalLinksInputProps> = ({
2117
const form = useFormContext();
2218

2319
return (
24-
<Flex flexDir="column" gap={2}>
25-
<Flex
26-
w="full"
27-
gap={{ base: 4, md: 2 }}
28-
flexDir={{ base: "column", md: "row" }}
29-
>
30-
<FormControl
31-
as={Flex}
32-
flexDir="column"
33-
gap={1}
34-
isInvalid={
35-
!!form.getFieldState(`externalLinks.${index}.name`, form.formState)
36-
.error
37-
}
38-
>
39-
<FormLabel textTransform="capitalize">Resource Name</FormLabel>
20+
<div className="flex flex-col gap-2">
21+
<div className="flex w-full flex-col gap-4 md:flex-row md:gap-2">
22+
<div className="flex flex-1 flex-col gap-1">
23+
<Label htmlFor={`externalLinks.${index}.name`} className="capitalize">
24+
Resource Name
25+
</Label>
4026
<Input
27+
id={`externalLinks.${index}.name`}
4128
placeholder="Resource name"
4229
{...form.register(`externalLinks.${index}.name`)}
4330
/>
44-
</FormControl>
45-
<FormControl
46-
as={Flex}
47-
flexDir="column"
48-
gap={1}
49-
isInvalid={
50-
!!form.getFieldState(`externalLinks.${index}.url`, form.formState)
51-
.error
52-
}
53-
>
54-
<FormLabel textTransform="capitalize">Link</FormLabel>
31+
{form.getFieldState(`externalLinks.${index}.name`, form.formState)
32+
.error?.message && (
33+
<p className="text-destructive-text text-sm">
34+
{
35+
form.getFieldState(
36+
`externalLinks.${index}.name`,
37+
form.formState,
38+
).error?.message
39+
}
40+
</p>
41+
)}
42+
</div>
43+
<div className="flex flex-1 flex-col gap-1">
44+
<Label htmlFor={`externalLinks.${index}.url`} className="capitalize">
45+
Link
46+
</Label>
5547
<Input
48+
id={`externalLinks.${index}.url`}
5649
placeholder="Provide URL to the resource page"
5750
{...form.register(`externalLinks.${index}.url`, {
5851
required: true,
@@ -64,21 +57,28 @@ export const ExternalLinksInput: React.FC<ExternalLinksInputProps> = ({
6457
},
6558
})}
6659
/>
67-
<FormErrorMessage>
68-
{
69-
form.getFieldState(`externalLinks.${index}.url`, form.formState)
70-
.error?.message
71-
}
72-
</FormErrorMessage>
73-
</FormControl>
74-
<IconButton
75-
icon={<TrashIcon className="size-5" />}
60+
{form.getFieldState(`externalLinks.${index}.url`, form.formState)
61+
.error?.message && (
62+
<p className="text-destructive-text text-sm">
63+
{
64+
form.getFieldState(`externalLinks.${index}.url`, form.formState)
65+
.error?.message
66+
}
67+
</p>
68+
)}
69+
</div>
70+
<Button
71+
variant="ghost"
72+
size="icon"
7673
aria-label="Remove row"
7774
onClick={() => remove(index)}
78-
alignSelf="end"
79-
/>
80-
</Flex>
81-
<Divider />
82-
</Flex>
75+
className="self-end"
76+
>
77+
<TrashIcon className="size-5" />
78+
<span className="sr-only">Remove row</span>
79+
</Button>
80+
</div>
81+
<Separator />
82+
</div>
8383
);
8484
};

0 commit comments

Comments
 (0)