Issue after building the app but in develop all is good

Please provide the following:

  1. SDK Version: 38
  2. Platforms(Android/iOS/web/all): Android

I’m stuck at something weird so please help me if you have any idea.
I build an app (a doctor appointment booking system) in develop everything is working flawlessly and without any error.
but after I get my apk I think my dispatch function run exactly 3 times to book an appointment on my firebase database and I have no idea why is this happening, I’m gonna mention one more time that in development all is good and user book it’s appointment just once. I greatly appreciate any help such as how can I debug this or what’s wrong with my code.

this is my code on booking:

const bookingHandler = () => {
   Linking.openURL('http://www.medicalbookingapp.cloudsite.ir/sendPay.php');
 }

 const handler = (e) => handleOpenUrl(e.url);
 useEffect(() => {

   Linking.addEventListener('url', handler)

   return () => {
     Linking.removeEventListener('url', handler);

   }

 });

 const handleOpenUrl = useCallback((url) => {
   const route = url.replace(/.*?:\/\/\w*:\w*\/\W/g, '') // exp://.... --> ''
   const id = route.split('=')[1]

   if (id == 1) {
     handleDispatch();
     toggleModal();
   } else if (id == 0) {
     console.log('purchase failed...');
     toggleModal();
   }
 });

 const handleDispatch = useCallback(() => {

   dispatch(
     BookingActions.addBooking(
       therapistId,
       therapistFirstName,
       therapistLastName,
       selected.title,
       moment(selectedDate).format("YYYY-MMM-DD"),
       selected.slots,
     )
   );

   dispatch(
     doctorActions.updateTherapists(therapistId, selected.slots, selectedDate, selected.title, selectedPlanIndex, selectedTimeIndex)
   );
   setBookingConfirm(true)
 })

my action code :

export const addBooking = (therapistId, therapistFirstName, therapistLastName, sessionTime, sessionDate, slotTaken) => {
  return async (dispatch, getState) => {
    let userId = firebase.auth().currentUser.uid
    
    const confirmDate = moment(new Date()).format("ddd DD MMMM YYYY")

    const response = await fetch(
      `https://mymedicalbooking.firebaseio.com/bookings/${userId}.json`,
      {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          userId,
          therapistId,
          confirmDate,
          therapistFirstName,
          therapistLastName,
          sessionTime,
          sessionDate,
          slotTaken
        })
      }
    );

    if (!response.ok) {
      throw new Error('Something went wrong!');
    }

    const resData = await response.json();
   
    dispatch({
      type: ADD_BOOKING,
      bookingData: {
        userId: userId,
        therapistId: therapistId,
        therapistFirstName: therapistFirstName,
        therapistLastName: therapistLastName,
        sessionTime: sessionTime,
        sessionDate: sessionDate
      }
    });
  };
};

and this is the reducer:

const initialState = {
  bookings: [],
  userBookings: []
};

export default (state = initialState, action) => {
  switch (action.type) {
    case ADD_BOOKING:
      const newBooking = new Booking(
        action.bookingData.id,
        action.bookingData.therapistId,
        action.bookingData.therapistFirstName,
        action.bookingData.therapistLastName,
        action.bookingData.bookingdate
      );
      return {
        ...state,
        bookings: state.bookings.concat(newBooking)
      };
    case FETCH_BOOKING:
      const userBookings = action.userBookings;
      return {
        ...state,
        userBookings: userBookings
      };
  }

  return state;
};

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.