// @flow import React, { Component } from 'react'; import { components, i18n } from '../../wp'; const { __, sprintf } = i18n; const { Modal, Button, RadioControl, } = components; type DeclareWinnerProps = { variants: { id: string; name: string; rate: number; winner: boolean; participants: number; conversions: number; control: boolean; uplift: number; }[]; onDeclareWinner: (id: string) => void; }; type DeclareWinnerState = { isOpen: boolean; confirm: boolean; value: string; }; class DeclareWinner extends Component { state = { isOpen: false, confirm: false, value: '', }; openModal = () => this.setState({ isOpen: true, confirm: false, value: '', }); closeModal = () => this.setState({ isOpen: false }); toConfirm = () => this.setState({ confirm: true }); render() { const { variants, onDeclareWinner } = this.props; const { isOpen, confirm, value } = this.state; const selectedValue = value !== '' ? value : (variants.find(variant => variant.winner) || { id: '' }).id; const selectedVariant = (variants.find(variant => variant.id === selectedValue) || { name: '' }); return (
{isOpen && !confirm && (

{__('Which variant do you want to declare a winner?')}

({ label: sprintf(__('%s — %d%% %s'), variant.name, variant.rate, variant.winner ? __('(winner)') : ''), value: variant.id, }))} onChange={newValue => this.setState({ value: newValue })} />
)} {isOpen && confirm && (

{sprintf(__('Do you want to declare variant "%s" as the winner?'), selectedVariant.name)}

{__('This will remove the test and place the winning variant in its place.')}

{__('The test will be removed!')}

)}
); } } export default DeclareWinner;