Commit 38e3d9cb authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch 'fix/events-fields-saving' into 'master'

Fix events field saving

See merge request !266
parents 98e21f0e 6455c5f2
......@@ -10,6 +10,8 @@ import * as eventActions from '../../app/actions/event';
import { tokenSelector } from '../../app/selectors/session';
import { currentEventSelector } from '../../app/selectors/events';
const { ServerError } = jest.requireActual('../../app/utils/url');
jest.mock('react-native-snackbar', () => ({
LENGTH_LONG: 100,
show: jest.fn(),
......@@ -32,7 +34,8 @@ describe('event selector', () => {
});
describe('registration saga', () => {
const error = new Error('error');
const errorResponse = { status: 500 };
const error = new ServerError('Invalid status code: 500', errorResponse);
beforeEach(() => {
apiRequest.mockReset();
......
......@@ -34,7 +34,7 @@ const register = function* register(action) {
const registration = yield call(apiRequest, `events/${event}/registrations`, data);
yield put(eventActions.event(event, false));
if (registration.fields) {
if (registration.fields && Object.keys(registration.fields).length > 0) {
yield put(registrationActions.retrieveFields(registration.pk));
}
Snackbar.show({ title: t('Registration successful!') });
......@@ -53,7 +53,9 @@ const update = function* update(action) {
const body = {};
Object.keys(fields).forEach((key) => {
body[`fields[${key}]`] = fields[key];
if (fields[key] !== undefined && fields[key] !== '') {
body[`fields[${key}]`] = fields[key];
}
});
const data = {
......@@ -72,8 +74,12 @@ const update = function* update(action) {
yield delay(50);
Snackbar.show({ title: t('Successfully updated registration') });
} catch (error) {
Sentry.captureException(error);
yield put(registrationActions.failure());
if (error.response.status === 400) {
Snackbar.show({ title: 'The field values are not correct' });
} else {
Sentry.captureException(error);
yield put(registrationActions.failure());
}
}
};
......
......@@ -66,6 +66,11 @@ class RegistrationScreen extends Component {
reason: this.props.t('This field is required.'),
};
}
} else if (field.type === 'integer' && !(value === '' || value === null) && !value.match(/^-?\d+$/)) {
return {
isValid: false,
reason: this.props.t('This field must be an integer.'),
};
}
return {
isValid: true,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment