feat: Ability to Hyperlink text in Checkbox on Additional Questions (#15194)

* feat: Ability to Hyperlink text in Checkbox on Additional Questions

* update

* fix and update

* fix type error

* fix and update

* dpdate

* fix type error

* fix unit test

* Update

* fix tests

* revert test

* remove yarn.lock

* remove schema.prisma

* update

* remove log

* revert

---------

Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Amit Sharma <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-09-05 09:05:45 +00:00
1 parent 633697a812
commit fabcf2055b
9 files changed
+118 -38

No files matched your search

+51 -15
View File
@@ -6,7 +6,9 @@ import type { z } from "zod";
import { classNames } from "@calcom/lib";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { md } from "@calcom/lib/markdownIt";
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
import turndown from "@calcom/lib/turndownService";
import {
Badge,
BooleanToggleGroupField,
@@ -24,6 +26,7 @@ import {
Label,
SelectField,
showToast,
Editor,
Switch,
} from "@calcom/ui";
@@ -421,6 +424,27 @@ function Options({
);
}
const CheckboxFieldLabel = ({ fieldForm }: { fieldForm: UseFormReturn<RhfFormField> }) => {
const { t } = useLocale();
const [firstRender, setFirstRender] = useState(true);
return (
<div className="mt-6">
<Label>{t("label")}</Label>
<Editor
getText={() => md.render(fieldForm.getValues("label") || "")}
setText={(value: string) => {
fieldForm.setValue("label", turndown(value), { shouldDirty: true });
}}
excludedToolbarItems={["blockType", "bold", "italic"]}
disableLists
firstRender={firstRender}
setFirstRender={setFirstRender}
placeholder={t(fieldForm.getValues("defaultLabel") || "")}
/>
</div>
);
};
function FieldEditDialog({
dialog,
onOpenChange,
@@ -437,19 +461,22 @@ function FieldEditDialog({
defaultValues: dialog.data || {},
// resolver: zodResolver(fieldSchema),
});
const formFieldType = fieldForm.getValues("type");
useEffect(() => {
if (!fieldForm.getValues("type")) {
if (!formFieldType) {
return;
}
const variantsConfig = getVariantsConfig({
type: fieldForm.getValues("type"),
type: formFieldType,
variantsConfig: fieldForm.getValues("variantsConfig"),
});
// We need to set the variantsConfig in the RHF instead of using a derived value because RHF won't have the variantConfig for the variant that's not rendered yet.
fieldForm.setValue("variantsConfig", variantsConfig);
}, [fieldForm]);
const isFieldEditMode = !!dialog.data;
const fieldType = getCurrentFieldType(fieldForm);
@@ -458,8 +485,11 @@ function FieldEditDialog({
const fieldTypes = Object.values(fieldTypesConfigMap);
return (
<Dialog open={dialog.isOpen} onOpenChange={onOpenChange}>
<DialogContent className="max-h-none p-0" data-testid="edit-field-dialog">
<Dialog open={dialog.isOpen} onOpenChange={onOpenChange} modal={false}>
<DialogContent
className="max-h-none p-0"
data-testid="edit-field-dialog"
forceOverlayWhenNoModal={true}>
<Form id="form-builder" form={fieldForm} handleSubmit={handleSubmit}>
<div className="h-auto max-h-[85vh] overflow-auto px-8 pb-7 pt-8">
<DialogHeader title={t("add_a_booking_question")} subtitle={t("booking_questions_description")} />
@@ -478,7 +508,7 @@ function FieldEditDialog({
}
fieldForm.setValue("type", value, { shouldDirty: true });
}}
value={fieldTypesConfigMap[fieldForm.getValues("type")]}
value={fieldTypesConfigMap[formFieldType]}
options={fieldTypes.filter((f) => !f.systemOnly)}
label={t("input_type")}
/>
@@ -505,16 +535,22 @@ function FieldEditDialog({
description={t("disable_input_if_prefilled")}
{...fieldForm.register("disableOnPrefill", { setValueAs: Boolean })}
/>
<InputField
{...fieldForm.register("label")}
// System fields have a defaultLabel, so there a label is not required
required={
!["system", "system-but-optional"].includes(fieldForm.getValues("editable") || "")
}
placeholder={t(fieldForm.getValues("defaultLabel") || "")}
containerClassName="mt-6"
label={t("label")}
/>
<div>
{formFieldType === "boolean" ? (
<CheckboxFieldLabel fieldForm={fieldForm} />
) : (
<InputField
{...fieldForm.register("label")}
// System fields have a defaultLabel, so there a label is not required
required={
!["system", "system-but-optional"].includes(fieldForm.getValues("editable") || "")
}
placeholder={t(fieldForm.getValues("defaultLabel") || "")}
containerClassName="mt-6"
label={t("label")}
/>
)}
</div>
{fieldType?.isTextType ? (
<InputField
+13 -3
View File
@@ -145,8 +145,18 @@ export const pageObject = {
}) => {
fireEvent.change(dialog.getAllByRole("textbox")[0], { target: { value: identifier } });
},
fillInFieldLabel: ({ dialog, label }: { dialog: TestingLibraryElement; label: string }) => {
fireEvent.change(dialog.getAllByRole("textbox")[1], { target: { value: label } });
fillInFieldLabel: ({
dialog,
label,
fieldType,
}: {
dialog: TestingLibraryElement;
label: string;
fieldType: string;
}) => {
if (fieldType !== "boolean") {
fireEvent.change(dialog.getAllByRole("textbox")[1], { target: { value: label } });
}
},
close: ({ dialog }: { dialog: TestingLibraryElement }) => {
fireEvent.click(dialog.getByTestId("dialog-rejection"));
@@ -183,7 +193,7 @@ export const verifier = {
const dialog = pageObject.openAddFieldDialog();
pageObject.dialog.selectFieldType({ dialog, fieldType: props.fieldType });
pageObject.dialog.fillInFieldIdentifier({ dialog, identifier: props.identifier });
pageObject.dialog.fillInFieldLabel({ dialog, label: props.label });
pageObject.dialog.fillInFieldLabel({ dialog, label: props.label, fieldType: props.fieldType });
pageObject.dialog.saveField({ dialog: getEditDialogForm() });
await waitFor(() => {