Skip to content

Commit

Permalink
Merge pull request #321 from labzero/jeffrey/flash-error
Browse files Browse the repository at this point in the history
Convert ErrorPage and Flash to TypeScript
  • Loading branch information
JeffreyATW authored May 23, 2023
2 parents 352ec26 + 81ac7d6 commit 8a56a40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
* LICENSE.txt file in the root directory of this source tree.
*/

import PropTypes from "prop-types";
import React from "react";
import withStyles from "isomorphic-style-loader/withStyles";
import s from "./ErrorPage.scss";

export const ErrorPage = ({ error }) => {
interface ErrorPageProps {
error: { stack: string; status: number };
}

export const ErrorPage = ({ error }: ErrorPageProps) => {
let title = "Error";
let content = "Sorry, a critical error occurred on this page.";
let errorMessage = null;
Expand All @@ -33,7 +36,5 @@ export const ErrorPage = ({ error }) => {
);
};

ErrorPage.propTypes = { error: PropTypes.object.isRequired };

export { ErrorPage as ErrorPageWithoutStyle };
export default withStyles(s)(ErrorPage);
13 changes: 6 additions & 7 deletions src/components/Flash/Flash.js → src/components/Flash/Flash.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import PropTypes from "prop-types";
import React, { Component } from "react";
import withStyles from "isomorphic-style-loader/withStyles";
// eslint-disable-next-line css-modules/no-unused-class
import s from "./Flash.scss";

class Flash extends Component {
static propTypes = {
expireFlash: PropTypes.func.isRequired,
message: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
};
interface FlashProps {
expireFlash: () => void;
message: string;
type: keyof typeof s;
}

class Flash extends Component<FlashProps> {
componentDidMount() {
setTimeout(this.props.expireFlash, 5000);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { connect } from "react-redux";
import Flash from "./Flash";
import { expireFlash } from "../../actions/flash";
import { Dispatch } from "../../interfaces";

const mapDispatchToProps = (dispatch, ownProps) => ({
const mapDispatchToProps = (dispatch: Dispatch, ownProps: { id: string }) => ({
expireFlash: () => {
dispatch(expireFlash(ownProps.id));
},
Expand Down

0 comments on commit 8a56a40

Please sign in to comment.