Add support for flash messages utilizing redux
This commit is contained in:
parent
b93b40ba31
commit
435626f4b7
15 changed files with 268 additions and 34 deletions
38
resources/scripts/components/FlashMessageRender.tsx
Normal file
38
resources/scripts/components/FlashMessageRender.tsx
Normal file
|
@ -0,0 +1,38 @@
|
|||
import * as React from 'react';
|
||||
import { FlashMessage, ReduxState } from '@/redux/types';
|
||||
import { connect } from 'react-redux';
|
||||
import MessageBox from '@/components/MessageBox';
|
||||
|
||||
type Props = Readonly<{
|
||||
flashes: FlashMessage[];
|
||||
}>;
|
||||
|
||||
class FlashMessageRender extends React.PureComponent<Props> {
|
||||
render () {
|
||||
if (this.props.flashes.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
{
|
||||
this.props.flashes.map(flash => (
|
||||
<MessageBox
|
||||
key={flash.id || flash.type + flash.message}
|
||||
type={flash.type}
|
||||
title={flash.title}
|
||||
>
|
||||
{flash.message}
|
||||
</MessageBox>
|
||||
))
|
||||
}
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state: ReduxState) => ({
|
||||
flashes: state.flashes,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(FlashMessageRender);
|
Loading…
Add table
Add a link
Reference in a new issue