diff --git a/web/app/assets/javascripts/react-components/BookLessonFree.js.jsx.coffee b/web/app/assets/javascripts/react-components/BookLessonFree.js.jsx.coffee index 7c8a12fb7..a40997576 100644 --- a/web/app/assets/javascripts/react-components/BookLessonFree.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/BookLessonFree.js.jsx.coffee @@ -132,21 +132,31 @@ proficiencyDescriptionMap = { else context.location = '/client#/jamclass/payment' + resetErrors: () -> + @setState({generalErrors:null, slot1Errors:null, slot2Errors:null, descriptionError:null}) failedBooking: (jqXHR) -> if jqXHR.status == 422 body = JSON.parse(jqXHR.responseText) - logger.debug("BODY", body) generalErrors = [] for errorType, errors of body.errors if errorType == 'description' @setState({descriptionError: errors}) - else if errorType == 'lesson_booking_slots' - @setState({}) else error = {} error[errorType] = errors generalErrors.push(errors) + + for childErrorType, childErrors of body._children + if childErrorType == 'lesson_booking_slots' + slot1Errors = childErrors[0] + slot2Errors = childErrors[1] + if Object.keys(slot1Errors["errors"]).length > 0 + @setState({slot1Errors: slot1Errors["errors"]}) + if Object.keys(slot2Errors["errors"]).length > 0 + @setState({slot2Errors: slot2Errors["errors"]}) + if childErrors.length > 0 + @setState({childErrorType, childErrors}) @setState({generalErrors: generalErrors}) onCancel: (e) -> diff --git a/web/app/controllers/api_controller.rb b/web/app/controllers/api_controller.rb index 421350c61..e202c509e 100644 --- a/web/app/controllers/api_controller.rb +++ b/web/app/controllers/api_controller.rb @@ -40,14 +40,14 @@ class ApiController < ApplicationController protected def recursive_errors(model, children) - response = {errors:model.errors.to_json, _children:{}} + response = {errors:model.errors, _children:{}} children_response = response[:_children] children.each do |child| child_response = [] associations = model.send(child) if associations associations.each do |association| - child_response << {errors: association.errors.to_json} + child_response << {errors: association.errors} end end children_response[child] = child_response