import React from 'react' ; import { CancelOrderModal , CancelAllOrdersModal , CancelProfitOrderModal , CancelAllProfitOrdersModal , AddProfitOrderModal , } from 'components/modals' ; export type ShowModalArgs = { [ key in keyof RegisteredModals ] : { type : key ; props : InferProps < RegisteredModals [ key ] > ; } ; } [ keyof RegisteredModals ] ; export type ModalType = keyof RegisteredModals ; export type RegisteredModals = typeof registeredModals ; export type Modals = { [ key in keyof RegisteredModals ] : ( modalProps : InferProps < RegisteredModals [ key ] > ) => void ; } ; const registeredModals = { showCancelOrder : CancelOrderModal , showCancelProfitOrder : CancelProfitOrderModal , showCancelAllOrders : CancelAllOrdersModal , showCancelAllProfitOrders : CancelAllProfitOrdersModal , showAddProfitTarget : AddProfitOrderModal , } ; export function showRegisteredModal < P > ( type , modalProps ) { return React . createElement ( registeredModals [ type ] as any , modalProps ) ; } export function createModals ( showModal ) { return Object . assign ( { } , ... Object . keys ( registeredModals ) . map ( ( modalName ) => ( { [ modalName ] : ( props ) => showModal ( { type : modalName as any , props } ) , } ) ) ) ; }