Skip to content

Commit

Permalink
Merge pull request #2089 from lbke/apollo2-withMessages
Browse files Browse the repository at this point in the history
Apollo2 withMessages
  • Loading branch information
Eric Burel authored Sep 28, 2018
2 parents fd26020 + e8a62d9 commit 90d0e0c
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 55 deletions.
86 changes: 68 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@babel/runtime": "7.0.0-beta.55",
"analytics-node": "^2.1.1",
"apollo-cache-inmemory": "^1.2.10",
"apollo-client": "^2.0.4",
"apollo-client": "^2.4.2",
"apollo-engine": "^0.5.4",
"apollo-errors": "^1.4.0",
"apollo-link-state": "^0.4.2",
Expand Down Expand Up @@ -61,7 +61,7 @@
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-addons-pure-render-mixin": "^15.4.1",
"react-apollo": "^2.0.4",
"react-apollo": "^2.2.1",
"react-bootstrap": "^0.32.0",
"react-bootstrap-datetimepicker": "0.0.22",
"react-cookie": "^2.1.4",
Expand Down
45 changes: 30 additions & 15 deletions packages/vulcan-core/lib/modules/components/Flash.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import PropTypes from 'prop-types';
import { intlShape } from 'meteor/vulcan:i18n';

class Flash extends PureComponent {

constructor() {
super();
this.dismissFlash = this.dismissFlash.bind(this);
Expand All @@ -27,52 +26,68 @@ class Flash extends PureComponent {
return {
message: errorObject,
type: 'error'
}
};
} else {
// else return full error object after internationalizing message
const { id, message, properties } = errorObject;
const translatedMessage = this.context.intl.formatMessage({ id, defaultMessage: message }, properties);
const translatedMessage = this.context.intl.formatMessage(
{ id, defaultMessage: message },
properties
);
return {
...errorObject,
message: translatedMessage,
message: translatedMessage
};
}
}
};

render() {

const { message, type } = this.getProperties();
const flashType = type === 'error' ? 'danger' : type; // if flashType is "error", use "danger" instead

return (
<Components.Alert className="flash-message" variant={flashType} onDismiss={this.dismissFlash}>
<Components.Alert
className="flash-message"
variant={flashType}
onDismiss={this.dismissFlash}
>
{message}
</Components.Alert>
)
);
}
}

Flash.propTypes = {
message: PropTypes.object.isRequired
}
message: PropTypes.object.isRequired,
markAsSeen: PropTypes.func.isRequired,
clear: PropTypes.func.isRequired
};

Flash.contextTypes = {
intl: intlShape
};

registerComponent('Flash', Flash);

const FlashMessages = ({messages, clear, markAsSeen}) => {
const FlashMessages = ({ messages, clear, markAsSeen }) => {
return (
<div className="flash-messages">
{messages
.filter(message => message.show)
.map(message => <Components.Flash key={message._id} message={message} clear={clear} markAsSeen={markAsSeen} />)}
{messages.filter(message => message.show).map(message => (
<Components.Flash
key={message._id}
message={message}
clear={clear}
markAsSeen={markAsSeen}
/>
))}
</div>
);
}
};

FlashMessages.displayName = 'FlashMessages';
FlashMessages.propTypes = {
messages: PropTypes.array.isRequired
};

registerComponent('FlashMessages', FlashMessages, withMessages);

Expand Down
Loading

0 comments on commit 90d0e0c

Please sign in to comment.