1. Nós agora iremos fazer a deleção do hábito, quando deletarmos o hábito também iremos deletar a nossa notificação.

  2. Vamos em “UpdateExcludeButtons”, que é onde a gente excluí o hábito. Nós vamos estar adicionando a função de deletar hábito o nosso método dentro do serviço. “Components → HabitPage → UpdateExcludeButtons → index.jsx”

    import React from "react";
    import {
      View,
      Text,
      TouchableOpacity,
      StyleSheet,
      Image,
      Alert,
    } from "react-native";
    
    import { useNavigation } from "@react-navigation/native";
    
    import HabitsService from "../../../services/HabitsService";
    import NotificationService from "../../../services/NotificationService";
    
    export default function UpdateExcludeButtons({ handleUpdate, habitArea, habitInput }) {
      const navigation = useNavigation();
    
      function handleDeleteHabit() {
        HabitsService.deleteByName(habitArea)
          .then(() => {
            Alert.alert("Exclusão feita com sucesso");
            NotificationService.deleteNotification(habitInput);
            navigation.navigate("Home", {
              excludeArea: `${habitArea}`,
            });
          })
          .catch((err) => console.log(err));
      }
    
    	// ... Outros códigos
    
  3. Agora nós vamos na página “HabitPage” para colocar o nosso “HabitInput” lá. “Pages → HabitPage → index.jsx”

    {create === false ? (
    	<UpdateExcludeButtons
    	  handleUpdate={handleUpdateHabit}
        habitInput={habitInput}
        habitArea={habit?.habitArea}
       />
       ) : (
       <View style={styles.configButton}>
    	   <DefaultButton
    	     buttonText={"Criar"}
           handlePress={handleCreateHabit}
           width={250}
           height={50}
         />
       </View>
     )}
    
  4. Ao fazermos isso nós vamos estar excluindo a notificação quando o hábito for excluído.