File size: 836 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// @flow
import React from 'react';
import { connect } from 'react-redux';
import BanUserModal from './BanUserModal';
import DeleteDoubleCheckModal from './DeleteDoubleCheckModal';

const MODAL_COMPONENTS = {
  DELETE_DOUBLE_CHECK_MODAL: DeleteDoubleCheckModal,
  BAN_USER_MODAL: BanUserModal,
};

export type ModalTypes = $Keys<typeof MODAL_COMPONENTS>;

/*
  Takes a modalType and modalProps to dynamically return the
  modal component we imported above
*/
const modalRoot = ({ modalType, modalProps }) => {
  if (!modalType) {
    return null;
  }

  const SpecificModal = MODAL_COMPONENTS[modalType];
  return <SpecificModal {...modalProps} />;
};

const mapStateToProps = state => ({
  modalProps: state.modals.modalProps,
  modalType: state.modals.modalType,
});

// $FlowIssue
export default connect(mapStateToProps)(modalRoot);