-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from cosmos/formgen-field-description
Add field description
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
components/forms/CreateTxForm/Fields/FieldDescription.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; | ||
import { Input } from "@/components/ui/input"; | ||
import { prettyFieldName } from "@/lib/form"; | ||
import * as z from "zod"; | ||
import type { FieldProps } from "./types"; | ||
|
||
const isFieldDescription = (fieldName: string) => fieldName === "description"; | ||
|
||
export const getFieldDescription = (fieldName: string) => | ||
isFieldDescription(fieldName) ? FieldDescription : null; | ||
|
||
export const getFieldDescriptionSchema = (fieldName: string) => | ||
isFieldDescription(fieldName) | ||
? z.object({ | ||
moniker: z | ||
.string({ invalid_type_error: "Must be a string", required_error: "Required" }) | ||
.trim() | ||
.min(1, "Required"), | ||
identity: z | ||
.string({ invalid_type_error: "Must be a string", required_error: "Required" }) | ||
.trim() | ||
.min(1, "Required"), | ||
website: z | ||
.string({ invalid_type_error: "Must be a string", required_error: "Required" }) | ||
.trim() | ||
.url("Must be a url") | ||
.min(1, "Required"), | ||
securityContact: z | ||
.string({ invalid_type_error: "Must be a string", required_error: "Required" }) | ||
.trim() | ||
.min(1, "Required"), | ||
details: z | ||
.string({ invalid_type_error: "Must be a string", required_error: "Required" }) | ||
.trim() | ||
.min(1, "Required"), | ||
}) | ||
: null; | ||
|
||
export default function FieldDescription({ form, fieldFormName }: FieldProps) { | ||
const prettyLabel = prettyFieldName(fieldFormName); | ||
|
||
return ( | ||
<> | ||
<FormField | ||
control={form.control} | ||
name={`${fieldFormName}.moniker`} | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>{`${prettyLabel} Moniker`}</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter moniker" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name={`${fieldFormName}.identity`} | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>{`${prettyLabel} Identity`}</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter identity" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name={`${fieldFormName}.website`} | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>{`${prettyLabel} Website`}</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter website" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name={`${fieldFormName}.securityContact`} | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>{`${prettyLabel} Security Contact`}</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter security contact" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name={`${fieldFormName}.details`} | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>{`${prettyLabel} Details`}</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter details" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from "./FieldAddress"; | ||
export * from "./FieldAmount"; | ||
export * from "./FieldBoolean"; | ||
export * from "./FieldDescription"; | ||
export * from "./FieldNumber"; | ||
export * from "./FieldString"; | ||
export * from "./FieldTimeoutHeight"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters