[MM-56850] Convert ./components/modal_controller/modal_controller.tsx from Class Component to Function Component (#26259)

* [MM-56850] Convert `./components/modal_controller/modal_controller.tsx` from Class Component to Function Component

* fix: failing type check
This commit is contained in:
Syed Ali Abbas Zaidi 2024-02-27 02:04:36 +05:00 committed by GitHub
parent 782f81d22f
commit 48117fb21f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,39 +32,38 @@ type Props = {
}; };
} }
export default class ModalController extends React.PureComponent<Props> { const ModalController = ({
public render(): React.ReactNode { modals,
const {modals, ...props} = this.props; actions,
const {modalState} = modals; }: Props) => {
if (!modals) {
return null;
}
if (!modals) { const {modalState} = modals;
return null; const modalOutput = [];
}
const modalOutput = []; for (const modalId in modalState) {
if (modalState.hasOwnProperty(modalId)) {
const modal = modalState[modalId];
if (modal.open) {
const modalComponent = React.createElement(modal.dialogType, Object.assign({}, modal.dialogProps, {
onExited: () => {
actions.closeModal(modalId);
for (const modalId in modalState) { // Call any onExited prop provided by whoever opened the modal, if one was provided
if (modalState.hasOwnProperty(modalId)) { modal.dialogProps?.onExited?.();
const modal = modalState[modalId]; },
if (modal.open) { onHide: actions.closeModal.bind(this, modalId),
const modalComponent = React.createElement(modal.dialogType, Object.assign({}, modal.dialogProps, { key: `${modalId}_modal`,
onExited: () => { }));
props.actions.closeModal(modalId);
// Call any onExited prop provided by whoever opened the modal, if one was provided modalOutput.push(modalComponent);
modal.dialogProps?.onExited?.();
},
onHide: props.actions.closeModal.bind(this, modalId),
key: `${modalId}_modal`,
}));
modalOutput.push(modalComponent);
}
} }
} }
return (
modalOutput
);
} }
}
return <>{modalOutput}</>;
};
export default ModalController;