{"size": 767, "ext": "js", "max_stars_repo_path": "client/src/reducers/adminReducer.js", "max_stars_repo_name": "aliangeland/decentralized_election", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/reducers/adminReducer.js", "max_issues_repo_name": "aliangeland/decentralized_election", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/src/reducers/adminReducer.js", "max_forks_repo_name": "aliangeland/decentralized_election", "max_forks_repo_forks_event_min_datetime": "2022-01-17T18:19:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-17T18:19:15.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 24.7419354839, "max_line_length": 74, "alphanum_fraction": 0.5814863103}
export default function AdminReducer(state, action) {
  switch (action.type) {
    case "ADD_CANDIDATE":
      return {
        ...state,
        candidates: [...state.candidates, action.payload],
      };
    case "EDIT_CANDIDATE":
      const updatedCandidate = action.payload;
      const updatedCandidates = state.candidates.map((candidate) => {
        if (candidate.id === updatedCandidate.id) return updatedCandidate;
        return candidate;
      });

      return {
        ...state,
        candidates: updatedCandidates,
      };

    case "DELETE_CANDIDATE":
      return {
        ...state,
        candidates: state.candidates.filter(
          (candidate) => candidate.id !== action.payload
        ),
      };
    default:
      return state;
  }
}
