-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DT-841]Display error from Consent on Sign In #2701
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A suggestion to simplify getting the body:
@@ -113,18 +114,34 @@ export const SignInButton = (props: SignInButtonProps) => { | |||
await Metrics.captureEvent(event); | |||
}; | |||
|
|||
const errorStreamToString = async (error: HttpError) => { | |||
const body = await new Response(error.body).json(); | |||
return body.message || JSON.stringify(body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is a message return that, else return the whole error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if that is really long? Do we truncate the message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe its truncated, I think it will display the whole thing. Would it be preferable to truncate it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. This is possibly something we can just observe and address if it becomes a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable - I think there are a few questions but mine at least isn't blocking.
src/components/SignInButton.tsx
Outdated
setErrorDisplay({show: true, title: 'Error', description: errorMessage}); | ||
setTimeout(() => { | ||
setErrorDisplay({}); | ||
}, 10000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you x
out of the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, I don't think we have a close handler on the error message. Would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hacked this a little bit ... this code looks ugly (style wise), but works. Modify the alert div around line 221:
: <div className="dialog-alert">
<button onClick={() => setErrorDisplay({})}>X</button>
<Alert
id="dialog"
type="danger"
title={(errorDisplay as ErrorInfo).title}
description={(errorDisplay as ErrorInfo).description}
/>
</div>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spent some more time with this - I think the Alert
component is too restrictive. Modifying it to take a conditional close handler might be more work than we want to take on due to how much usage it has. Here is my hacky attempt at a solution that uses import CloseIcon from '@mui/icons-material/Close';
: <div id={`dialog_alert`} className={`alert-wrapper danger`} style={{border: '1px solid red', borderRadius: '5px'}}>
<span
style={{float: 'right', fontWeight: 'bolder', fontSize: 24, cursor: 'pointer'}}
onClick={() => setErrorDisplay({})}><CloseIcon/></span>
<h4 id={`dialog_title`} className="alert-title">{(errorDisplay as ErrorInfo).title}</h4>
<span id={`dialog_description`}
className="alert-description">{(errorDisplay as ErrorInfo).description}</span>
</div>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With some advice from Miguel, I decided to convert the Alert to tsx so I could explicitly define the props and make onClose optional with an undefined default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good 👍
src/components/Alert.tsx
Outdated
onClose?: () => void; | ||
} | ||
|
||
export const Alert = ({id, type, title, description, onClose}: AlertProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
breaking this out to a second line would help readability and match the recommended pattern (including the return type:
export const Alert = (props: AlertProps): React.ReactNode => {
const { id, type, title, description, onClose } = props;
//...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏽
Addresses
Ticket: https://broadworkbench.atlassian.net/browse/DT-841
Summary
Have you read Terra's Contributing Guide lately? If not, do that first.