text: import { all, takeLatest, call, put } from 'redux-saga/effects';
  
  import { Alert } from 'react-native';
  
  import api from '~/services/api';
  
  import { updateProfileSuccess, updateProfileFailure } from './actions';
  
  function* updateProfile({ payload }) {
    try {
      const { name, email, ...rest } = payload.data;
  
      const profile = Object.assign(
        { name, email },
        rest.oldPassword ? rest : {}
      );
  
      const response = yield call(api.put, 'users', profile);
  
      Alert.alert('Perfil atualizado', 'Perfil atualizado com sucesso!');
  
      yield put(updateProfileSuccess(response.data));
    } catch (err) {
      Alert.alert(
        'Falha ao atualizar',
        'Falha ao atualizar o perfil, verifique seus dados'
      );
  
      yield put(updateProfileFailure());
    }
  }
  
  export default all([takeLatest('@user/UPDATE_PROFILE_REQUEST', updateProfile)]);
  