From e38d55b5b83687016b6d663a0ebae56d46ab54d6 Mon Sep 17 00:00:00 2001 From: Julian Kobrynski Date: Thu, 18 Jan 2024 14:15:35 +0100 Subject: [PATCH] migrate UpdateAppModal to TypeScript --- ...dateAppModal.js => BaseUpdateAppModal.tsx} | 22 +++++++++---------- .../{index.desktop.js => index.desktop.tsx} | 11 +++++----- .../UpdateAppModal/{index.js => index.tsx} | 7 +++--- src/components/UpdateAppModal/types.ts | 5 +++++ .../UpdateAppModal/updateAppModalPropTypes.js | 12 ---------- 5 files changed, 25 insertions(+), 32 deletions(-) rename src/components/UpdateAppModal/{BaseUpdateAppModal.js => BaseUpdateAppModal.tsx} (56%) rename src/components/UpdateAppModal/{index.desktop.js => index.desktop.tsx} (67%) rename src/components/UpdateAppModal/{index.js => index.tsx} (71%) create mode 100644 src/components/UpdateAppModal/types.ts delete mode 100644 src/components/UpdateAppModal/updateAppModalPropTypes.js diff --git a/src/components/UpdateAppModal/BaseUpdateAppModal.js b/src/components/UpdateAppModal/BaseUpdateAppModal.tsx similarity index 56% rename from src/components/UpdateAppModal/BaseUpdateAppModal.js rename to src/components/UpdateAppModal/BaseUpdateAppModal.tsx index 07b446172286..7e3c739283ee 100755 --- a/src/components/UpdateAppModal/BaseUpdateAppModal.js +++ b/src/components/UpdateAppModal/BaseUpdateAppModal.tsx @@ -1,24 +1,25 @@ -import React, {memo, useState} from 'react'; +import React, {useState} from 'react'; import ConfirmModal from '@components/ConfirmModal'; -import withLocalize from '@components/withLocalize'; -import {defaultProps, propTypes} from './updateAppModalPropTypes'; +import useLocalize from '@hooks/useLocalize'; +import type UpdateAppModalProps from './types'; -function BaseUpdateAppModal({translate, onSubmit}) { +function BaseUpdateAppModal({onSubmit}: UpdateAppModalProps) { const [isModalOpen, setIsModalOpen] = useState(true); + const {translate} = useLocalize(); /** * Execute the onSubmit callback and close the modal. */ - function submitAndClose() { - onSubmit(); + const submitAndClose = () => { + onSubmit?.(); setIsModalOpen(false); - } + }; return ( submitAndClose()} + onConfirm={submitAndClose} onCancel={() => setIsModalOpen(false)} prompt={translate('baseUpdateAppModal.updatePrompt')} confirmText={translate('baseUpdateAppModal.updateApp')} @@ -27,7 +28,4 @@ function BaseUpdateAppModal({translate, onSubmit}) { ); } -BaseUpdateAppModal.propTypes = propTypes; -BaseUpdateAppModal.defaultProps = defaultProps; - -export default memo(withLocalize(BaseUpdateAppModal)); +export default React.memo(BaseUpdateAppModal); diff --git a/src/components/UpdateAppModal/index.desktop.js b/src/components/UpdateAppModal/index.desktop.tsx similarity index 67% rename from src/components/UpdateAppModal/index.desktop.js rename to src/components/UpdateAppModal/index.desktop.tsx index 397ce2c75ea3..78bd2ef1f7ae 100644 --- a/src/components/UpdateAppModal/index.desktop.js +++ b/src/components/UpdateAppModal/index.desktop.tsx @@ -1,17 +1,18 @@ import React from 'react'; import ELECTRON_EVENTS from '../../../desktop/ELECTRON_EVENTS'; import BaseUpdateAppModal from './BaseUpdateAppModal'; -import {propTypes} from './updateAppModalPropTypes'; +import type UpdateAppModalProps from './types'; -function UpdateAppModal(props) { +function UpdateAppModal({onSubmit}: UpdateAppModalProps) { const updateApp = () => { - if (props.onSubmit) { - props.onSubmit(); + if (onSubmit) { + onSubmit(); } window.electron.send(ELECTRON_EVENTS.START_UPDATE); }; return ; } -UpdateAppModal.propTypes = propTypes; + UpdateAppModal.displayName = 'UpdateAppModal'; + export default UpdateAppModal; diff --git a/src/components/UpdateAppModal/index.js b/src/components/UpdateAppModal/index.tsx similarity index 71% rename from src/components/UpdateAppModal/index.js rename to src/components/UpdateAppModal/index.tsx index 488f69f66385..d596ae0686fe 100644 --- a/src/components/UpdateAppModal/index.js +++ b/src/components/UpdateAppModal/index.tsx @@ -1,8 +1,8 @@ import React from 'react'; import BaseUpdateAppModal from './BaseUpdateAppModal'; -import {propTypes} from './updateAppModalPropTypes'; +import type UpdateAppModalProps from './types'; -function UpdateAppModal(props) { +function UpdateAppModal(props: UpdateAppModalProps) { return ( ); } -UpdateAppModal.propTypes = propTypes; + UpdateAppModal.displayName = 'UpdateAppModal'; + export default UpdateAppModal; diff --git a/src/components/UpdateAppModal/types.ts b/src/components/UpdateAppModal/types.ts new file mode 100644 index 000000000000..572a9764f8e7 --- /dev/null +++ b/src/components/UpdateAppModal/types.ts @@ -0,0 +1,5 @@ +type UpdateAppModalProps = { + onSubmit?: () => void; +}; + +export default UpdateAppModalProps; diff --git a/src/components/UpdateAppModal/updateAppModalPropTypes.js b/src/components/UpdateAppModal/updateAppModalPropTypes.js deleted file mode 100644 index 37c112bf7598..000000000000 --- a/src/components/UpdateAppModal/updateAppModalPropTypes.js +++ /dev/null @@ -1,12 +0,0 @@ -import PropTypes from 'prop-types'; - -const propTypes = { - /** Callback to fire when we want to trigger the update. */ - onSubmit: PropTypes.func, -}; - -const defaultProps = { - onSubmit: null, -}; - -export {propTypes, defaultProps};