Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-9590 | FIO-9575: Show api validation errors for form settings block #592

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/components/FormEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useRef, ReactNode } from 'react';
import { useRef, ReactNode, useState } from 'react';
import { FormBuilder as FormioFormBuilder } from '@formio/js';
import { FormBuilder, FormBuilderProps } from './FormBuilder';
import { Form, FormOptions, FormType, FormProps } from './Form';
import { ComponentProp } from './FormGrid';
import { useFormioContext } from '../hooks/useFormioContext';
import { Form as CoreFormType } from '@formio/core';
import Errors from './Errors';

type FormEditProps = {
initialForm?: FormType;
Expand All @@ -27,6 +28,10 @@ type FormEditProps = {
};
};

type ErrorObject = {
[key: string]: unknown;
};

const DEFAULT_INITAL_FORM = {
title: '',
name: '',
Expand Down Expand Up @@ -190,6 +195,7 @@ export const FormEdit = ({
onBuilderReady,
}: FormEditProps) => {
const { Formio } = useFormioContext();
const [error, setError] = useState<ErrorObject | null>(null);
const {
Container = ({ children }) => <div>{children}</div>,
SettingsFormContainer = ({ children }) => <div>{children}</div>,
Expand Down Expand Up @@ -232,6 +238,7 @@ export const FormEdit = ({
onSaveForm?.(form);
} catch (error) {
console.error('Error saving form', error);
setError(error as ErrorObject) ;
}
};

Expand All @@ -251,10 +258,10 @@ export const FormEdit = ({
options={settingsFormOptions}
submission={{
data: {
title: initialForm.title,
name: initialForm.name,
path: initialForm.path,
display: initialForm.display,
title: settingsFormData.current.title,
name: settingsFormData.current.name,
path: settingsFormData.current.path,
display: settingsFormData.current.display,
},
}}
onChange={({ changed, data }, flags, modified) => {
Expand All @@ -266,6 +273,7 @@ export const FormEdit = ({
}
}}
/>
{error && <Errors type="error" errors={error} />}
</SettingsFormContainer>
<BuilderContainer>
<FormBuilder
Expand Down