Update Alerts to use ReactNode as a message content (#2399)

This commit is contained in:
Oleg Shur 2022-08-08 13:00:43 +03:00 committed by GitHub
parent 32b550f671
commit 8efd890540
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 15 deletions

View file

@ -109,11 +109,16 @@ const SendMessage: React.FC = () => {
} }
} }
if (errors.length > 0) { if (errors.length > 0) {
const errorsHtml = errors.map((e) => `<li>${e}</li>`).join('');
showAlert('error', { showAlert('error', {
id: `${clusterName}-${topicName}-createTopicMessageError`, id: `${clusterName}-${topicName}-createTopicMessageError`,
title: 'Validation Error', title: 'Validation Error',
message: `<ul>${errorsHtml}</ul>`, message: (
<ul>
{errors.map((e) => (
<li>{e}</li>
))}
</ul>
),
}); });
return; return;
} }

View file

@ -3,7 +3,7 @@ import styled from 'styled-components';
export const Alert = styled.div<{ $type: ToastType }>` export const Alert = styled.div<{ $type: ToastType }>`
background-color: ${({ $type, theme }) => theme.alert.color[$type]}; background-color: ${({ $type, theme }) => theme.alert.color[$type]};
min-width: 500px; width: 500px;
min-height: 64px; min-height: 64px;
border-radius: 8px; border-radius: 8px;
padding: 12px; padding: 12px;

View file

@ -8,7 +8,7 @@ import * as S from './Alert.styled';
export interface AlertProps { export interface AlertProps {
title: string; title: string;
type: ToastType; type: ToastType;
message: string; message: React.ReactNode;
onDissmiss(): void; onDissmiss(): void;
} }
@ -16,10 +16,7 @@ const Alert: React.FC<AlertProps> = ({ title, type, message, onDissmiss }) => (
<S.Alert $type={type} role="alert"> <S.Alert $type={type} role="alert">
<div> <div>
<S.Title role="heading">{title}</S.Title> <S.Title role="heading">{title}</S.Title>
<S.Message <S.Message role="contentinfo">{message}</S.Message>
role="contentinfo"
dangerouslySetInnerHTML={{ __html: message }}
/>
</div> </div>
<IconButtonWrapper role="button" onClick={onDissmiss}> <IconButtonWrapper role="button" onClick={onDissmiss}>
<CloseIcon /> <CloseIcon />

View file

@ -30,7 +30,7 @@ export const getResponse = async (
interface AlertOptions { interface AlertOptions {
id?: string; id?: string;
title?: string; title?: string;
message: string; message: React.ReactNode;
} }
export const showAlert = ( export const showAlert = (
@ -67,10 +67,12 @@ export const showServerError = async (
} catch (e) { } catch (e) {
// do nothing; // do nothing;
} }
showAlert('error', { if (response.status) {
id: response.url, showAlert('error', {
title: `${response.status} ${response.statusText}`, id: response.url,
message: body?.message || 'An error occurred', title: `${response.status} ${response.statusText}`,
...options, message: body?.message || 'An error occurred',
}); ...options,
});
}
}; };