import React, { PureComponent } from 'react'; import { Margin } from 'styled-components-spacing'; import Flex, { FlexItem } from 'styled-flex-component'; import { compose } from 'react-apollo'; import { Link } from 'react-router-dom'; import ReduxForm from 'declarative-redux-form'; import { connect } from 'react-redux'; import { Field, change } from 'redux-form'; import { withRouter } from 'react-router'; import get from 'lodash.get'; import plur from 'plur'; import Step, { Header as StepHeader, Description as StepDescription, Preview as StepPreview, Outlet as StepOutlet } from 'joyent-ui-resource-step'; import { H2, P, FormGroup, FormLabel, Input, FormMeta, Button, InstanceCountIcon } from 'joyent-ui-toolkit'; import { Forms } from '@root/constants'; import { name as validateName } from '@state/validators'; const { SGC_N_F } = Forms; const Name = ({ history, handleGetValue, preview = {}, readOnlyName, initialValues, handleValidate, handlePlusClick, handleMinusClick, ...props }) => ( }> Name and instance count Input the name of your Service Group and the desired number of instances this group will aim to maintain. You can scale up or down your Service Group anytime after commisioning.

{preview.name}

{preview.capacity} {plur('instance', preview.capacity)}

{({ next }) => ( {({ pristine, invalid }) => (
history.push(next)}> Service group name Desired number of instances
)}
)}
); const Container = compose( withRouter, connect((store, { preview = {} }) => { const { form } = store; return { handleGetValue: () => get(form, `${SGC_N_F}.values`, {}), initialValues: { capacity: 1, ...preview } }; }), connect(null, (dispatch, { handleGetValue }) => ({ handleValidate: validateName, handlePlusClick: ({ shiftKey, metaKey }) => { const count = metaKey ? 100 : shiftKey ? 10 : 1; const capacity = handleGetValue().capacity || 0; return dispatch(change(SGC_N_F, 'capacity', capacity + count)); }, handleMinusClick: ({ shiftKey, metaKey }) => { const count = metaKey ? 100 : shiftKey ? 10 : 1; const capacity = handleGetValue().capacity || 0; return dispatch(change(SGC_N_F, 'capacity', capacity - count)); } })) )(Name); export default class extends PureComponent { isValid(values) { const msgs = validateName(values); return !msgs || !Object.values(msgs).length; } render() { const { children, ...props } = this.props; return {children}; } }