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';
|
2020-07-04 21:21:28 +00:00
|
|
|
import { useStoreState } from 'easy-peasy';
|
2020-07-04 19:39:55 +00:00
|
|
|
import tw from 'twin.macro';
|
2019-06-12 06:12:03 +00:00
|
|
|
|
|
|
|
type Props = Readonly<{
|
2019-06-23 06:45:09 +00:00
|
|
|
byKey?: string;
|
2020-07-04 21:21:28 +00:00
|
|
|
className?: string;
|
2019-06-12 06:12:03 +00:00
|
|
|
}>;
|
|
|
|
|
2020-07-04 21:21:28 +00:00
|
|
|
const FlashMessageRender = ({ byKey, className }: Props) => {
|
|
|
|
const flashes = useStoreState(state => state.flashes.items.filter(
|
|
|
|
flash => byKey ? flash.key === byKey : true,
|
|
|
|
));
|
2019-06-12 06:12:03 +00:00
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
return (
|
2020-07-04 23:26:07 +00:00
|
|
|
flashes.length ?
|
|
|
|
<div className={className}>
|
|
|
|
{
|
|
|
|
flashes.map((flash, index) => (
|
|
|
|
<React.Fragment key={flash.id || flash.type + flash.message}>
|
2020-12-31 03:18:56 +00:00
|
|
|
{index > 0 && <div css={tw`mt-2`}/>}
|
2020-07-04 23:26:07 +00:00
|
|
|
<MessageBox type={flash.type} title={flash.title}>
|
|
|
|
{flash.message}
|
|
|
|
</MessageBox>
|
|
|
|
</React.Fragment>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
:
|
|
|
|
null
|
2019-06-22 23:45:51 +00:00
|
|
|
);
|
|
|
|
};
|
2020-07-04 21:21:28 +00:00
|
|
|
|
|
|
|
export default FlashMessageRender;
|