{"size": 1485, "ext": "js", "max_stars_repo_path": "components/Modules/Support/redux/action.js", "max_stars_repo_name": "gopeshjangid/comboware", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "components/Modules/Support/redux/action.js", "max_issues_repo_name": "gopeshjangid/comboware", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "components/Modules/Support/redux/action.js", "max_forks_repo_name": "gopeshjangid/comboware", "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": 30.9375, "max_line_length": 131, "alphanum_fraction": 0.6121212121}

import {START ,STOP,SAVE_SUPPORT ,MESSAGE,API} from  "./constants";
import Service from  "../../../../service/index";

export const getAllMessages = (query) => (dispatch) =>{
  Service.get(API.getAllMessages+query).then(({data})=>{
    dispatch({type : SAVE_SUPPORT , payload  :  {messageList: [...data?.data] ,chat_id : Number(localStorage.getItem("chatId"))}});
  }).catch(err =>{
    console.log("err--" ,err)
    dispatch({type : STOP , payload : {error : "Something went wrong"}});
  })

}

export const getLatestMessage = (query) => (dispatch ,getState) =>{
  Service.get(API.getLatestMessage+query).then(({data})=>{
    let state = getState();
    if(data?.data){
      dispatch({type : SAVE_SUPPORT , payload  :  {messageList: [...state?.support?.messageList,data?.data] }});
    }
  }).catch(err =>{
    
  })

}


export const sendMessage = (data) => (dispatch ,getState) =>{
  
  Service.post(API.sendMessage ,data).then(res=>{
    dispatch({type : SAVE_SUPPORT , payload  :  {chat_id: res?.data?.data?.chat_id } });
  }).catch(err =>{
    console.log("err--" ,err)
    dispatch({type : STOP , payload : {error : "Something went wrong"}});
  })

}

export const getAllChats = (data) => (dispatch ,getState) =>{
  
  Service.get(API.getAllChats).then(res=>{
    dispatch({type : SAVE_SUPPORT , payload  :  {chatList: [...res?.data?.data] } });
  }).catch(err =>{
    console.log("err--" ,err)
    dispatch({type : STOP , payload : {error : "Something went wrong"}});
  })

}