2019-06-22 23:45:51 +00:00
|
|
|
import React from 'react';
|
2019-06-12 06:12:03 +00:00
|
|
|
import MessageBox from '@/components/MessageBox';
|
2019-06-22 23:45:51 +00:00
|
|
|
import { State, useStoreState } from 'easy-peasy';
|
2019-07-10 04:25:57 +00:00
|
|
|
import { ApplicationStore } from '@/state';
|
2019-06-12 06:12:03 +00:00
|
|
|
|
|
|
|
type Props = Readonly<{
|
2019-06-23 06:45:09 +00:00
|
|
|
byKey?: string;
|
2019-06-16 23:57:57 +00:00
|
|
|
spacerClass?: string;
|
2019-07-17 05:15:14 +00:00
|
|
|
className?: string;
|
2019-06-12 06:12:03 +00:00
|
|
|
}>;
|
|
|
|
|
2019-07-17 05:15:14 +00:00
|
|
|
export default ({ className, spacerClass, byKey }: Props) => {
|
2019-07-10 04:25:57 +00:00
|
|
|
const flashes = useStoreState((state: State<ApplicationStore>) => state.flashes.items);
|
2019-06-12 06:12:03 +00:00
|
|
|
|
2019-06-23 06:45:09 +00:00
|
|
|
let filtered = flashes;
|
|
|
|
if (byKey) {
|
|
|
|
filtered = flashes.filter(flash => flash.key === byKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filtered.length === 0) {
|
2019-06-22 23:45:51 +00:00
|
|
|
return null;
|
2019-06-12 06:12:03 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
return (
|
2019-07-17 05:15:14 +00:00
|
|
|
<div className={className}>
|
2019-06-22 23:45:51 +00:00
|
|
|
{
|
2019-06-23 06:45:09 +00:00
|
|
|
filtered.map((flash, index) => (
|
2019-06-22 23:45:51 +00:00
|
|
|
<React.Fragment key={flash.id || flash.type + flash.message}>
|
|
|
|
{index > 0 && <div className={spacerClass || 'mt-2'}></div>}
|
|
|
|
<MessageBox type={flash.type} title={flash.title}>
|
|
|
|
{flash.message}
|
|
|
|
</MessageBox>
|
|
|
|
</React.Fragment>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|