Skip to content

Commit

Permalink
feat: add static fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nzambello committed Mar 16, 2021
1 parent 2e3e54a commit 746e62e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 16 additions & 4 deletions src/components/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,22 @@ const formStateReducer = (state, action) => {
const Form = ({ data, id, path }) => {
const intl = useIntl();
const dispatch = useDispatch();

const [formData, setFormData] = useReducer((state, action) => {
return { ...state, [action.field]: action.value };
}, {});
const { static_fields = [] } = data;

const [formData, setFormData] = useReducer(
(state, action) => {
return {
...state,
[action.field]: action.value,
};
},
{
...static_fields.reduce(
(acc, field) => ({ ...acc, [getFieldName(field.label)]: field }),
{},
),
},
);

const [formState, setFormState] = useReducer(formStateReducer, initialState);
const [formErrors, setFormErrors] = useState([]);
Expand Down
6 changes: 1 addition & 5 deletions src/components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import {
Dimmer,
Loader,
} from 'semantic-ui-react';
import {
defineMessages,
useIntl,
FormattedMessage,
} from 'react-intl';
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';

import {
Icon,
Expand Down

0 comments on commit 746e62e

Please sign in to comment.