misc_pterodactyl-panel/resources/scripts/components/FlashMessageRender.tsx

38 lines
1.1 KiB
TypeScript
Raw Normal View History

import React from 'react';
import MessageBox from '@/components/MessageBox';
import { State, useStoreState } from 'easy-peasy';
import { ApplicationStore } from '@/state';
type Props = Readonly<{
byKey?: string;
2019-06-16 23:57:57 +00:00
spacerClass?: string;
}>;
2020-07-03 21:19:05 +00:00
export default ({ spacerClass, byKey }: Props) => {
const flashes = useStoreState((state: State<ApplicationStore>) => state.flashes.items);
let filtered = flashes;
if (byKey) {
filtered = flashes.filter(flash => flash.key === byKey);
}
if (filtered.length === 0) {
return null;
}
return (
2020-07-03 21:19:05 +00:00
<div>
{
filtered.map((flash, index) => (
<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>}
<MessageBox type={flash.type} title={flash.title}>
{flash.message}
</MessageBox>
</React.Fragment>
))
}
</div>
);
};