text: import { createAsyncThunk } from '@reduxjs/toolkit';
  import fetchAPI from '../fetchAPI';
  
  const FETCH_MISSIONS = 'spaceX/missions/FETCH_MISSIONS/fulfilled';
  const JOIN_MISSION = 'spaceX/missions/JOIN_MISSIONS';
  const LEAVE_MISSION = 'spaceX/missions/LEAVE_MISSIONS';
  
  const initialState = {
    status: 'empty',
    missionList: [],
  };
  
  export const fetchMission = createAsyncThunk('spaceX/missions/FETCH_MISSIONS', async () => {
    const result = await fetchAPI('https://api.spacexdata.com/v3/missions');
    return result;
  });
  
  export const joinMission = (payload) => ({
    type: JOIN_MISSION,
    payload,
  });
  
  export const leaveMission = (payload) => ({
    type: LEAVE_MISSION,
    payload,
  });
  
  const missionsReducer = (state = initialState, action) => {
    switch (action.type) {
      case FETCH_MISSIONS:
        return {
          status: 'fetched',
          missionList: [...state.missionList, ...action.payload],
        };
      case JOIN_MISSION:
        return {
          status: state.status,
          missionList: [...action.payload],
        };
      case LEAVE_MISSION:
        return {
          status: state.status,
          missionList: [...action.payload],
        };
      default:
        return state;
    }
  };
  
  export default missionsReducer;
  