Skip to content

Commit

Permalink
Merge pull request #9 from HausDAO/sk/22012025-more-form
Browse files Browse the repository at this point in the history
pulls meta fields into a component and uses formcontext hook
  • Loading branch information
skuhlmann authored Jan 22, 2025
2 parents 175cad0 + 5ac43fd commit 78cff3f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 201 deletions.
74 changes: 74 additions & 0 deletions src/components/app/ProposalMetaFields.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { useFormContext } from "react-hook-form";
import {
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "../ui/form";
import { Input } from "../ui/input";
import { Textarea } from "../ui/textarea";

export const ProposalMetaFields = ({ disabled }: { disabled: boolean }) => {
const form = useFormContext();
return (
<>
<FormField
control={form.control}
name="title"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Title</FormLabel>
</div>
<FormControl>
<Input
id="title"
placeholder="Simple Input Placeholder"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="description"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Description</FormLabel>
</div>
<FormControl>
<Textarea
id="description"
placeholder="Add a proposal description"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="link"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Link</FormLabel>
</div>
<FormControl>
<Input id="link" placeholder="Url for more content" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</>
);
};
74 changes: 4 additions & 70 deletions src/components/forms/RequestFunding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Textarea } from "../ui/textarea";
import { Form } from "@/components/ui/form";
import { FormComponentProps } from "../app/FormSwitcher";
import { useParams } from "next/navigation";
import { useDao } from "@/hooks/useDao";
import { useDaoTokenBalances } from "@/hooks/useDaoTokenBalances";
import { FormActionButtons } from "../app/FormActionButtons";
import { ProposalMetaFields } from "../app/ProposalMetaFields";

const formSchema = z.object({
title: z.string().min(2, {
Expand Down Expand Up @@ -69,66 +61,8 @@ export const RequestFunding = ({
onSubmit={form.handleSubmit(onSubmit)}
className="w-full px-4 space-y-4"
>
<FormField
control={form.control}
name="title"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Title</FormLabel>
</div>
<FormControl>
<Input
id="title"
placeholder="Simple Input Placeholder"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="description"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Description</FormLabel>
</div>
<FormControl>
<Textarea
id="description"
placeholder="Add a proposal description"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="link"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Link</FormLabel>
</div>
<FormControl>
<Input
id="link"
placeholder="Url for more content"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<ProposalMetaFields disabled={disabled} />

<FormActionButtons
submitButtonText={submitButtonText}
loading={loading}
Expand Down
64 changes: 3 additions & 61 deletions src/components/forms/RequestMembership.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Textarea } from "../ui/textarea";
import { FormComponentProps } from "../app/FormSwitcher";
import { parseUnits } from "viem";
import { FormActionButtons } from "../app/FormActionButtons";
import { ProposalMetaFields } from "../app/ProposalMetaFields";

const formSchema = z.object({
title: z.string().min(2, {
Expand Down Expand Up @@ -65,66 +65,8 @@ export const RequestMembership = ({
onSubmit={form.handleSubmit(onSubmit)}
className="w-full px-4 space-y-4"
>
<FormField
control={form.control}
name="title"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Title</FormLabel>
</div>
<FormControl>
<Input
id="title"
placeholder="Simple Input Placeholder"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="description"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Description</FormLabel>
</div>
<FormControl>
<Textarea
id="description"
placeholder="Add a proposal description"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="link"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Link</FormLabel>
</div>
<FormControl>
<Input
id="link"
placeholder="Url for more content"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<ProposalMetaFields disabled={disabled} />

<FormField
control={form.control}
name="recipient"
Expand Down
74 changes: 4 additions & 70 deletions src/components/forms/Signal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Textarea } from "../ui/textarea";
import { Form } from "@/components/ui/form";
import { FormComponentProps } from "../app/FormSwitcher";
import { FormActionButtons } from "../app/FormActionButtons";
import { ProposalMetaFields } from "../app/ProposalMetaFields";

const formSchema = z.object({
title: z.string().min(2, {
Expand Down Expand Up @@ -56,66 +48,8 @@ export const Signal = ({
onSubmit={form.handleSubmit(onSubmit)}
className="w-full px-4 space-y-4"
>
<FormField
control={form.control}
name="title"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Title</FormLabel>
</div>
<FormControl>
<Input
id="title"
placeholder="Simple Input Placeholder"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="description"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Description</FormLabel>
</div>
<FormControl>
<Textarea
id="description"
placeholder="Add a proposal description"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="link"
disabled={disabled}
render={({ field }) => (
<FormItem>
<div className="flex mb-2 justify-between">
<FormLabel>Link</FormLabel>
</div>
<FormControl>
<Input
id="link"
placeholder="Url for more content"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<ProposalMetaFields disabled={disabled} />

<FormActionButtons
submitButtonText={submitButtonText}
loading={loading}
Expand Down

0 comments on commit 78cff3f

Please sign in to comment.