{"size": 1572, "ext": "js", "max_stars_repo_path": "replate/src/reducers/reducer.js", "max_stars_repo_name": "Buildweek-Replate-1/Front-End", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "replate/src/reducers/reducer.js", "max_issues_repo_name": "Buildweek-Replate-1/Front-End", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "replate/src/reducers/reducer.js", "max_forks_repo_name": "Buildweek-Replate-1/Front-End", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 35.7272727273, "max_line_length": 159, "alphanum_fraction": 0.5737913486}
import {FETCHING_DATA, DONE_WITH_DATA, LOGIN_TO_ACCT, GET_ALL_PICKUPS, CREATE_PICKUP, UPDATE_PICKUP, GET_USER_DATA} from '../actions/allActions';

const initState = {
    isFetching: false,
    currentUser: {
        id: '',
        username: '',
        password: '',
        accountType: ''
    },
    pickups: {
        id: '',
        businessAccountID: '',
        volunteerAccountID: '',
        foodType: '',
        amount: '',
        preferredPickupTime: '',
        status: ''
    }
};

export const reducer = (state = initState, action) => {
    switch(action.type) {
        case FETCHING_DATA:
            return {...state, isFetching: true};
        case DONE_WITH_DATA:
            return {...state, isFetching: false};
        case LOGIN_TO_ACCT:
            return {...state, isFetching: false, currentUser: {...action.payload}};
        case CREATE_PICKUP:
            return {...state, isFetching: false, pickups: [...state.pickups, {...action.payload, status: 'Pending', businessAccountID: state.currentUser.id}]};
        case GET_USER_DATA:
            return {...state, isFetching: false, currentUser: {...action.payload}};
        case GET_ALL_PICKUPS:
            return {...state, isFetching: false, pickups: [...action.payload]};
        case UPDATE_PICKUP:
            const updatedPickups = state.pickups.filter(eachPU => {
                return eachPU.id !== action.payload.id
            });
            return {...state, isFetching: false, pickups: [...updatedPickups, action.payload]};
        default:
            return state;
    };
}