import Backdrop from '@material-ui/core/Backdrop'; import Button from '@material-ui/core/Button'; import Fade from '@material-ui/core/Fade'; import FormControl from '@material-ui/core/FormControl'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import FormGroup from '@material-ui/core/FormGroup'; import InputLabel from '@material-ui/core/InputLabel'; import MenuItem from '@material-ui/core/MenuItem'; import Modal from '@material-ui/core/Modal'; import Select from '@material-ui/core/Select'; import Switch from '@material-ui/core/Switch'; import TextField from '@material-ui/core/TextField'; import Checkbox from '@material-ui/core/Checkbox'; import classNames from 'classnames'; import React, { useEffect, useState } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators, Dispatch } from "redux"; import { selectAdminState } from "../reducers/admin/selector"; import { createLocation, patchLocation, removeLocation } from "../reducers/admin/service"; import { selectAppState } from "../../common/reducers/app/selector"; import { selectAuthState } from "../../user/reducers/auth/selector"; // @ts-ignore import styles from './Admin.module.scss'; import Tooltip from '@material-ui/core/Tooltip'; import { useTranslation } from 'react-i18next'; interface Props { open: boolean; handleClose: any; location: any; editing: boolean; adminState?: any; createLocation?: any; patchLocation?: any; removeLocation?: any; } const mapStateToProps = (state: any): any => { return { appState: selectAppState(state), authState: selectAuthState(state), adminState: selectAdminState(state) }; }; const mapDispatchToProps = (dispatch: Dispatch): any => ({ createLocation: bindActionCreators(createLocation, dispatch), patchLocation: bindActionCreators(patchLocation, dispatch), removeLocation: bindActionCreators(removeLocation, dispatch) }); const LocationModal = (props: Props): any => { const { open, handleClose, location, editing, adminState, createLocation, patchLocation, removeLocation } = props; const [name, setName] = useState(''); const [sceneId, setSceneId] = useState(''); const [maxUsers, setMaxUsers] = useState(10); const [videoEnabled, setVideoEnabled] = useState(false); const [instanceMediaChatEnabled, setInstanceMediaChatEnabled] = useState(false); const [locationType, setLocationType] = useState('private'); const adminLocations = adminState.get('locations').get('locations'); const adminScenes = adminState.get('scenes').get('scenes'); const locationTypes = adminState.get('locationTypes').get('locationTypes'); const [state, setState] = React.useState({ feature: false, lobby: false, }); const { t } = useTranslation(); const submitLocation = () => { const submission = { name: name, sceneId: sceneId, maxUsersPerInstance: maxUsers, location_setting: { locationType: locationType, instanceMediaChatEnabled: instanceMediaChatEnabled, videoEnabled: videoEnabled }, isLobby: state.lobby, isFeatured: state.feature }; if (editing === true) { patchLocation(location.id, submission); } else { createLocation(submission); } handleClose(); }; const deleteLocation = () => { removeLocation(location.id); handleClose(); }; useEffect(() => { if (editing === true) { setName(location.name); setSceneId(location.sceneId || ''); setMaxUsers(location.maxUsersPerInstance); setVideoEnabled(location.location_setting.videoEnabled); setInstanceMediaChatEnabled(location.location_setting.instanceMediaChatEnabled); setLocationType(location.location_setting.locationType); setState({ lobby: location.isLobby, feature: location.isFeature, }); } else { setName(''); setSceneId(''); setMaxUsers(10); setVideoEnabled(false); setInstanceMediaChatEnabled(false); setLocationType('private'); } }, [location]); const handleChange = (event: React.ChangeEvent) => { setState({ ...state, [event.target.name]: event.target.checked }); }; return (
{editing === true && {location.id} } setName(e.target.value)} /> setMaxUsers(parseInt(e.target.value))} /> {t('admin:components.locationModel.lbl-scene')} {t('admin:components.locationModel.lbl-type')} setVideoEnabled(e.target.checked)} name="videoEnabled" />} label={t('admin:components.locationModel.lbl-ve')} /> setInstanceMediaChatEnabled(e.target.checked)} name="instanceMediaChatEnabled" />} label={t('admin:components.locationModel.lbl-gme')} /> {!location.isLobby && } label={t('admin:components.locationModel.lbl-lobby')} />} } label={t('admin:components.locationModel.lbl-featured')} /> {editing === true && } {editing !== true && } {editing === true && }
); }; export default connect(mapStateToProps, mapDispatchToProps)(LocationModal);