Skip to content

Commit fadb84e

Browse files
committed
WIP: migrating PropertiesFormControl to shadcnui + tailwind
1 parent b5650f9 commit fadb84e

File tree

3 files changed

+113
-6
lines changed

3 files changed

+113
-6
lines changed

apps/dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"preinstall": "npx only-allow pnpm",
7-
"dev": "next dev",
7+
"dev": "next dev --turbo",
88
"build": "next build",
99
"start": "next start",
1010
"format": "biome format ./src --write",

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/BatchMetadata.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { Input } from "@/components/ui/input";
2020
import { Separator } from "@/components/ui/separator";
2121
import { Textarea } from "@/components/ui/textarea";
2222
import { useMutation } from "@tanstack/react-query";
23-
import { PropertiesFormControl } from "components/contract-pages/forms/properties.shared";
2423
import { CircleAlertIcon } from "lucide-react";
2524
import { useCallback } from "react";
2625
import { useForm } from "react-hook-form";
@@ -33,6 +32,7 @@ import { ModuleCardUI, type ModuleCardUIProps } from "./module-card";
3332
import type { ModuleInstanceProps } from "./module-instance";
3433
import { AdvancedNFTMetadataFormGroup } from "./nft/AdvancedNFTMetadataFormGroup";
3534
import { NFTMediaFormGroup } from "./nft/NFTMediaFormGroup";
35+
import { PropertiesFormControl } from "./nft/PropertiesFormControl";
3636

3737
export type UploadMetadataFormValues = NFTMetadataInputLimited & {
3838
supply: number;
@@ -181,12 +181,8 @@ function UploadMetadataNFTSection(props: {
181181
)}
182182
/>
183183

184-
{/* TODO - convert to shadcn + tailwind */}
185184
<PropertiesFormControl
186-
watch={form.watch}
187-
errors={form.formState.errors}
188185
control={form.control}
189-
register={form.register}
190186
setValue={form.setValue}
191187
/>
192188

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { Button } from "@/components/ui/button";
2+
import {
3+
FormControl,
4+
FormField,
5+
FormItem,
6+
FormMessage,
7+
} from "@/components/ui/form";
8+
import { Input } from "@/components/ui/input";
9+
import { BanIcon, PlusIcon, Trash2Icon } from "lucide-react";
10+
import {
11+
type ArrayPath,
12+
type FieldValues,
13+
type UseFormReturn,
14+
useFieldArray,
15+
} from "react-hook-form";
16+
17+
type OptionalPropertiesInput = {
18+
[key: string]: string | number;
19+
};
20+
21+
interface IPropertyFieldValues extends FieldValues {
22+
attributes?: OptionalPropertiesInput;
23+
}
24+
25+
export function PropertiesFormControl<
26+
TFieldValues extends IPropertyFieldValues,
27+
>({
28+
form,
29+
}: {
30+
form: UseFormReturn<TFieldValues>;
31+
}) {
32+
const { fields, append, remove, replace } = useFieldArray({
33+
control: form.control,
34+
name: "attributes" as ArrayPath<TFieldValues>,
35+
});
36+
37+
return (
38+
<div className="flex flex-col gap-4">
39+
<div className="flex items-center justify-between gap-2">
40+
<p>Attributes</p>
41+
<Button
42+
className="flex items-center gap-2"
43+
variant="destructive"
44+
size="sm"
45+
// biome-ignore lint/suspicious/noExplicitAny: FIXME
46+
onClick={() =>
47+
form.setValue("attributes", [{ trait_type: "", value: "" } as any])
48+
}
49+
>
50+
Reset
51+
<BanIcon className="size-4" />
52+
</Button>
53+
</div>
54+
55+
<div className="flex flex-col gap-3">
56+
{/* Addresses */}
57+
{fields.map((fieldItem, index) => (
58+
<div className="flex items-start gap-3" key={fieldItem.id}>
59+
<FormField
60+
control={form.control}
61+
name={`attributes.${index}.trait_type`}
62+
render={({ field }) => (
63+
<FormItem className="grow">
64+
<FormControl>
65+
<Input placeholder="0x..." {...field} />
66+
</FormControl>
67+
<FormMessage />
68+
</FormItem>
69+
)}
70+
/>
71+
72+
<FormField
73+
control={form.control}
74+
name={`attributes.${index}.value`}
75+
render={({ field }) => (
76+
<FormItem className="grow">
77+
<FormControl>
78+
<Input placeholder="0x..." {...field} />
79+
</FormControl>
80+
<FormMessage />
81+
</FormItem>
82+
)}
83+
/>
84+
85+
<Button
86+
variant="outline"
87+
className="!text-destructive-text bg-background"
88+
onClick={() => remove(index)}
89+
>
90+
<Trash2Icon className="size-4" />
91+
</Button>
92+
</div>
93+
))}
94+
</div>
95+
96+
<div className="flex flex-row gap-2">
97+
<Button
98+
size="sm"
99+
className="flex items-center gap-2"
100+
onClick={() =>
101+
// biome-ignore lint/suspicious/noExplicitAny: FIXME
102+
append({ trait_type: undefined, value: undefined } as any)
103+
}
104+
>
105+
<PlusIcon className="size-5" />
106+
Add Row
107+
</Button>
108+
</div>
109+
</div>
110+
);
111+
}

0 commit comments

Comments
 (0)