Skip to content

Commit

Permalink
🚚 [#4908] Move relative api endpoint admin field to separate file
Browse files Browse the repository at this point in the history
Will be easier to add new fields
  • Loading branch information
viktorvanwijk committed Dec 19, 2024
1 parent 0ab6dfa commit 0d74a05
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
import {useField} from 'formik';
import PropTypes from 'prop-types';
import React, {useContext} from 'react';
import {FormattedMessage} from 'react-intl';

import Field from 'components/admin/forms/Field';
import Fieldset from 'components/admin/forms/Fieldset';
import FormRow from 'components/admin/forms/FormRow';
import {TextInput} from 'components/admin/forms/Inputs';
import ModalOptionsConfiguration from 'components/admin/forms/ModalOptionsConfiguration';
import {
ValidationErrorContext,
ValidationErrorsProvider,
filterErrors,
} from 'components/admin/forms/ValidationErrors';


const RelativeAPIEndpoint = () => {
// TODO-4098: is this the serializer name?
const [fieldProps] = useField('relativeApiEndpoint');
return (
<FormRow>
<Field
name="relativeApiEndpoint"
label={
<FormattedMessage
description="JSON registration options 'relativeApiEndpoint' label"
defaultMessage="Relative API Endpoint"
/>
}
>
<TextInput id="id_relativeApiEndpoint" {...fieldProps} />
</Field>
</FormRow>
);
};
// TODO-4098: maybe create separate file (JSONOptionsFormFields) for all the fields?
// Though, no need to use multiple FieldSets, so adding the fields to the form is pretty
// straightforward.
import RelativeAPIEndpoint from './fields/RelativeAPIEndpoint';


const JSONOptionsForm = ({name, label, formData, onChange}) => {
Expand Down Expand Up @@ -67,7 +47,7 @@ JSONOptionsForm.propTypes = {
name: PropTypes.string.isRequired,
label: PropTypes.node.isRequired,
formData: PropTypes.shape({
apiEndpoint: PropTypes.string,
relativeApiEndpoint: PropTypes.string,
}),
onChange: PropTypes.func.isRequired,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {useField} from 'formik';
import React from 'react';
import {FormattedMessage} from 'react-intl';

import Field from 'components/admin/forms/Field';
import FormRow from 'components/admin/forms/FormRow';
import {TextInput} from 'components/admin/forms/Inputs';


const RelativeAPIEndpoint = () => {
// TODO-4098: is this the serializer name?
const [fieldProps] = useField('relativeApiEndpoint');
return (
<FormRow>
<Field
name="relativeApiEndpoint"
label={
<FormattedMessage
description="JSON registration options 'relativeApiEndpoint' label"
defaultMessage="Relative API Endpoint"
/>
}
>
<TextInput id="id_relativeApiEndpoint" {...fieldProps} />
</Field>
</FormRow>
);
};

export default RelativeAPIEndpoint;

0 comments on commit 0d74a05

Please sign in to comment.