🧲 New features Custom user role permissions Employee edit form updated Employee daily task list Attendance and employee distribution charts on dashboard Improvements to company structure and company assets module Improved tables for displaying data in several modules Faster data loading (specially for employee module) Initials based profile pictures Re-designed login page Re-designed user profile page Improvements to filtering New REST endpoints for employee qualifications 🐛 Bug fixes Fixed, issue with managers being able to create performance reviews for employees who are not their direct reports Fixed, issues related to using full profile image instead of using smaller version of profile image Changing third gender to other Improvements and fixes for internal frontend data caching
151 lines
3.9 KiB
JavaScript
151 lines
3.9 KiB
JavaScript
import React from 'react';
|
|
import {
|
|
Button, Col, Modal, Row, Space,
|
|
} from 'antd';
|
|
import IceForm from './IceForm';
|
|
|
|
class IceFormModal extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
visible: false,
|
|
viewOnly: false,
|
|
loading: false,
|
|
};
|
|
this.iceFormReference = React.createRef();
|
|
this.width = 800;
|
|
}
|
|
|
|
setViewOnly(value) {
|
|
this.setState({ viewOnly: value });
|
|
}
|
|
|
|
show(data) {
|
|
if (!data) {
|
|
this.setState({ visible: true });
|
|
if (this.iceFormReference.current) {
|
|
this.iceFormReference.current.resetFields();
|
|
}
|
|
} else {
|
|
this.setState({ visible: true });
|
|
if (this.iceFormReference.current && this.iceFormReference.current.isReady()) {
|
|
this.iceFormReference.current.updateFields(data);
|
|
} else {
|
|
this.waitForIt(
|
|
() => this.iceFormReference.current && this.iceFormReference.current.isReady(),
|
|
() => { this.iceFormReference.current.updateFields(data); },
|
|
1000,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
waitForIt(condition, callback, time) {
|
|
setTimeout(() => {
|
|
if (condition()) {
|
|
callback();
|
|
} else {
|
|
this.waitForIt(condition, callback, time);
|
|
}
|
|
}, time);
|
|
}
|
|
|
|
hide() {
|
|
this.setState({ visible: false });
|
|
}
|
|
|
|
save(params) {
|
|
this.iceFormReference.current.save(params, () => { this.closeModal(); });
|
|
}
|
|
|
|
closeModal() {
|
|
this.hide();
|
|
this.iceFormReference.current.showError(false);
|
|
}
|
|
|
|
render() {
|
|
const {
|
|
fields, adapter, saveCallback, cancelCallback,
|
|
} = this.props;
|
|
|
|
const additionalProps = {};
|
|
additionalProps.footer = (
|
|
<Row gutter={16}>
|
|
<Col className="gutter-row" span={12} style={{}} />
|
|
<Col className="gutter-row" span={12} style={{ textAlign: 'right' }}>
|
|
<Space>
|
|
<Button onClick={() => {
|
|
if (cancelCallback) {
|
|
cancelCallback();
|
|
} else {
|
|
this.closeModal();
|
|
}
|
|
}}
|
|
>
|
|
{this.props.adapter.gt('Cancel')}
|
|
</Button>
|
|
<Button
|
|
loading={this.state.loading}
|
|
type="primary"
|
|
onClick={() => {
|
|
this.setState({ loading: true });
|
|
const iceFrom = this.iceFormReference.current;
|
|
iceFrom
|
|
.validateFields()
|
|
.then((values) => {
|
|
if (!iceFrom.isValid()) {
|
|
this.setState({ loading: false });
|
|
return;
|
|
}
|
|
if (saveCallback) {
|
|
saveCallback(values, iceFrom.showError.bind(this), this.closeModal.bind(this));
|
|
} else {
|
|
this.save(values);
|
|
}
|
|
this.setState({ loading: false });
|
|
})
|
|
.catch((info) => {
|
|
this.setState({ loading: false });
|
|
});
|
|
}}
|
|
>
|
|
{this.state.viewOnly ? this.props.adapter.gt('Done') : this.props.adapter.gt('Save')}
|
|
</Button>
|
|
</Space>
|
|
</Col>
|
|
</Row>
|
|
);
|
|
|
|
if (this.state.viewOnly) {
|
|
additionalProps.footer = null;
|
|
}
|
|
|
|
return (
|
|
<Modal
|
|
visible={this.state.visible}
|
|
title={this.props.adapter.gt(this.props.title || adapter.objectTypeName)}
|
|
maskClosable={false}
|
|
width={this.width}
|
|
onCancel={() => {
|
|
if (cancelCallback) {
|
|
cancelCallback();
|
|
} else {
|
|
this.closeModal();
|
|
}
|
|
}}
|
|
{...additionalProps}
|
|
>
|
|
<IceForm
|
|
ref={this.iceFormReference}
|
|
adapter={adapter}
|
|
fields={fields}
|
|
viewOnly={this.state.viewOnly}
|
|
/>
|
|
</Modal>
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
export default IceFormModal;
|