import React, { Component, Fragment } from 'react'; import { If, Then } from 'react-if'; import ReduxForm from 'declarative-redux-form'; import { SubmissionError, destroy } from 'redux-form'; import { Margin, Padding } from 'styled-components-spacing'; import { compose, graphql } from 'react-apollo'; import { connect } from 'react-redux'; import { set, destroyAll } from 'react-redux-values'; import intercept from 'apr-intercept'; import get from 'lodash.get'; import { ViewContainer, Message, MessageTitle, MessageDescription, Button } from 'joyent-ui-toolkit'; import { PostCreation, PostCreationContent, PostCreationTitle } from 'joyent-ui-resource-widgets'; import { Provider as ResourceSteps } from 'joyent-ui-resource-step'; import parseError from '@state/parse-error'; import { Forms, Values } from '@root/constants'; import ListServiceGroups from '@graphql/list-service-groups.gql'; import CreateServiceGroup from '@graphql/create-service-group.gql'; import GetServiceGroup from '@graphql/get-service-group.gql'; import Template from './steps/template'; import Name from './steps/name'; const { SGC_F } = Forms; const { SGC_N_V, SGC_T_V } = Values; class CreateTemplate extends Component { constructor(...args) { super(...args); this.isValids = {}; } setIsValid = name => ref => { if (!ref) { return; } const { isValid } = ref; if (!isValid) { return; } this.isValids = Object.assign({}, this.isValids, { [name]: isValid }); }; isFormValid = () => { const { steps } = this.props; return Boolean( Object.keys(this.isValids).filter( name => !this.isValids[name](steps[name] || {}) ).length ); }; isStepValid = step => { const { steps } = this.props; const fn = this.isValids[step]; const values = steps[step]; if (!fn || !values) { return true; } return fn(values); }; render() { const { match, steps, handleDefocus, handleSubmit } = this.props; const { params } = match; const { step } = params; const { template, name } = steps; const disabled = !( template && template.id && name && name.name && name.capacity ); return (