import React from 'react'; import cn from 'classnames'; import { connect } from 'react-redux'; import withPageTitle from 'HOCs/withPageTitle'; import { IconButton, SlideModal, Loader, NoContent, Icon, TextLink } from 'UI'; import { init, fetchList, save, remove } from 'Duck/customField'; import SiteDropdown from 'Shared/SiteDropdown'; import styles from './customFields.module.css'; import CustomFieldForm from './CustomFieldForm'; import ListItem from './ListItem'; import { confirm } from 'UI'; import AnimatedSVG, { ICONS } from 'Shared/AnimatedSVG/AnimatedSVG'; @connect(state => ({ fields: state.getIn(['customFields', 'list']).sortBy(i => i.index), field: state.getIn(['customFields', 'instance']), loading: state.getIn(['customFields', 'fetchRequest', 'loading']), sites: state.getIn([ 'site', 'list' ]), errors: state.getIn([ 'customFields', 'saveRequest', 'errors' ]), }), { init, fetchList, save, remove, }) @withPageTitle('Metadata - OpenReplay Preferences') class CustomFields extends React.Component { state = { showModal: false, currentSite: this.props.sites.get(0), deletingItem: null }; componentWillMount() { const activeSite = this.props.sites.get(0); if (!activeSite) return; this.props.fetchList(activeSite.id); } save = (field) => { const { currentSite } = this.state; this.props.save(currentSite.id, field).then(() => { const { errors } = this.props; if (!errors || errors.size === 0) { return this.closeModal(); } }); }; closeModal = () => this.setState({ showModal: false }); init = (field) => { this.props.init(field); this.setState({ showModal: true }); } onChangeSelect = ({ value }) => { const site = this.props.sites.find(s => s.id === value.value); this.setState({ currentSite: site }) this.props.fetchList(site.id); } removeMetadata = async (field) => { if (await confirm({ header: 'Metadata', confirmation: `Are you sure you want to remove?` })) { const { currentSite } = this.state; this.setState({ deletingItem: field.index }); this.props.remove(currentSite.id, field.index) .then(() => this.setState({ deletingItem: null })); } } render() { const { fields, field, loading } = this.props; const { showModal, currentSite, deletingItem } = this.state; return (