Skip to content

Commit

Permalink
simplify errorStreamToString, display just message if there is one
Browse files Browse the repository at this point in the history
  • Loading branch information
raejohanek committed Oct 31, 2024
1 parent 4d0c19e commit 588c60c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
11 changes: 0 additions & 11 deletions src/components/Alert.jsx

This file was deleted.

23 changes: 23 additions & 0 deletions src/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import './Alert.css';
import CloseIcon from '@mui/icons-material/Close';

export interface AlertProps {
id: string;
type: string;
title: string;
description: string;
onClose?: () => void;
}

export const Alert = ({id, type, title, description, onClose}: AlertProps) => {
return (
<div id={`${id}_alert`} className={`alert-wrapper ${type}`} style={{border: '1px solid red', borderRadius: '5px'}}>
{onClose && <span
style={{float: 'right', fontWeight: 'bolder', fontSize: 24, cursor: 'pointer'}}
onClick={onClose} ><CloseIcon/></span> }
{title && <h4 id={`${id}_title`} className="alert-title">{title}</h4>}
{description && <span id={`${id}_description`} className="alert-description">{description}</span>}
</div>
);
};
14 changes: 3 additions & 11 deletions src/components/SignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ export const SignInButton = (props: SignInButtonProps) => {
const handleServerError = async (error: HttpError) => {
const errorMessage = await errorStreamToString(error);
setErrorDisplay({show: true, title: 'Error', description: errorMessage});
setTimeout(() => {
setErrorDisplay({});
}, 10000);
};

const handleErrors = async (error: HttpError, redirectTo: string, shouldRedirect: boolean) => {
Expand Down Expand Up @@ -160,14 +157,8 @@ export const SignInButton = (props: SignInButtonProps) => {
if (response.toString().includes('Popup closed by user')) {
setErrorDisplay(
{title: 'Sign in cancelled', description: 'Sign in cancelled by closing the sign in window'});
setTimeout(() => {
setErrorDisplay({});
}, 2000);
} else {
setErrorDisplay({title: 'Error', description: response.toString()});
setTimeout(() => {
setErrorDisplay({});
}, 2000);
}
};

Expand Down Expand Up @@ -222,8 +213,9 @@ export const SignInButton = (props: SignInButtonProps) => {
<Alert
id="dialog"
type="danger"
title={(errorDisplay as ErrorInfo).title}
description={(errorDisplay as ErrorInfo).description}
title={(errorDisplay as ErrorInfo).title || 'Error'}
description={(errorDisplay as ErrorInfo).description || ''}
onClose={() => setErrorDisplay({})}
/>
</div>
}
Expand Down

0 comments on commit 588c60c

Please sign in to comment.