Skip to content
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

udpate styling of error boundary #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 58 additions & 57 deletions src/canopy-react-error-boundary.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,74 @@
import React from 'react';
import {CprButton} from 'canopy-styleguide!sofe';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old

import React from "react";
import { CpButton, CpModal, CpEmptyState } from "canopy-styleguide!sofe";

export default function decorateOptions(opts) {
if (typeof opts !== 'object' || typeof opts.featureName !== 'string') {
throw new Error("canopy-react-error-boundary decorator should be called with an opts object that has a featureName string. e.g. @ErrorBoundary({featureName: 'life'})");
if (typeof opts !== "object" || typeof opts.featureName !== "string") {
throw new Error(
"canopy-react-error-boundary decorator should be called with an opts object that has a featureName string. e.g. @ErrorBoundary({featureName: 'life'})"
);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only formatting changed

}

return function decorateComponent(Comp) {
return class CanopyReactErrorBoundary extends React.Component {
static displayName = `CanopyReactErrorBoundary(${opts.featureName})`
constructor(props) {
super(props);
console.count("construct");
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

static displayName = `CanopyReactErrorBoundary(${opts.featureName})`;
state = {
caughtError: null,
caughtErrorInfo: null,
dismissed: false,
}
};
render() {
if (!this.state.caughtError) {
if (opts.noStrictMode || !React.StrictMode) {
return <Comp {...this.props} />
} else {
return (
<React.StrictMode>
return (
<>
<CpModal
show={this.state.caughtError && !this.state.dismissed}
onClose={() => this.setState({ dismissed: false })}
width={500}
>
<CpModal.Header
title={`The ${opts.featureName} is having problems`}
/>
<CpModal.Body>
<CpEmptyState
img='es_caution'
text='Looks like there was a problem'
subText='If the error continues, chat with support via the help center or call 855-558-8407'
/>
</CpModal.Body>
<CpModal.Footer>
<CpButton
btnType="primary"
onClick={() => window.history.back()}
>
Go back
</CpButton>
<CpButton
btnType="flat"
onClick={() => window.location.reload()}
>
Reload page
</CpButton>
</CpModal.Footer>
</CpModal>

{!this.state.caughtError &&
(opts.noStrictMode || !React.StrictMode ? (
<Comp {...this.props} />
</React.StrictMode>
)
}
} else if (document.getElementById('canopy-react-error-boundary-modal')) {
// Only show one application's error modal at a time
return null;
} else if (this.state.dismissed) {
// Maybe they want to click on the navbar underneath the modal?
return null;
} else {
return (
<div className="cps-modal" id="canopy-react-error-boundary-modal" style={{whiteSpace: "normal"}}>
<div className="cps-modal__screen" />
<div className="cps-modal__dialog cps-card__height-3" style={{maxWidth: '100vw', transform: "translateX(-50%)", left: "50%"}}>
<div className="cps-card__header cps-subheader-sm">
<span>
The {opts.featureName} feature is having problems
</span>
<a className="cps-modal__dialog__close cps-icon cps-icon-close" onClick={() => this.setState({dismissed: false})} />
</div>
<div className="cps-card__body" style={{display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center'}}>
<img src="https://cdn.canopytax.com/images/ErrorState.svg" style={{width: '25%', padding: '16px 0'}} />
<div style={{fontSize: '20px', fontWeight: 'bold', textAlign: 'center'}}>
Looks like there was a problem
</div>
<div style={{textAlign: 'center'}}>
If the error continues, chat with support via the help center or call <a href="tel:855-558-8407">855-558-8407</a>
</div>
</div>
<div className="cps-modal__dialog__actions">
<CprButton actionType="primary" onClick={() => window.history.back()}>
Go back
</CprButton>
<CprButton actionType="flat" onClick={() => window.location.reload()}>
Reload page
</CprButton>
</div>
</div>
</div>
);
}
) : (
<React.StrictMode>
<Comp {...this.props} />
</React.StrictMode>
))}
</>
);
}
componentDidCatch(err, info) {
if (info && info.componentStack) {
err.extra = Object.assign(err.extra || {}, {
componentStack: info.componentStack
err.extra = Object.assign(err.extra || {}, {
componentStack: info.componentStack,
});
}

Expand All @@ -80,6 +81,6 @@ export default function decorateOptions(opts) {
caughtErrorInfo: info,
});
Copy link
Author

@dvnrsn dvnrsn Sep 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why caughtErrorInfo was set in state 🤷 and caughtError should be in static getDerivedStateFromErr

}
}
}
};
};
}