'use strict'; import React, {Component} from 'react'; import PropTypes from 'prop-types'; import {withTranslation} from '../lib/i18n'; import { LinkButton, requiresAuthenticatedUser, Title, withPageHelpers } from '../lib/page'; import { AlignedRow, ButtonRow, CheckBox, DatePicker, Form, InputField, TableSelect, withForm } from '../lib/form'; import { withAsyncErrorHandler, withErrorHandling } from '../lib/error-handling'; import {getCampaignLabels} from './helpers'; import {Table} from "../lib/table"; import { Button, Icon, ModalDialog } from "../lib/bootstrap-components"; import axios from "../lib/axios"; import { getPublicUrl, getUrl } from "../lib/urls"; import interoperableErrors from '../../../shared/interoperable-errors'; import { CampaignStatus, CampaignType } from "../../../shared/campaigns"; import moment from 'moment'; import campaignsStyles from "./styles.scss"; import {withComponentMixins} from "../lib/decorator-helpers"; @withComponentMixins([ withTranslation, withForm, withErrorHandling, withPageHelpers, requiresAuthenticatedUser ]) class TestUser extends Component { constructor(props) { super(props); this.initForm(); } static propTypes = { entity: PropTypes.object.isRequired } localValidateFormValues(state) { const t = this.props.t; if (!state.getIn(['testUser', 'value'])) { state.setIn(['testUser', 'error'], t('subscriptionHasToBeSelectedToShowThe')) } else { state.setIn(['testUser', 'error'], null); } } componentDidMount() { this.populateFormValues({ testUser: null, }); } async previewAsync() { if (this.isFormWithoutErrors()) { const campaignCid = this.props.entity.cid; const [listCid, subscriptionCid] = this.getFormValue('testUser').split(':'); window.open(getPublicUrl(`archive/${campaignCid}/${listCid}/${subscriptionCid}`, {withLocale: true}), '_blank'); } else { this.showFormValidation(); } } render() { const t = this.props.t; const testUsersColumns = [ { data: 1, title: t('email') }, { data: 2, title: t('subscriptionId'), render: data => {data} }, { data: 3, title: t('listId'), render: data => {data} }, { data: 4, title: t('list') }, { data: 5, title: t('listNamespace') } ]; return (