@umituz/react-native-settings 5.1.4 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/presentation/hooks/useSettingsScreenConfig.ts +2 -5
- package/src/presentation/navigation/SettingsStackNavigator.tsx +1 -12
- package/src/presentation/navigation/hooks/useSettingsScreens.ts +9 -1
- package/src/presentation/navigation/types.ts +7 -0
- package/src/presentation/utils/useAuthHandlers.ts +13 -14
- package/src/presentation/utils/usePasswordPromptNavigation.ts +49 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-settings",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Complete settings hub for React Native apps - consolidated package with settings, localization, about, legal, appearance, feedback, FAQs, rating, and gamification",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -49,7 +49,6 @@ export interface SettingsScreenConfigResult {
|
|
|
49
49
|
translatedFaqData: FAQData | undefined;
|
|
50
50
|
isLoading: boolean;
|
|
51
51
|
isAuthReady: boolean;
|
|
52
|
-
PasswordPromptComponent: React.ReactNode;
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
export const useSettingsScreenConfig = (
|
|
@@ -75,7 +74,7 @@ export const useSettingsScreenConfig = (
|
|
|
75
74
|
const userProfileData = useUserProfile({});
|
|
76
75
|
|
|
77
76
|
// Use centralized auth handlers
|
|
78
|
-
const { handleRatePress, handleSignOut, handleDeleteAccount, handleSignIn
|
|
77
|
+
const { handleRatePress, handleSignOut, handleDeleteAccount, handleSignIn } =
|
|
79
78
|
useAuthHandlers(appInfo, translations?.errors);
|
|
80
79
|
|
|
81
80
|
// Use settings config factory
|
|
@@ -164,8 +163,7 @@ export const useSettingsScreenConfig = (
|
|
|
164
163
|
onLogout: handleSignOut,
|
|
165
164
|
onDeleteAccount: handleDeleteAccount,
|
|
166
165
|
translations: translations?.account as any,
|
|
167
|
-
|
|
168
|
-
}), [user, userProfileData, handleSignIn, handleSignOut, handleDeleteAccount, translations, PasswordPromptComponent]);
|
|
166
|
+
}), [user, userProfileData, handleSignIn, handleSignOut, handleDeleteAccount, translations]);
|
|
169
167
|
|
|
170
168
|
// Use centralized FAQ translation
|
|
171
169
|
const translatedFaqData = useMemo(() =>
|
|
@@ -180,6 +178,5 @@ export const useSettingsScreenConfig = (
|
|
|
180
178
|
translatedFaqData,
|
|
181
179
|
isLoading: loading,
|
|
182
180
|
isAuthReady,
|
|
183
|
-
PasswordPromptComponent,
|
|
184
181
|
};
|
|
185
182
|
};
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import React from "react";
|
|
9
|
-
import { View } from "react-native";
|
|
10
9
|
import {
|
|
11
10
|
StackNavigator,
|
|
12
11
|
type StackNavigatorConfig,
|
|
@@ -18,7 +17,6 @@ import {
|
|
|
18
17
|
createLegalScreenProps,
|
|
19
18
|
} from "./utils";
|
|
20
19
|
import type { SettingsStackParamList, SettingsStackNavigatorProps } from "./types";
|
|
21
|
-
import { useAuthHandlers } from "../utils/useAuthHandlers";
|
|
22
20
|
|
|
23
21
|
export const SettingsStackNavigator: React.FC<SettingsStackNavigatorProps> = (props) => {
|
|
24
22
|
const {
|
|
@@ -32,8 +30,6 @@ export const SettingsStackNavigator: React.FC<SettingsStackNavigatorProps> = (pr
|
|
|
32
30
|
const { handlePrivacyPress, handleTermsPress, handleEulaPress, aboutConfig } =
|
|
33
31
|
useNavigationHandlers(appInfo, legalUrls, aboutTranslations);
|
|
34
32
|
|
|
35
|
-
const { PasswordPromptComponent } = useAuthHandlers(appInfo, config?.translations?.errors);
|
|
36
|
-
|
|
37
33
|
const screenOptions = React.useMemo(
|
|
38
34
|
() => ({
|
|
39
35
|
headerShown: false,
|
|
@@ -62,12 +58,5 @@ export const SettingsStackNavigator: React.FC<SettingsStackNavigatorProps> = (pr
|
|
|
62
58
|
screens,
|
|
63
59
|
};
|
|
64
60
|
|
|
65
|
-
return
|
|
66
|
-
<>
|
|
67
|
-
<View style={{ flex: 1 }}>
|
|
68
|
-
<StackNavigator<SettingsStackParamList> config={navigatorConfig} />
|
|
69
|
-
</View>
|
|
70
|
-
{PasswordPromptComponent}
|
|
71
|
-
</>
|
|
72
|
-
);
|
|
61
|
+
return <StackNavigator<SettingsStackParamList> config={navigatorConfig} />;
|
|
73
62
|
};
|
|
@@ -3,6 +3,7 @@ import type { StackScreen } from "@umituz/react-native-design-system";
|
|
|
3
3
|
import { LanguageSelectionScreen } from "../../../domains/localization";
|
|
4
4
|
import { NotificationSettingsScreen } from "../../../domains/notifications";
|
|
5
5
|
import { AccountScreen } from "@umituz/react-native-auth";
|
|
6
|
+
import { PasswordPromptScreen } from "@umituz/react-native-firebase";
|
|
6
7
|
import { SettingsScreen } from "../../screens/SettingsScreen";
|
|
7
8
|
import { AppearanceScreen } from "../../screens/AppearanceScreen";
|
|
8
9
|
import { FAQScreen } from "../../../domains/faqs";
|
|
@@ -128,6 +129,12 @@ export const useSettingsScreens = (props: UseSettingsScreensProps): StackScreen[
|
|
|
128
129
|
title: videoTutorialConfig?.title || translations?.videoTutorial?.title || "",
|
|
129
130
|
});
|
|
130
131
|
|
|
132
|
+
const passwordPromptScreen: StackScreen = {
|
|
133
|
+
name: "PasswordPrompt",
|
|
134
|
+
component: PasswordPromptScreen as any,
|
|
135
|
+
options: { headerShown: false },
|
|
136
|
+
};
|
|
137
|
+
|
|
131
138
|
return combineScreens(
|
|
132
139
|
baseScreens,
|
|
133
140
|
faqScreen,
|
|
@@ -135,7 +142,8 @@ export const useSettingsScreens = (props: UseSettingsScreensProps): StackScreen[
|
|
|
135
142
|
gamificationScreen,
|
|
136
143
|
languageScreen,
|
|
137
144
|
accountScreen,
|
|
138
|
-
videoTutorialScreen
|
|
145
|
+
videoTutorialScreen,
|
|
146
|
+
passwordPromptScreen
|
|
139
147
|
);
|
|
140
148
|
}, [
|
|
141
149
|
translations,
|
|
@@ -47,6 +47,13 @@ export type SettingsStackParamList = {
|
|
|
47
47
|
Gamification: undefined;
|
|
48
48
|
Account: undefined;
|
|
49
49
|
VideoTutorial: undefined;
|
|
50
|
+
PasswordPrompt: {
|
|
51
|
+
onComplete: (password: string | null) => void;
|
|
52
|
+
title?: string;
|
|
53
|
+
message?: string;
|
|
54
|
+
confirmText?: string;
|
|
55
|
+
cancelText?: string;
|
|
56
|
+
};
|
|
50
57
|
};
|
|
51
58
|
|
|
52
59
|
/**
|
|
@@ -11,9 +11,10 @@ import {
|
|
|
11
11
|
useAuthModalStore,
|
|
12
12
|
useAccountManagement,
|
|
13
13
|
} from "@umituz/react-native-auth";
|
|
14
|
-
import { AlertService } from "@umituz/react-native-design-system";
|
|
14
|
+
import { AlertService, useAppNavigation } from "@umituz/react-native-design-system";
|
|
15
15
|
import type { AppInfo } from "../navigation/types";
|
|
16
16
|
import type { SettingsTranslations } from "../screens/types";
|
|
17
|
+
import { usePasswordPromptNavigation } from "./usePasswordPromptNavigation";
|
|
17
18
|
|
|
18
19
|
declare const __DEV__: boolean;
|
|
19
20
|
|
|
@@ -23,12 +24,18 @@ declare const __DEV__: boolean;
|
|
|
23
24
|
export const useAuthHandlers = (appInfo: AppInfo, translations?: SettingsTranslations["account"] & SettingsTranslations["errors"]) => {
|
|
24
25
|
const { signOut } = useAuth();
|
|
25
26
|
const { showAuthModal } = useAuthModalStore();
|
|
27
|
+
const navigation = useAppNavigation();
|
|
26
28
|
|
|
27
|
-
const {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const { showPasswordPrompt } = usePasswordPromptNavigation({
|
|
30
|
+
navigation,
|
|
31
|
+
title: translations?.deleteAccountTitle || "Confirm Account Deletion",
|
|
32
|
+
message: translations?.deleteAccountMessage || "Please enter your password to permanently delete your account. This action cannot be undone.",
|
|
33
|
+
cancelText: translations?.cancel || "Cancel",
|
|
34
|
+
confirmText: translations?.delete || "Delete",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const { deleteAccount: deleteAccountFromAuth } = useAccountManagement({
|
|
38
|
+
onPasswordRequired: showPasswordPrompt,
|
|
32
39
|
});
|
|
33
40
|
|
|
34
41
|
const handleRatePress = useCallback(async () => {
|
|
@@ -71,17 +78,10 @@ export const useAuthHandlers = (appInfo: AppInfo, translations?: SettingsTransla
|
|
|
71
78
|
}, [signOut, translations]);
|
|
72
79
|
|
|
73
80
|
const handleDeleteAccount = useCallback(async () => {
|
|
74
|
-
console.log("[useAuthHandlers] handleDeleteAccount called");
|
|
75
81
|
try {
|
|
76
|
-
console.log("[useAuthHandlers] Calling deleteAccountFromAuth...");
|
|
77
82
|
await deleteAccountFromAuth();
|
|
78
|
-
console.log("[useAuthHandlers] Delete account successful");
|
|
79
|
-
// Account deleted successfully - auth package handles everything
|
|
80
83
|
} catch (error) {
|
|
81
84
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
82
|
-
|
|
83
|
-
console.error("[useAuthHandlers] Delete account failed:", error);
|
|
84
|
-
|
|
85
85
|
AlertService.createErrorAlert(
|
|
86
86
|
translations?.common || "Error",
|
|
87
87
|
errorMessage || translations?.deleteAccountError || "Failed to delete account"
|
|
@@ -98,6 +98,5 @@ export const useAuthHandlers = (appInfo: AppInfo, translations?: SettingsTransla
|
|
|
98
98
|
handleSignOut,
|
|
99
99
|
handleDeleteAccount,
|
|
100
100
|
handleSignIn,
|
|
101
|
-
PasswordPromptComponent,
|
|
102
101
|
};
|
|
103
102
|
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Password Prompt Navigation Hook
|
|
3
|
+
* Navigation-based password prompt that maintains Promise interface
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useCallback, useRef } from 'react';
|
|
7
|
+
import type { useAppNavigation } from '@umituz/react-native-design-system';
|
|
8
|
+
|
|
9
|
+
export interface UsePasswordPromptNavigationOptions {
|
|
10
|
+
navigation: ReturnType<typeof useAppNavigation>;
|
|
11
|
+
title?: string;
|
|
12
|
+
message?: string;
|
|
13
|
+
confirmText?: string;
|
|
14
|
+
cancelText?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface UsePasswordPromptNavigationReturn {
|
|
18
|
+
showPasswordPrompt: () => Promise<string | null>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const usePasswordPromptNavigation = (
|
|
22
|
+
options: UsePasswordPromptNavigationOptions
|
|
23
|
+
): UsePasswordPromptNavigationReturn => {
|
|
24
|
+
const { navigation, title, message, confirmText, cancelText } = options;
|
|
25
|
+
const resolveRef = useRef<((value: string | null) => void) | null>(null);
|
|
26
|
+
|
|
27
|
+
const showPasswordPrompt = useCallback((): Promise<string | null> => {
|
|
28
|
+
return new Promise<string | null>((resolve) => {
|
|
29
|
+
resolveRef.current = resolve;
|
|
30
|
+
|
|
31
|
+
navigation.navigate('PasswordPrompt', {
|
|
32
|
+
onComplete: (password: string | null) => {
|
|
33
|
+
if (resolveRef.current) {
|
|
34
|
+
resolveRef.current(password);
|
|
35
|
+
resolveRef.current = null;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
title,
|
|
39
|
+
message,
|
|
40
|
+
confirmText,
|
|
41
|
+
cancelText,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}, [navigation, title, message, confirmText, cancelText]);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
showPasswordPrompt,
|
|
48
|
+
};
|
|
49
|
+
};
|