diff --git a/src/components/Dialogs/AlertDialog.js b/src/components/Dialogs/AlertDialog.tsx
similarity index 58%
rename from src/components/Dialogs/AlertDialog.js
rename to src/components/Dialogs/AlertDialog.tsx
index 4ad7aad..642bc9b 100644
--- a/src/components/Dialogs/AlertDialog.js
+++ b/src/components/Dialogs/AlertDialog.tsx
@@ -17,36 +17,31 @@
* along with Campus INSAT. If not, see .
*/
-// @flow
-
import * as React from 'react';
import {Button, Dialog, Paragraph, Portal} from 'react-native-paper';
import i18n from 'i18n-js';
type PropsType = {
- visible: boolean,
- onDismiss: () => void,
- title: string | React.Node,
- message: string | React.Node,
+ visible: boolean;
+ onDismiss: () => void;
+ title: string | React.ReactNode;
+ message: string | React.ReactNode;
};
-class AlertDialog extends React.PureComponent {
- render(): React.Node {
- const {props} = this;
- return (
-
-
-
- );
- }
+function AlertDialog(props: PropsType) {
+ return (
+
+
+
+ );
}
export default AlertDialog;
diff --git a/src/components/Dialogs/ErrorDialog.js b/src/components/Dialogs/ErrorDialog.js
deleted file mode 100644
index b228ce1..0000000
--- a/src/components/Dialogs/ErrorDialog.js
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2019 - 2020 Arnaud Vergnet.
- *
- * This file is part of Campus INSAT.
- *
- * Campus INSAT is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Campus INSAT is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Campus INSAT. If not, see .
- */
-
-// @flow
-
-import * as React from 'react';
-import i18n from 'i18n-js';
-import {ERROR_TYPE} from '../../utils/WebData';
-import AlertDialog from './AlertDialog';
-
-type PropsType = {
- visible: boolean,
- onDismiss: () => void,
- errorCode: number,
-};
-
-class ErrorDialog extends React.PureComponent {
- title: string;
-
- message: string;
-
- generateMessage() {
- const {props} = this;
- this.title = i18n.t('errors.title');
- switch (props.errorCode) {
- case ERROR_TYPE.BAD_CREDENTIALS:
- this.message = i18n.t('errors.badCredentials');
- break;
- case ERROR_TYPE.BAD_TOKEN:
- this.message = i18n.t('errors.badToken');
- break;
- case ERROR_TYPE.NO_CONSENT:
- this.message = i18n.t('errors.noConsent');
- break;
- case ERROR_TYPE.TOKEN_SAVE:
- this.message = i18n.t('errors.tokenSave');
- break;
- case ERROR_TYPE.TOKEN_RETRIEVE:
- this.message = i18n.t('errors.unknown');
- break;
- case ERROR_TYPE.BAD_INPUT:
- this.message = i18n.t('errors.badInput');
- break;
- case ERROR_TYPE.FORBIDDEN:
- this.message = i18n.t('errors.forbidden');
- break;
- case ERROR_TYPE.CONNECTION_ERROR:
- this.message = i18n.t('errors.connectionError');
- break;
- case ERROR_TYPE.SERVER_ERROR:
- this.message = i18n.t('errors.serverError');
- break;
- default:
- this.message = i18n.t('errors.unknown');
- break;
- }
- this.message += `\n\nCode ${props.errorCode}`;
- }
-
- render(): React.Node {
- this.generateMessage();
- const {props} = this;
- return (
-
- );
- }
-}
-
-export default ErrorDialog;
diff --git a/src/components/Dialogs/ErrorDialog.tsx b/src/components/Dialogs/ErrorDialog.tsx
new file mode 100644
index 0000000..b726d56
--- /dev/null
+++ b/src/components/Dialogs/ErrorDialog.tsx
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2019 - 2020 Arnaud Vergnet.
+ *
+ * This file is part of Campus INSAT.
+ *
+ * Campus INSAT is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Campus INSAT is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Campus INSAT. If not, see .
+ */
+
+import * as React from 'react';
+import i18n from 'i18n-js';
+import {ERROR_TYPE} from '../../utils/WebData';
+import AlertDialog from './AlertDialog';
+
+type PropsType = {
+ visible: boolean;
+ onDismiss: () => void;
+ errorCode: number;
+};
+
+function ErrorDialog(props: PropsType) {
+ let title: string;
+ let message: string;
+
+ title = i18n.t('errors.title');
+ switch (props.errorCode) {
+ case ERROR_TYPE.BAD_CREDENTIALS:
+ message = i18n.t('errors.badCredentials');
+ break;
+ case ERROR_TYPE.BAD_TOKEN:
+ message = i18n.t('errors.badToken');
+ break;
+ case ERROR_TYPE.NO_CONSENT:
+ message = i18n.t('errors.noConsent');
+ break;
+ case ERROR_TYPE.TOKEN_SAVE:
+ message = i18n.t('errors.tokenSave');
+ break;
+ case ERROR_TYPE.TOKEN_RETRIEVE:
+ message = i18n.t('errors.unknown');
+ break;
+ case ERROR_TYPE.BAD_INPUT:
+ message = i18n.t('errors.badInput');
+ break;
+ case ERROR_TYPE.FORBIDDEN:
+ message = i18n.t('errors.forbidden');
+ break;
+ case ERROR_TYPE.CONNECTION_ERROR:
+ message = i18n.t('errors.connectionError');
+ break;
+ case ERROR_TYPE.SERVER_ERROR:
+ message = i18n.t('errors.serverError');
+ break;
+ default:
+ message = i18n.t('errors.unknown');
+ break;
+ }
+ message += `\n\nCode ${props.errorCode}`;
+
+ return (
+
+ );
+}
+
+export default ErrorDialog;
diff --git a/src/components/Dialogs/LoadingConfirmDialog.js b/src/components/Dialogs/LoadingConfirmDialog.tsx
similarity index 82%
rename from src/components/Dialogs/LoadingConfirmDialog.js
rename to src/components/Dialogs/LoadingConfirmDialog.tsx
index 41382c8..914ff13 100644
--- a/src/components/Dialogs/LoadingConfirmDialog.js
+++ b/src/components/Dialogs/LoadingConfirmDialog.tsx
@@ -17,8 +17,6 @@
* along with Campus INSAT. If not, see .
*/
-// @flow
-
import * as React from 'react';
import {
ActivityIndicator,
@@ -30,20 +28,23 @@ import {
import i18n from 'i18n-js';
type PropsType = {
- visible: boolean,
- onDismiss?: () => void,
- onAccept?: () => Promise, // async function to be executed
- title?: string,
- titleLoading?: string,
- message?: string,
- startLoading?: boolean,
+ visible: boolean;
+ onDismiss?: () => void;
+ onAccept?: () => Promise; // async function to be executed
+ title?: string;
+ titleLoading?: string;
+ message?: string;
+ startLoading?: boolean;
};
type StateType = {
- loading: boolean,
+ loading: boolean;
};
-class LoadingConfirmDialog extends React.PureComponent {
+export default class LoadingConfirmDialog extends React.PureComponent<
+ PropsType,
+ StateType
+> {
static defaultProps = {
onDismiss: () => {},
onAccept: (): Promise => {
@@ -71,14 +72,16 @@ class LoadingConfirmDialog extends React.PureComponent {
onClickAccept = () => {
const {props} = this;
this.setState({loading: true});
- if (props.onAccept != null) props.onAccept().then(this.hideLoading);
+ if (props.onAccept != null) {
+ props.onAccept().then(this.hideLoading);
+ }
};
/**
* Waits for fade out animations to finish before hiding loading
- * @returns {TimeoutID}
+ * @returns {NodeJS.Timeout}
*/
- hideLoading = (): TimeoutID =>
+ hideLoading = (): NodeJS.Timeout =>
setTimeout(() => {
this.setState({loading: false});
}, 200);
@@ -88,10 +91,12 @@ class LoadingConfirmDialog extends React.PureComponent {
*/
onDismiss = () => {
const {state, props} = this;
- if (!state.loading && props.onDismiss != null) props.onDismiss();
+ if (!state.loading && props.onDismiss != null) {
+ props.onDismiss();
+ }
};
- render(): React.Node {
+ render() {
const {state, props} = this;
return (
@@ -121,5 +126,3 @@ class LoadingConfirmDialog extends React.PureComponent {
);
}
}
-
-export default LoadingConfirmDialog;
diff --git a/src/components/Dialogs/OptionsDialog.js b/src/components/Dialogs/OptionsDialog.tsx
similarity index 54%
rename from src/components/Dialogs/OptionsDialog.js
rename to src/components/Dialogs/OptionsDialog.tsx
index 1ef7349..c311995 100644
--- a/src/components/Dialogs/OptionsDialog.js
+++ b/src/components/Dialogs/OptionsDialog.tsx
@@ -17,28 +17,26 @@
* along with Campus INSAT. If not, see .
*/
-// @flow
-
import * as React from 'react';
import {Button, Dialog, Paragraph, Portal} from 'react-native-paper';
import {FlatList} from 'react-native';
export type OptionsDialogButtonType = {
- title: string,
- icon?: string,
- onPress: () => void,
+ title: string;
+ icon?: string;
+ onPress: () => void;
};
type PropsType = {
- visible: boolean,
- title: string,
- message: string,
- buttons: Array,
- onDismiss: () => void,
+ visible: boolean;
+ title: string;
+ message: string;
+ buttons: Array;
+ onDismiss: () => void;
};
-class OptionsDialog extends React.PureComponent {
- getButtonRender = ({item}: {item: OptionsDialogButtonType}): React.Node => {
+function OptionsDialog(props: PropsType) {
+ const getButtonRender = ({item}: {item: OptionsDialogButtonType}) => {
return (