import {
  actionGetContactsSuccess,
  actionGetContactsReject
} from '../action';
import { addContact,getContacts} from '../../../api-data';
import { IContactsState } from '../../../typescript/redux/contacts/interfaces'

const asyncGetContacts = () => async (dispatch:any) => {
  try {
    const data = await getContacts<IContactsState>()
    data&&dispatch(actionGetContactsSuccess(data))
  } catch (e) {
    dispatch(actionGetContactsReject())
  } 
};

const asyncAddContact = (number:string) => async (dispatch:any) => {
  try {
    await addContact(number)
  } catch(e) {}
};


export { asyncAddContact,asyncGetContacts };
