Skip to content

Commit

Permalink
Merge pull request #41 from bleu-fi/joao/perk-1082-integrate-media-li…
Browse files Browse the repository at this point in the history
…brary-with-buildforms

Integrate media library with buildforms
  • Loading branch information
devjoaov authored Mar 21, 2024
2 parents 0ad7d5b + 30b6ef3 commit b971eff
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 166 deletions.
10 changes: 8 additions & 2 deletions src/components/FormBuilder/buildForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { BaseField, CommonFieldProps, fieldComponents } from "./index";

type FieldComponentType = (
export type FieldComponentType = (
props: CommonFieldProps<BaseField>
) => React.ReactNode | null;

Expand Down Expand Up @@ -31,7 +31,13 @@ export function buildForm(

const name = field.name.replace("RESOURCE_ID", String(index));

return <FieldComponent field={{ ...field, name, index }} form={form} />;
return (
<FieldComponent
field={{ ...field, name, index }}
form={form}
customComponents={customComponents}
/>
);
});

return formElements;
Expand Down
3 changes: 0 additions & 3 deletions src/components/FormBuilder/builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { HiddenField } from "./fields/HiddenField";
import { FileUploadField } from "./fields/FileUploadField";
import { InputField } from "./fields/InputField";
import { MultiSelectCheckboxes } from "./fields/MultiSelectCheckboxesField";

import { RadioGroupField } from "./fields/RadioGroupField";
import { RichTextEditorField } from "./fields/RichTextEditorField";
import { ColorPickerField } from "./fields/selects/ColorPickerField";
Expand All @@ -16,7 +15,6 @@ import { SelectField } from "./fields/selects/SelectField";
import { SwitchField } from "./fields/SwitchField";
import { TextAreaField } from "./fields/TextAreaField";
import { DelegateField } from "./fields/DelegateField";
import { QuestionsField } from "./fields/QuestionsField";

export const fieldComponents = {
input: InputField,
Expand All @@ -31,7 +29,6 @@ export const fieldComponents = {
multi_select: MultiSelect,
field_array: FieldArray,
hidden: HiddenField,
questions: QuestionsField,
wysiwyg: RichTextEditorField,
multi_select_checkbox: MultiSelectCheckboxes,
color_picker: ColorPickerField,
Expand Down
4 changes: 2 additions & 2 deletions src/components/FormBuilder/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { CheckboxFieldProps } from "./fields/CheckboxField";
import { DatePickerInputProps } from "./fields/DatePickerInput";
import { FileUploadFieldProps } from "./fields/FileUploadField";
import { InputFieldProps } from "./fields/InputField";
import { QuestionsFieldProps } from "./fields/QuestionsField";
import { RadioGroupFieldProps } from "./fields/RadioGroupField";
import { RichTextEditorFieldProps } from "./fields/RichTextEditorField";
import { SelectFieldProps } from "./fields/selects/SelectField";
import { TextAreaFieldProps } from "./fields/TextAreaField";
import { FieldArrayFieldProps } from "./fields/FieldArray";
import { FieldComponentType } from "./buildForm";

export interface BaseField {
component?: React.ComponentType<CommonFieldProps<BaseField>>;
Expand All @@ -33,6 +33,7 @@ export interface BaseField {
}

export interface CommonFieldProps<T extends BaseField> {
customComponents?: { [key: string]: FieldComponentType };
field: T;
form: UseFormReturn<FieldValues>;
}
Expand Down Expand Up @@ -98,6 +99,5 @@ export type FormFieldProps =
| FileUploadFieldProps
| SelectFieldProps
| RadioGroupFieldProps
| QuestionsFieldProps
| RichTextEditorFieldProps
| FieldArrayFieldProps;
9 changes: 7 additions & 2 deletions src/components/FormBuilder/fields/FieldArray.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface FieldArrayFieldProps extends BaseField {
}

export const FieldArray = withConditional<FieldArrayFieldProps>(
({ form, field }) => {
({ form, field, customComponents }) => {
const { fields, append, remove, move } = useFieldArray({
control: form.control,
name: field.name,
Expand Down Expand Up @@ -157,7 +157,12 @@ export const FieldArray = withConditional<FieldArrayFieldProps>(
<MoveIcon className="size-6 self-center" />
</div>
)}
{buildForm(field.fields, form, Number(index))}
{buildForm(
field.fields,
form,
Number(index),
customComponents
)}
{field.remove !== false && (
// eslint-disable-next-line jsx-a11y/control-has-associated-label
<button
Expand Down
156 changes: 0 additions & 156 deletions src/components/FormBuilder/fields/QuestionsField.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/FormBuilder/fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export * from "./HiddenField";
export * from "./FileUploadField";
export * from "./InputField";
export * from "./MultiSelectCheckboxesField";
export * from "./QuestionsField";
export * from "./RadioGroupField";
export * from "./RichTextEditorField";
export * from "./SwitchField";
Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from "./RailsApp";
export * from "./SectionTitle";
export * from "./OtpInput";
export * from "./SubmitButton";
export * from "./StrictModeDroppable";

0 comments on commit b971eff

Please sign in to comment.