misc_pterodactyl-panel/resources/scripts/components/FlashMessageRender.tsx
2022-11-25 13:25:03 -07:00

28 lines
915 B
TypeScript

import { Fragment } from 'react';
import MessageBox from '@/components/MessageBox';
import { useStoreState } from 'easy-peasy';
import tw from 'twin.macro';
type Props = Readonly<{
byKey?: string;
className?: string;
}>;
const FlashMessageRender = ({ byKey, className }: Props) => {
const flashes = useStoreState(state => state.flashes.items.filter(flash => (byKey ? flash.key === byKey : true)));
return flashes.length ? (
<div className={className}>
{flashes.map((flash, index) => (
<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>
</Fragment>
))}
</div>
) : null;
};
export default FlashMessageRender;