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-06-12 06:12:03 +00:00
|
|
|
}>;
|
|
|
|
|
2020-07-03 21:19:05 +00:00
|
|
|
export default ({ 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 (
|
2020-07-03 21:19:05 +00:00
|
|
|
<div>
|
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}>
|
2020-07-03 21:19:05 +00:00
|
|
|
{index > 0 && <div css={tw`${spacerClass || 'mt-2'}`}></div>}
|
2019-06-22 23:45:51 +00:00
|
|
|
<MessageBox type={flash.type} title={flash.title}>
|
|
|
|
{flash.message}
|
|
|
|
</MessageBox>
|
|
|
|
</React.Fragment>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|