Add response handling when editing a Campaign

This commit is contained in:
David Craig 2016-04-21 10:10:13 +12:00 committed by Ingo Schommer
parent e2afcd0acb
commit a8056aedff
4 changed files with 63 additions and 3 deletions

View File

@ -146,7 +146,9 @@ class CampaignAdmin extends SilverStripeComponent {
return (
<div className="cms-middle no-preview">
<div className="cms-campaigns collapse in" aria-expanded="true">
<NorthHeader />
<NorthHeader>
<h2 className="text-truncate north-header__heading">Campaigns</h2>
</NorthHeader>
<FormBuilder {...formBuilderProps} />
</div>
</div>

View File

@ -63,10 +63,10 @@ export function submitForm(submitApi, formId, fieldValues) {
});
submitApi(Object.assign({ ID: formId }, fieldValues), { 'X-Formschema-Request': 'state' })
.then(() => {
.then((response) => {
dispatch({
type: ACTION_TYPES.SUBMIT_FORM_SUCCESS,
payload: {},
payload: { response },
});
})
.catch((error) => {

View File

@ -33,6 +33,14 @@ function formsReducer(state = initialState, action) {
}),
}));
case ACTION_TYPES.SUBMIT_FORM_SUCCESS:
return deepFreeze(Object.assign({}, state, {
[action.payload.response.id]: {
fields: action.payload.response.state.fields,
messages: action.payload.response.state.messages,
},
}));
default:
return state;

View File

@ -123,4 +123,54 @@ describe('formsReducer', () => {
expect(nextState.DetailEditForm.fields[0].value).toBe('Updated');
});
});
describe('SUBMIT_FORM_SUCCESS', () => {
const initialState = deepFreeze({
DetailEditForm: {
fields: [
{
data: [],
id: 'Form_DetailEditForm_Name',
messages: [],
valid: true,
value: 'Test',
},
],
},
});
it('should add top level form messages', () => {
const nextState = formsReducer(initialState, {
type: ACTION_TYPES.SUBMIT_FORM_SUCCESS,
payload: {
id: 'DetailEditForm',
response: {
id: 'DetailEditForm',
state: {
fields: [
{
data: [],
id: 'Form_DetailEditForm_Name',
messages: [],
valid: true,
value: 'Test',
},
],
messages: [
{
type: 'good',
value: 'Saved.',
},
],
},
},
},
});
expect(nextState.DetailEditForm.messages).toBeDefined();
expect(nextState.DetailEditForm.messages.length).toBe(1);
expect(nextState.DetailEditForm.messages[0].type).toBe('good');
expect(nextState.DetailEditForm.messages[0].value).toBe('Saved.');
});
});
});