aboutsummaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
authorLibravatar Ricardo Cino <ricardo@cino.io>2022-06-27 22:27:27 +0200
committerLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2022-06-28 04:32:53 +0530
commit8715d489b58534470fc0d35b5961797bc0118e84 (patch)
tree563d81196d6026945ad1898bda76e078eb2a5d82 /src/components
parentchore: transform containers/settings from js to tsx (#384) (diff)
downloadferdium-app-8715d489b58534470fc0d35b5961797bc0118e84.tar.gz
ferdium-app-8715d489b58534470fc0d35b5961797bc0118e84.tar.zst
ferdium-app-8715d489b58534470fc0d35b5961797bc0118e84.zip
chore: turn error boundary into typescript
Diffstat (limited to 'src/components')
-rw-r--r--src/components/ui/button/index.tsx20
-rw-r--r--src/components/util/ErrorBoundary/index.tsx (renamed from src/components/util/ErrorBoundary/index.js)26
-rw-r--r--src/components/util/ErrorBoundary/styles.tsx (renamed from src/components/util/ErrorBoundary/styles.js)0
3 files changed, 25 insertions, 21 deletions
diff --git a/src/components/ui/button/index.tsx b/src/components/ui/button/index.tsx
index 9c64e909a..26fd6bcfe 100644
--- a/src/components/ui/button/index.tsx
+++ b/src/components/ui/button/index.tsx
@@ -2,7 +2,7 @@ import Icon from '@mdi/react';
2import classnames from 'classnames'; 2import classnames from 'classnames';
3import { Property } from 'csstype'; 3import { Property } from 'csstype';
4import { Component, MouseEvent } from 'react'; 4import { Component, MouseEvent } from 'react';
5import injectStyle, { WithStylesProps } from 'react-jss'; 5import withStyles, { WithStylesProps } from 'react-jss';
6import Loader from 'react-loader'; 6import Loader from 'react-loader';
7 7
8import { Theme } from '../../../themes'; 8import { Theme } from '../../../themes';
@@ -18,6 +18,7 @@ type ButtonType =
18 18
19interface IProps extends IFormField, WithStylesProps<typeof styles> { 19interface IProps extends IFormField, WithStylesProps<typeof styles> {
20 className?: string; 20 className?: string;
21 label?: string;
21 disabled?: boolean; 22 disabled?: boolean;
22 id?: string; 23 id?: string;
23 type?: 'button' | 'reset' | 'submit' | undefined; 24 type?: 'button' | 'reset' | 'submit' | undefined;
@@ -148,12 +149,19 @@ const styles = (theme: Theme) => ({
148}); 149});
149 150
150class ButtonComponent extends Component<IProps> { 151class ButtonComponent extends Component<IProps> {
151 public static defaultProps = { 152 customDefaultProps: {
153 disabled: boolean;
154 type: 'button' | 'reset' | 'submit' | undefined;
155 onClick: (
156 event: MouseEvent<HTMLButtonElement> | MouseEvent<HTMLAnchorElement>,
157 ) => void;
158 buttonType: ButtonType;
159 busy: boolean;
160 } = {
152 type: 'button', 161 type: 'button',
153 disabled: false, 162 disabled: false,
154 onClick: () => null, 163 onClick: () => null,
155 buttonType: 'primary' as ButtonType, 164 buttonType: 'primary' as ButtonType,
156 stretch: false,
157 busy: false, 165 busy: false,
158 }; 166 };
159 167
@@ -193,7 +201,7 @@ class ButtonComponent extends Component<IProps> {
193 href, 201 href,
194 target, 202 target,
195 htmlForm, 203 htmlForm,
196 } = this.props; 204 } = { ...this.customDefaultProps, ...this.props };
197 205
198 const { busy } = this.state; 206 const { busy } = this.state;
199 let showLoader = false; 207 let showLoader = false;
@@ -265,6 +273,4 @@ class ButtonComponent extends Component<IProps> {
265 } 273 }
266} 274}
267 275
268const Button = injectStyle(styles, { injectTheme: true })(ButtonComponent); 276export default withStyles(styles, { injectTheme: true })(ButtonComponent);
269
270export default Button;
diff --git a/src/components/util/ErrorBoundary/index.js b/src/components/util/ErrorBoundary/index.tsx
index c1861e5f7..846d6dc3f 100644
--- a/src/components/util/ErrorBoundary/index.js
+++ b/src/components/util/ErrorBoundary/index.tsx
@@ -1,7 +1,6 @@
1import { Component } from 'react'; 1import { Component, ReactNode } from 'react';
2import PropTypes from 'prop-types'; 2import withStyles, { WithStylesProps } from 'react-jss';
3import injectSheet from 'react-jss'; 3import { defineMessages, injectIntl, IntlShape } from 'react-intl';
4import { defineMessages, injectIntl } from 'react-intl';
5 4
6import Button from '../../ui/button'; 5import Button from '../../ui/button';
7import { H1 } from '../../ui/headline'; 6import { H1 } from '../../ui/headline';
@@ -19,21 +18,20 @@ const messages = defineMessages({
19 }, 18 },
20}); 19});
21 20
22class ErrorBoundary extends Component { 21interface ErrorBoundaryProps extends WithStylesProps<typeof styles> {
22 intl: IntlShape;
23}
24
25class ErrorBoundary extends Component<ErrorBoundaryProps> {
23 state = { 26 state = {
24 hasError: false, 27 hasError: false,
25 }; 28 };
26 29
27 static propTypes = { 30 componentDidCatch(): void {
28 classes: PropTypes.object.isRequired,
29 children: PropTypes.node.isRequired,
30 };
31
32 componentDidCatch() {
33 this.setState({ hasError: true }); 31 this.setState({ hasError: true });
34 } 32 }
35 33
36 render() { 34 render(): ReactNode {
37 const { classes } = this.props; 35 const { classes } = this.props;
38 const { intl } = this.props; 36 const { intl } = this.props;
39 37
@@ -56,6 +54,6 @@ class ErrorBoundary extends Component {
56 } 54 }
57} 55}
58 56
59export default injectIntl( 57export default withStyles(styles, { injectTheme: true })(
60 injectSheet(styles, { injectTheme: true })(ErrorBoundary), 58 injectIntl<'intl', ErrorBoundaryProps>(ErrorBoundary),
61); 59);
diff --git a/src/components/util/ErrorBoundary/styles.js b/src/components/util/ErrorBoundary/styles.tsx
index 0960546ff..0960546ff 100644
--- a/src/components/util/ErrorBoundary/styles.js
+++ b/src/components/util/ErrorBoundary/styles.tsx