From 5606e41f654e0bdb8b5cb00125ea8056d139b214 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Wed, 31 Jul 2024 13:09:11 +0200 Subject: [PATCH 1/2] Add FieldDescription --- .../CreateTxForm/Fields/FieldDescription.tsx | 111 ++++++++++++++++++ components/forms/CreateTxForm/Fields/index.ts | 1 + 2 files changed, 112 insertions(+) create mode 100644 components/forms/CreateTxForm/Fields/FieldDescription.tsx 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"; From 75294eb6273de546d3ca758a916e9e82fda09145 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Wed, 31 Jul 2024 13:09:25 +0200 Subject: [PATCH 2/2] Add FieldDescription to form helpers --- lib/form.ts | 4 ++++ 1 file changed, 4 insertions(+) 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) => {