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) => {
|
2022-06-26 19:13:52 +00:00
|
|
|
const flashes = useStoreState((state) =>
|
|
|
|
state.flashes.items.filter((flash) => (byKey ? flash.key === byKey : true))
|
2019-06-22 23:45:51 +00:00
|
|
|
);
|
2022-06-26 19:13:52 +00:00
|
|
|
|
|
|
|
return flashes.length ? (
|
|
|
|
<div className={className}>
|
|
|
|
{flashes.map((flash, index) => (
|
|
|
|
<React.Fragment key={flash.id || flash.type + flash.message}>
|
|
|
|
{index > 0 && <div css={tw`mt-2`}></div>}
|
|
|
|
<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;
|