diff --git a/components/forms/CreateTxForm/Fields/FieldBoolean.tsx b/components/forms/CreateTxForm/Fields/FieldBoolean.tsx new file mode 100644 index 00000000..077c384d --- /dev/null +++ b/components/forms/CreateTxForm/Fields/FieldBoolean.tsx @@ -0,0 +1,35 @@ +import { Checkbox } from "@/components/ui/checkbox"; +import { FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; +import { prettyFieldName } from "@/lib/form"; +import * as z from "zod"; +import type { FieldProps } from "./types"; + +const isFieldBoolean = (fieldName: string) => ["delayed", "fixMsg"].includes(fieldName); + +export const getFieldBoolean = (fieldName: string) => + isFieldBoolean(fieldName) ? FieldBoolean : null; + +export const getFieldBooleanSchema = (fieldName: string) => + isFieldBoolean(fieldName) + ? z.coerce.boolean({ invalid_type_error: "Must be a boolean", required_error: "Required" }) + : null; + +export default function FieldBoolean({ form, fieldFormName }: FieldProps) { + return ( + ( + + + + +
+ {prettyFieldName(fieldFormName)} + +
+
+ )} + /> + ); +} diff --git a/components/forms/CreateTxForm/Fields/index.ts b/components/forms/CreateTxForm/Fields/index.ts index 2135f9d3..4417b14e 100644 --- a/components/forms/CreateTxForm/Fields/index.ts +++ b/components/forms/CreateTxForm/Fields/index.ts @@ -1,4 +1,5 @@ export * from "./FieldAddress"; export * from "./FieldAmount"; +export * from "./FieldBoolean"; export * from "./FieldNumber"; export * from "./FieldString"; diff --git a/lib/form.ts b/lib/form.ts index cc2b8f19..a4ad2fb5 100644 --- a/lib/form.ts +++ b/lib/form.ts @@ -3,6 +3,8 @@ import { getFieldAddressSchema, getFieldAmount, getFieldAmountSchema, + getFieldBoolean, + getFieldBooleanSchema, getFieldNumber, getFieldNumberSchema, getFieldString, @@ -24,6 +26,7 @@ export const getField = (fieldName: string) => getFieldAmount(fieldName) || getFieldString(fieldName) || getFieldNumber(fieldName) || + getFieldBoolean(fieldName) || null; const getFieldSchema = (fieldName: string, schemaInput: FieldSchemaInput) => @@ -31,6 +34,7 @@ const getFieldSchema = (fieldName: string, schemaInput: FieldSchemaInput) => getFieldAmountSchema(fieldName) || getFieldStringSchema(fieldName) || getFieldNumberSchema(fieldName) || + getFieldBooleanSchema(fieldName) || null; export const getMsgSchema = (fieldNames: readonly string[], schemaInput: FieldSchemaInput) => {