mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Improve edit/new buttons callback handling
This commit is contained in:
parent
ceabbc1314
commit
5705de3559
2 changed files with 51 additions and 27 deletions
|
@ -3,16 +3,21 @@ import React from 'react';
|
|||
import Button from 'react-bootstrap/lib/Button';
|
||||
import { FormattedMessage, intlShape } from 'meteor/vulcan:i18n';
|
||||
|
||||
const EditButton = ({ style = 'primary', size, ...props }, {intl}) =>
|
||||
<Components.ModalTrigger
|
||||
label={intl.formatMessage({id: 'datatable.edit'})}
|
||||
component={<Button bsSize={size} bsStyle={style}><FormattedMessage id="datatable.edit" /></Button>}
|
||||
const EditButton = ({ style = 'primary', size, ...props }, { intl }) => (
|
||||
<Components.ModalTrigger
|
||||
label={intl.formatMessage({ id: 'datatable.edit' })}
|
||||
component={
|
||||
<Button bsSize={size} bsStyle={style}>
|
||||
<FormattedMessage id="datatable.edit" />
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Components.EditForm {...props} />
|
||||
</Components.ModalTrigger>
|
||||
);
|
||||
|
||||
EditButton.contextTypes = {
|
||||
intl: intlShape
|
||||
intl: intlShape,
|
||||
};
|
||||
|
||||
EditButton.displayName = 'EditButton';
|
||||
|
@ -24,14 +29,24 @@ registerComponent('EditButton', EditButton);
|
|||
EditForm Component
|
||||
|
||||
*/
|
||||
const EditForm = ({ closeModal, ...props }) =>
|
||||
<Components.SmartForm
|
||||
successCallback={document => {
|
||||
closeModal();
|
||||
}}
|
||||
removeSuccessCallback={document => {
|
||||
closeModal();
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
const EditForm = ({ closeModal, successCallback, removeSuccessCallback, ...props }) => {
|
||||
|
||||
const success = successCallback
|
||||
? () => {
|
||||
successCallback();
|
||||
closeModal();
|
||||
}
|
||||
: closeModal;
|
||||
|
||||
const remove = removeSuccessCallback
|
||||
? () => {
|
||||
removeSuccessCallback();
|
||||
closeModal();
|
||||
}
|
||||
: closeModal;
|
||||
|
||||
return (
|
||||
<Components.SmartForm successCallback={success} removeSuccessCallback={remove} {...props} />
|
||||
);
|
||||
};
|
||||
registerComponent('EditForm', EditForm);
|
||||
|
|
|
@ -3,16 +3,21 @@ import React from 'react';
|
|||
import Button from 'react-bootstrap/lib/Button';
|
||||
import { FormattedMessage, intlShape } from 'meteor/vulcan:i18n';
|
||||
|
||||
const NewButton = ({ collection, size, style = 'primary', ...props }, {intl}) =>
|
||||
<Components.ModalTrigger
|
||||
label={intl.formatMessage({id: 'datatable.new'})}
|
||||
component={<Button bsStyle={style} bsSize={size}><FormattedMessage id="datatable.new" /></Button>}
|
||||
const NewButton = ({ collection, size, style = 'primary', ...props }, { intl }) => (
|
||||
<Components.ModalTrigger
|
||||
label={intl.formatMessage({ id: 'datatable.new' })}
|
||||
component={
|
||||
<Button bsStyle={style} bsSize={size}>
|
||||
<FormattedMessage id="datatable.new" />
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Components.NewForm collection={collection} {...props} />
|
||||
</Components.ModalTrigger>
|
||||
);
|
||||
|
||||
NewButton.contextTypes = {
|
||||
intl: intlShape
|
||||
intl: intlShape,
|
||||
};
|
||||
|
||||
NewButton.displayName = 'NewButton';
|
||||
|
@ -24,11 +29,15 @@ registerComponent('NewButton', NewButton);
|
|||
NewForm Component
|
||||
|
||||
*/
|
||||
const NewForm = ({ closeModal, ...props }) =>
|
||||
<Components.SmartForm
|
||||
successCallback={document => {
|
||||
closeModal();
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
const NewForm = ({ closeModal, successCallback, ...props }) => {
|
||||
|
||||
const success = successCallback
|
||||
? () => {
|
||||
successCallback();
|
||||
closeModal();
|
||||
}
|
||||
: closeModal;
|
||||
|
||||
return <Components.SmartForm successCallback={success} {...props} />;
|
||||
};
|
||||
registerComponent('NewForm', NewForm);
|
||||
|
|
Loading…
Add table
Reference in a new issue