2017-10-17 09:35:41 -04:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Components } from 'meteor/vulcan:core';
|
|
|
|
import { registerComponent } from 'meteor/vulcan:core';
|
|
|
|
import { FormattedMessage } from 'meteor/vulcan:i18n';
|
|
|
|
|
|
|
|
const FormSubmit = ({
|
2018-03-22 16:54:50 +09:00
|
|
|
submitLabel,
|
|
|
|
cancelLabel,
|
|
|
|
cancelCallback,
|
2018-05-08 20:09:42 -04:00
|
|
|
revertLabel,
|
|
|
|
revertCallback,
|
2018-03-22 16:54:50 +09:00
|
|
|
document,
|
|
|
|
deleteDocument,
|
|
|
|
collectionName,
|
|
|
|
classes,
|
2018-05-08 20:09:42 -04:00
|
|
|
}, {
|
|
|
|
isChanged,
|
|
|
|
clearForm,
|
2018-03-22 16:54:50 +09:00
|
|
|
}) => (
|
2017-10-17 09:35:41 -04:00
|
|
|
<div className="form-submit">
|
2018-04-23 09:47:04 +09:00
|
|
|
<Components.Button type="submit" variant="primary">
|
2018-03-22 16:54:50 +09:00
|
|
|
{submitLabel ? submitLabel : <FormattedMessage id="forms.submit" />}
|
2018-04-23 09:47:04 +09:00
|
|
|
</Components.Button>
|
2018-03-22 16:54:50 +09:00
|
|
|
|
|
|
|
{cancelCallback ? (
|
|
|
|
<a
|
|
|
|
className="form-cancel"
|
|
|
|
onClick={e => {
|
2017-10-17 09:35:41 -04:00
|
|
|
e.preventDefault();
|
|
|
|
cancelCallback(document);
|
2018-03-22 16:54:50 +09:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{cancelLabel ? cancelLabel : <FormattedMessage id="forms.cancel" />}
|
|
|
|
</a>
|
|
|
|
) : null}
|
2018-05-08 20:09:42 -04:00
|
|
|
|
|
|
|
{revertCallback ? (
|
|
|
|
<a
|
|
|
|
className="form-cancel"
|
|
|
|
onClick={e => {
|
|
|
|
e.preventDefault();
|
|
|
|
clearForm({ clearErrors: true, clearCurrentValues: true, clearDeletedValues: true });
|
|
|
|
revertCallback(document);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{revertLabel ? revertLabel : <FormattedMessage id="forms.revert"/>}
|
|
|
|
</a>
|
|
|
|
) : null}
|
|
|
|
|
2018-03-22 16:54:50 +09:00
|
|
|
{deleteDocument ? (
|
|
|
|
<div>
|
|
|
|
<hr />
|
2018-05-01 16:02:31 -03:00
|
|
|
<a href="javascript:void(0)" onClick={deleteDocument} className={`delete-link ${collectionName}-delete-link`}>
|
2018-03-22 16:54:50 +09:00
|
|
|
<Components.Icon name="close" /> <FormattedMessage id="forms.delete" />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
) : null}
|
2017-10-17 09:35:41 -04:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
FormSubmit.propTypes = {
|
|
|
|
submitLabel: PropTypes.string,
|
|
|
|
cancelLabel: PropTypes.string,
|
|
|
|
cancelCallback: PropTypes.func,
|
2018-05-08 20:09:42 -04:00
|
|
|
revertLabel: PropTypes.string,
|
|
|
|
revertCallback: PropTypes.func,
|
2017-10-17 09:35:41 -04:00
|
|
|
document: PropTypes.object,
|
|
|
|
deleteDocument: PropTypes.func,
|
|
|
|
collectionName: PropTypes.string,
|
|
|
|
classes: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2018-05-08 20:09:42 -04:00
|
|
|
FormSubmit.contextTypes = {
|
|
|
|
isChanged: PropTypes.func,
|
|
|
|
clearForm: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-10-17 09:35:41 -04:00
|
|
|
registerComponent('FormSubmit', FormSubmit);
|