Verified Commit 6455c5f2 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Fix events field saving

parent 929eca3c
......@@ -9,6 +9,8 @@ import { apiRequest } from '../../app/utils/url';
import * as eventActions from '../../app/actions/event';
import { tokenSelector } from '../../app/selectors/session';
const { ServerError } = jest.requireActual('../../app/utils/url');
jest.mock('react-native-snackbar', () => ({
LENGTH_LONG: 100,
show: jest.fn(),
......@@ -31,7 +33,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: '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: '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