import * as types from '../constants/actionTypes';

const initialState = {
  classrooms: {
    loading: false,
    data: [],
    error: false,
    members: []
    //uniqueMembers currently not required for student.classrooms
  }
};

export function student(state = initialState, action) {
  switch (action.type) {
    case types.JOIN_CLASSROOM:
      return { ...state,
        classrooms: {
          loading: true,
          data: state.classrooms.data,
          error: false,
          members: state.classrooms.members,
        }
      }
    case types.JOIN_CLASSROOM_SUCCESS:
      return { ...state,
        classrooms: {
          loading: false,
          data: state.classrooms.data.concat(action.data),
          error: false,
          members: state.classrooms.members.concat(action.members),
        }
      }
    case types.JOIN_CLASSROOM_ERROR:
      alert('ERROR: Could not join Classroom. Classroom may no longer exist, or the join URL may be incorrect.');
      return { ...state,
        classrooms: {
          loading: false,
          data: state.classrooms.data,
          error: false,
          members: state.classrooms.members,
        }
      }
    case types.REQUEST_STUDENT_CLASSROOMS:
      return { ...state,
        classrooms: {
          loading: true,
          data: [],
          error: false,
          members: [],
        }
      }
    case types.RECEIVE_STUDENT_CLASSROOMS:
      return { ...state,
        classrooms: {
          loading: false,
          data: action.data || [],
          error: action.error,
          members: action.members || [],
        }
      }
    default:
      return state;
  }
}

@@ -575,16 +575,74 @@
 UCCESS:%0A
+      alert('You%5Cve successfully joined the classroom!');%0A
       re
@@ -958,17 +958,69 @@
 ssroom. 
-C
+You might have already joined the classroom, or the c
 lassroom

Add an extra message for successful Classroom Joins