diff --git a/src/Events/EventStatuses/Form/index.js b/src/Events/EventStatuses/Form/index.js
deleted file mode 100644
index 8bf09a35..00000000
--- a/src/Events/EventStatuses/Form/index.js
+++ /dev/null
@@ -1,165 +0,0 @@
-import { reduxActions } from '@codetanzania/ewea-api-states';
-import { Form } from '@ant-design/compatible';
-import '@ant-design/compatible/assets/index.css';
-import { Button, Input } from 'antd';
-import PropTypes from 'prop-types';
-import React, { Component } from 'react';
-import { notifyError, notifySuccess } from '../../../util';
-
-/* constants */
-const { TextArea } = Input;
-const { postEventStatus, putEventStatus } = reduxActions;
-
-/**
- * @class
- * @name EventStatusForm
- * @description Render React Form
- *
- * @version 0.1.0
- * @since 0.1.0
- */
-class EventStatusForm extends Component {
- /**
- * @function
- * @name handleSubmit
- * @description Handle form submit action
- *
- * @param {object} event onSubmit event
- *
- * @version 0.1.0
- * @since 0.1.0
- */
- handleSubmit = (event) => {
- event.preventDefault();
-
- const {
- form: { validateFieldsAndScroll },
- eventStatus,
- isEditForm,
- } = this.props;
-
- validateFieldsAndScroll((error, values) => {
- if (!error) {
- if (isEditForm) {
- const updatedEventStatus = { ...eventStatus, ...values };
- putEventStatus(
- updatedEventStatus,
- () => {
- notifySuccess('Event status was updated successfully');
- },
- () => {
- notifyError(
- 'Something occurred while updating event status, please try again!'
- );
- }
- );
- } else {
- postEventStatus(
- values,
- () => {
- notifySuccess('Event status was created successfully');
- },
- () => {
- notifyError(
- 'Something occurred while saving event status, please try again!'
- );
- }
- );
- }
- }
- });
- };
-
- render() {
- const {
- isEditForm,
- eventStatus,
- posting,
- onCancel,
- form: { getFieldDecorator },
- } = this.props;
-
- const formItemLayout = {
- labelCol: {
- xs: { span: 24 },
- sm: { span: 24 },
- md: { span: 24 },
- lg: { span: 24 },
- xl: { span: 24 },
- xxl: { span: 24 },
- },
- wrapperCol: {
- xs: { span: 24 },
- sm: { span: 24 },
- md: { span: 24 },
- lg: { span: 24 },
- xl: { span: 24 },
- xxl: { span: 24 },
- },
- };
-
- return (
-
- {getFieldDecorator('strings.name.en', {
- initialValue: isEditForm ? eventStatus.strings.name.en : undefined,
- rules: [
- { required: true, message: 'Event status name is required' },
- ],
- })()}
-
- {/* end event status name */}
-
- {/* event status description */}
- {/* eslint-disable-next-line react/jsx-props-no-spreading */}
-
- {getFieldDecorator('strings.description.en', {
- initialValue: isEditForm
- ? eventStatus.strings.description.en
- : undefined,
- })()}
-
- {/* end event status description */}
-
- {/* form actions */}
-
-
-
-
- {/* end form actions */}
-
- );
- }
-}
-
-EventStatusForm.propTypes = {
- isEditForm: PropTypes.bool.isRequired,
- eventStatus: PropTypes.shape({
- strings: PropTypes.shape({
- name: PropTypes.shape({ en: PropTypes.string }),
- abbreviation: PropTypes.shape({ en: PropTypes.string }),
- description: PropTypes.shape({ en: PropTypes.string }),
- }),
- }),
- form: PropTypes.shape({
- getFieldDecorator: PropTypes.func,
- validateFieldsAndScroll: PropTypes.func,
- }).isRequired,
- onCancel: PropTypes.func.isRequired,
- posting: PropTypes.bool.isRequired,
-};
-
-EventStatusForm.defaultProps = {
- eventStatus: null,
-};
-
-export default Form.create()(EventStatusForm);
diff --git a/src/Events/EventStatuses/index.js b/src/Events/EventStatuses/index.js
index 0837fa4b..cd551f99 100644
--- a/src/Events/EventStatuses/index.js
+++ b/src/Events/EventStatuses/index.js
@@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import NotificationForm from '../../components/NotificationForm';
import Topbar from '../../components/Topbar';
-import EventStatusForm from './Form';
+import SettingForm from '../../components/SettingForm';
import ListItemActions from '../../components/ListItemActions';
import ListItem from '../../components/ListItem';
import ItemList from '../../components/List';
@@ -33,6 +33,8 @@ const {
refreshEventStatuses,
paginateEventStatuses,
deleteEventStatus,
+ postEventStatus,
+ putEventStatus,
} = reduxActions;
const nameSpan = { xxl: 4, xl: 5, lg: 6, md: 7, sm: 0, xs: 0 };
@@ -202,6 +204,7 @@ class EventStatuses extends Component {
* @since 0.1.0
*/
handleAfterCloseForm = () => {
+ selectEventStatus(null);
this.setState({ isEditForm: false });
};
@@ -383,11 +386,12 @@ class EventStatuses extends Component {
maskClosable={false}
afterClose={this.handleAfterCloseForm}
>
-
{/* end create/edit form modal */}
diff --git a/src/components/SettingForm/index.js b/src/components/SettingForm/index.js
new file mode 100644
index 00000000..4ac8c055
--- /dev/null
+++ b/src/components/SettingForm/index.js
@@ -0,0 +1,126 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Button, Input, Form } from 'antd';
+import get from 'lodash/get';
+
+import { notifyError, notifySuccess } from '../../util';
+
+const { TextArea } = Input;
+const formItemLayout = {
+ labelCol: {
+ xs: { span: 24 },
+ sm: { span: 24 },
+ md: { span: 24 },
+ lg: { span: 24 },
+ xl: { span: 24 },
+ xxl: { span: 24 },
+ },
+ wrapperCol: {
+ xs: { span: 24 },
+ sm: { span: 24 },
+ md: { span: 24 },
+ lg: { span: 24 },
+ xl: { span: 24 },
+ xxl: { span: 24 },
+ },
+};
+
+/**
+ * @function
+ * @name SettingForm
+ * @description Form for creating and editing settings
+ * @param {object} props Properties object
+ * @param {object|null} props.setting Setting object to be edited
+ * @param {boolean} props.posting Flag for showing spinner while posting
+ * @param {Function} props.onCancel On Cancel form callback
+ * @param {Function} props.onCreate On Create setting callback function
+ * @param {Function} props.onUpdate onUpdate setting callback function
+ * @returns {object} Setting Form
+ * @version 0.1.0
+ * @since 0.1.0
+ */
+const SettingForm = ({ setting, posting, onCancel, onCreate, onUpdate }) => {
+ const onFinish = (values) => {
+ if (get(setting, '_id')) {
+ const updatedSetting = { ...setting, ...values };
+ onUpdate(
+ updatedSetting,
+ () => notifySuccess('Setting was updated successfully'),
+ () =>
+ notifyError(
+ 'An error occurred while updating setting, please contact your system administrator'
+ )
+ );
+
+ return;
+ }
+
+ onCreate(
+ values,
+ () => notifySuccess('Setting was created successfully'),
+ () =>
+ notifyError(
+ 'An error occurred while saving setting, please contact your system administrator'
+ )
+ );
+ };
+
+ return (
+
+
+
+ {/* end setting name */}
+
+ {/* setting description */}
+
+
+
+ {/* end setting description */}
+
+ {/* form actions */}
+
+
+
+
+ {/* end form actions */}
+
+ );
+};
+
+SettingForm.propTypes = {
+ setting: PropTypes.shape({
+ strings: PropTypes.shape({
+ name: PropTypes.shape({ en: PropTypes.string }),
+ abbreviation: PropTypes.shape({ en: PropTypes.string }),
+ description: PropTypes.shape({ en: PropTypes.string }),
+ }),
+ }),
+ onCancel: PropTypes.func.isRequired,
+ onCreate: PropTypes.func.isRequired,
+ onUpdate: PropTypes.func.isRequired,
+ posting: PropTypes.bool.isRequired,
+};
+
+SettingForm.defaultProps = {
+ setting: null,
+};
+
+export default SettingForm;