feat: Add URL-type input in booking question field (#15481)

* feat: Add URL-type input in booking question field

* fix type error

* Update common.json

* fix requested changes

* small update

---------

Co-authored-by: Rajiv Sahal <[email protected]>
Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-08-05 12:53:53 +05:30
1 parent add59896f5
commit 099d830e7e
7 files changed
+146 -1

No files matched your search

@@ -512,5 +512,11 @@ export const Components: Record<FieldType, Component> = {
);
},
},
url: {
propsType: propsTypes.url,
factory: (props) => {
return <Widgets.TextWidget type="url" noLabel={true} {...props} />;
},
},
} as const;
// Should use `statisfies` to check if the `type` is from supported types. But satisfies doesn't work with Next.js config
@@ -152,6 +152,11 @@ const configMap: Record<FieldType, Omit<z.infer<typeof fieldTypeConfigSchema>, "
value: "boolean",
isTextType: false,
},
url: {
label: "URL",
value: "url",
isTextType: true,
},
};
export const fieldTypesConfigMap = configMap as Record<FieldType, z.infer<typeof fieldTypeConfigSchema>>;
@@ -13,4 +13,5 @@ export const propsTypes = {
checkbox: "multiselect",
radio: "select",
boolean: "boolean",
url: "text",
} as const;
+17
View File
@@ -23,6 +23,7 @@ const fieldTypeEnum = z.enum([
"radio",
"radioInput",
"boolean",
"url",
]);
export type FieldType = z.infer<typeof fieldTypeEnum>;
@@ -368,6 +369,22 @@ export const fieldTypesSchemaMap: Partial<
}
},
},
url: {
preprocess: ({ response }) => {
return response.trim();
},
superRefine: ({ response, ctx, m }) => {
const value = response ?? "";
const urlSchema = z.string().url();
if (!urlSchema.safeParse(value).success) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: m("url_validation_error"),
});
}
},
},
};
/**