mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Add response handling when editing a Campaign
This commit is contained in:
parent
e2afcd0acb
commit
a8056aedff
@ -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>
|
||||
|
@ -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) => {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user