import { View, Text } from "react-native"; import React, { useGlobal } from "reactn"; import AppActionSheet from "../AppActionSheet"; import BorderGradientButton from "../BorderGradientButton"; import GradientButton from "../GradientButton"; import { Palette } from "../../styles"; import { FONT_FAMILY } from "../../styles/Fonts"; import { SheetManager } from "react-native-actions-sheet"; import alert from "../Alert"; import firebase, { usersRef } from "../../config/firebase"; import { reset } from "../../navigation/NavigationService"; import { Routes } from "../../navigation"; const DeleteAccountModal = () => { const [currentUID] = useGlobal("currentUID"); const [, setTooltip] = useGlobal("_tooltip"); const onClose = async () => { await SheetManager.hide("DeleteAccount"); }; const confirmDelete = () => { alert( "Êtes-vous sûr ?", "Cette action supprimera votre profil.", [ { text: "Annuler", style: "cancel", onPress: () => {} }, { text: "Confirmer", onPress: () => { alert( "Confirmation", "Dernière vérification : souhaitez-vous supprimer définitivement votre profil ?", [ { text: "Non", style: "cancel", onPress: () => {} }, { text: "Oui, supprimer", onPress: async () => { try { if (!currentUID) return; await usersRef.doc(currentUID).delete(); // Sign out and reset navigation to Login await firebase.auth().signOut(); reset({ index: 0, routes: [{ name: Routes.Login }] }); setTooltip({ type: "success", text: "Profil supprimé" }); } catch (e) { setTooltip({ type: "error", text: e?.message || "Suppression impossible", }); } finally { onClose(); } }, }, ], { cancelable: true }, ); }, }, ], { cancelable: true }, ); }; return ( Supprimer mon compte Es-tu sûr de vouloir supprimer ton compte ?{"\n"}Attention, cette action est irréversible ! ); }; export default DeleteAccountModal;