Skip to content

Commit

Permalink
Merge pull request #34723 from JKobrynski/migrateUpdateAppModalToType…
Browse files Browse the repository at this point in the history
…Script

[No QA] [TS migration] Migrate 'UpdateAppModal' component to TypeScript
  • Loading branch information
tylerkaraszewski authored Jan 22, 2024
2 parents 9f74d1e + fd5b47d commit f576a36
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -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 (
<ConfirmModal
title={translate('baseUpdateAppModal.updateApp')}
isVisible={isModalOpen}
onConfirm={() => submitAndClose()}
onConfirm={submitAndClose}
onCancel={() => setIsModalOpen(false)}
prompt={translate('baseUpdateAppModal.updatePrompt')}
confirmText={translate('baseUpdateAppModal.updateApp')}
Expand All @@ -27,7 +28,6 @@ function BaseUpdateAppModal({translate, onSubmit}) {
);
}

BaseUpdateAppModal.propTypes = propTypes;
BaseUpdateAppModal.defaultProps = defaultProps;
BaseUpdateAppModal.displayName = 'BaseUpdateAppModal';

export default memo(withLocalize(BaseUpdateAppModal));
export default React.memo(BaseUpdateAppModal);
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
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();
}
onSubmit?.();
window.electron.send(ELECTRON_EVENTS.START_UPDATE);
};
return <BaseUpdateAppModal onSubmit={updateApp} />;
}
UpdateAppModal.propTypes = propTypes;

UpdateAppModal.displayName = 'UpdateAppModal';

export default UpdateAppModal;
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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 (
<BaseUpdateAppModal
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
/>
);
}
UpdateAppModal.propTypes = propTypes;

UpdateAppModal.displayName = 'UpdateAppModal';

export default UpdateAppModal;
6 changes: 6 additions & 0 deletions src/components/UpdateAppModal/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type UpdateAppModalProps = {
/** Callback to fire when we want to trigger the update. */
onSubmit?: () => void;
};

export default UpdateAppModalProps;
12 changes: 0 additions & 12 deletions src/components/UpdateAppModal/updateAppModalPropTypes.js

This file was deleted.

0 comments on commit f576a36

Please sign in to comment.