Улучшение Вашего процесса сборки

Нашли решение. Просто передал Alert.alert () в функцию стрелки в .catch. Вот так:

    function onBuy() {
    const email = firebase.auth().currentUser.email;
    const ref = firebase.firestore().collection('parties').doc(String(name)).collection('users').doc(String(email));
    const ref2 = firebase.firestore().collection('users').doc(String(email));
    ref.get()
    .then((doc) => {
        if (!doc.exists) {
            ref2.get()
            .then((doc2) => {
                if (doc2.exists) {
                    ref.set({
                        firstname: doc2.data().firstname,
                        lastname: doc2.data().lastname,
                        phone: doc2.data().phone
                    }).then(
                        ref2.update({ parties: firebase.firestore.FieldValue.arrayUnion(name) }).then(
                            Actions.pop()))
                    .catch(() => Alert.alert('error', 'oops, something went wrong'));
                }
            }).catch(() => Alert.alert('error', 'Sorry, something went wrong'));                   
        }
        else {
            Alert.alert('Purches fails', 'You have already bought a ticket to this party!');
        }
    })
    .catch(() => Alert.alert('fails', 'user problem'));
}
27
задан peacedog 18 August 2008 в 16:48
поделиться