diff --git a/components/forms/CreateTxForm/Fields/FieldDescription.tsx b/components/forms/CreateTxForm/Fields/FieldDescription.tsx new file mode 100644 index 00000000..be94c5ee --- /dev/null +++ b/components/forms/CreateTxForm/Fields/FieldDescription.tsx @@ -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 ( + <> + ( + + {`${prettyLabel} Moniker`} + + + + + + )} + /> + ( + + {`${prettyLabel} Identity`} + + + + + + )} + /> + ( + + {`${prettyLabel} Website`} + + + + + + )} + /> + ( + + {`${prettyLabel} Security Contact`} + + + + + + )} + /> + ( + + {`${prettyLabel} Details`} + + + + + + )} + /> + + ); +} diff --git a/components/forms/CreateTxForm/Fields/index.ts b/components/forms/CreateTxForm/Fields/index.ts index ab659975..62413a5a 100644 --- a/components/forms/CreateTxForm/Fields/index.ts +++ b/components/forms/CreateTxForm/Fields/index.ts @@ -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"; diff --git a/lib/form.ts b/lib/form.ts index 9a1a8db2..53b2e5e8 100644 --- a/lib/form.ts +++ b/lib/form.ts @@ -5,6 +5,8 @@ import { getFieldAmountSchema, getFieldBoolean, getFieldBooleanSchema, + getFieldDescription, + getFieldDescriptionSchema, getFieldNumber, getFieldNumberSchema, getFieldString, @@ -30,6 +32,7 @@ export const getField = (fieldName: string) => getFieldNumber(fieldName) || getFieldBoolean(fieldName) || getFieldTimeoutHeight(fieldName) || + getFieldDescription(fieldName) || null; const getFieldSchema = (fieldName: string, schemaInput: FieldSchemaInput) => @@ -39,6 +42,7 @@ const getFieldSchema = (fieldName: string, schemaInput: FieldSchemaInput) => getFieldNumberSchema(fieldName) || getFieldBooleanSchema(fieldName) || getFieldTimeoutHeightSchema(fieldName) || + getFieldDescriptionSchema(fieldName) || null; export const getMsgSchema = (fieldNames: readonly string[], schemaInput: FieldSchemaInput) => {