fix(my-joy-beta): show create instance errors

# Conflicts:
#	packages/my-joy-beta/src/containers/create-instance/index.js
This commit is contained in:
Sérgio Ramos 2018-02-21 23:02:09 +00:00
parent 9d7e4e22d5
commit 01e10c6962
4 changed files with 115 additions and 89 deletions

View File

@ -44,7 +44,8 @@ const ImageContainer = ({
images, images,
vms, vms,
step step
}) => queryImage ? ( }) =>
queryImage ? (
<Fragment> <Fragment>
<HarcodedImage {...queryImage} /> <HarcodedImage {...queryImage} />
</Fragment> </Fragment>

View File

@ -3,7 +3,7 @@
import React from 'react'; import React from 'react';
import { Margin } from 'styled-components-spacing'; import { Margin } from 'styled-components-spacing';
import ReduxForm from 'declarative-redux-form'; import ReduxForm from 'declarative-redux-form';
import { stopSubmit, destroy } from 'redux-form'; import { SubmissionError, destroy } from 'redux-form';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { destroyAll } from 'react-redux-values'; import { destroyAll } from 'react-redux-values';
import { graphql, compose } from 'react-apollo'; import { graphql, compose } from 'react-apollo';
@ -15,7 +15,14 @@ import Values from 'lodash.values';
import omit from 'lodash.omit'; import omit from 'lodash.omit';
import uniqBy from 'lodash.uniqby'; import uniqBy from 'lodash.uniqby';
import { ViewContainer, H2, Button } from 'joyent-ui-toolkit'; import {
ViewContainer,
H2,
Button,
Message,
MessageTitle,
MessageDescription
} from 'joyent-ui-toolkit';
import Name from '@containers/create-instance/name'; import Name from '@containers/create-instance/name';
import Image from '@containers/create-instance/image'; import Image from '@containers/create-instance/image';
@ -44,6 +51,14 @@ const CreateInstance = ({
<Margin top={4} bottom={4}> <Margin top={4} bottom={4}>
<H2>Create Instances</H2> <H2>Create Instances</H2>
</Margin> </Margin>
{error ? (
<Margin bottom={4}>
<Message error>
<MessageTitle>Ooops!</MessageTitle>
<MessageDescription>{error}</MessageDescription>
</Message>
</Margin>
) : null}
{query.image ? ( {query.image ? (
<Image <Image
history={history} history={history}
@ -113,6 +128,14 @@ const CreateInstance = ({
expanded={step === 'affinity'} expanded={step === 'affinity'}
/> />
<Margin top={7} bottom={10}> <Margin top={7} bottom={10}>
{error ? (
<Margin bottom={4}>
<Message error>
<MessageTitle>Ooops!</MessageTitle>
<MessageDescription>{error}</MessageDescription>
</Message>
</Margin>
) : null}
<ReduxForm form={CREATE_FORM} onSubmit={handleSubmit}> <ReduxForm form={CREATE_FORM} onSubmit={handleSubmit}>
{({ handleSubmit, submitting }) => ( {({ handleSubmit, submitting }) => (
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
@ -133,6 +156,7 @@ export default compose(
const FORM_NAME = 'create-instance-name'; const FORM_NAME = 'create-instance-name';
const step = get(match, 'params.step', 'name'); const step = get(match, 'params.step', 'name');
const error = get(form, `${CREATE_FORM}.error`, null);
const name = get(form, `${FORM_NAME}.values.name`, ''); const name = get(form, `${FORM_NAME}.values.name`, '');
const image = get(form, 'create-instance-image.values.image', ''); const image = get(form, 'create-instance-image.values.image', '');
const pkg = get(form, 'create-instance-package.values.package', ''); const pkg = get(form, 'create-instance-package.values.package', '');
@ -146,6 +170,7 @@ export default compose(
if (!enabled) { if (!enabled) {
return { return {
error,
disabled: !enabled, disabled: !enabled,
step step
}; };
@ -178,6 +203,7 @@ export default compose(
} }
return { return {
error,
query, query,
forms: Object.keys(form), // improve this forms: Object.keys(form), // improve this
name, name,
@ -272,11 +298,9 @@ export default compose(
); );
if (err) { if (err) {
return dispatch( throw new SubmissionError({
stopSubmit(CREATE_FORM, {
_error: parseError(err) _error: parseError(err)
}) });
);
} }
dispatch([destroyAll(), forms.map(name => destroy(name))]); dispatch([destroyAll(), forms.map(name => destroy(name))]);

View File

@ -11,7 +11,6 @@ import intercept from 'apr-intercept';
import find from 'lodash.find'; import find from 'lodash.find';
import reverse from 'lodash.reverse'; import reverse from 'lodash.reverse';
import sort from 'lodash.sortby'; import sort from 'lodash.sortby';
import includes from 'lodash.includes';
import remcalc from 'remcalc'; import remcalc from 'remcalc';
import { import {

View File

@ -37,9 +37,11 @@ const SelectWrapper = styled.div`
} }
${is('embedded')` ${is('embedded')`
width: auto;
margin: 0 ${remcalc(6)}; margin: 0 ${remcalc(6)};
width: auto;
max-width: auto;
min-width: 0; min-width: 0;
&:after { &:after {
right: ${remcalc(6)}; right: ${remcalc(6)};
} }