@umituz/react-native-settings 4.23.40 → 4.23.41
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-settings",
|
|
3
|
-
"version": "4.23.
|
|
3
|
+
"version": "4.23.41",
|
|
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",
|
package/src/index.ts
CHANGED
|
@@ -37,6 +37,12 @@ export {
|
|
|
37
37
|
useResetSettingsMutation
|
|
38
38
|
} from './presentation/hooks/mutations/useSettingsMutations';
|
|
39
39
|
|
|
40
|
+
export { useSettingsScreenConfig } from './presentation/hooks/useSettingsScreenConfig';
|
|
41
|
+
export type {
|
|
42
|
+
UseSettingsScreenConfigParams,
|
|
43
|
+
SettingsScreenConfigResult,
|
|
44
|
+
} from './presentation/hooks/useSettingsScreenConfig';
|
|
45
|
+
|
|
40
46
|
|
|
41
47
|
// =============================================================================
|
|
42
48
|
// PRESENTATION LAYER - Screens
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSettingsScreenConfig Hook
|
|
3
|
+
*
|
|
4
|
+
* One-stop hook for settings screen configuration.
|
|
5
|
+
* Handles auth, feedback, and all settings config internally.
|
|
6
|
+
* Apps pass subscription config from subscription package.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useMemo, useCallback } from "react";
|
|
10
|
+
import { Linking } from "react-native";
|
|
11
|
+
import {
|
|
12
|
+
useAuth,
|
|
13
|
+
useAccountManagement,
|
|
14
|
+
useAuthModalStore,
|
|
15
|
+
useUserProfile,
|
|
16
|
+
} from "@umituz/react-native-auth";
|
|
17
|
+
import { AlertService } from "@umituz/react-native-design-system";
|
|
18
|
+
import { useLocalization } from "../../domains/localization";
|
|
19
|
+
import {
|
|
20
|
+
createAppearanceConfig,
|
|
21
|
+
createLanguageConfig,
|
|
22
|
+
createNotificationsConfig,
|
|
23
|
+
createAboutConfig,
|
|
24
|
+
createLegalConfig,
|
|
25
|
+
createFeedbackConfig,
|
|
26
|
+
createRatingConfig,
|
|
27
|
+
createFAQConfig,
|
|
28
|
+
createSubscriptionConfig,
|
|
29
|
+
} from "../utils/config-creators";
|
|
30
|
+
import type { SettingsConfig } from "../screens/types";
|
|
31
|
+
import type { FeedbackFormData } from "../utils/config-creators";
|
|
32
|
+
import type { AppInfo, FAQData, UserProfileConfig, AdditionalScreen } from "../navigation/types";
|
|
33
|
+
import type { AccountScreenConfig } from "@umituz/react-native-auth";
|
|
34
|
+
|
|
35
|
+
export interface UseSettingsScreenConfigParams {
|
|
36
|
+
appInfo: AppInfo;
|
|
37
|
+
faqData?: FAQData;
|
|
38
|
+
isPremium: boolean;
|
|
39
|
+
onFeedbackSubmit: (data: FeedbackFormData) => Promise<void>;
|
|
40
|
+
additionalScreens?: AdditionalScreen[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SettingsScreenConfigResult {
|
|
44
|
+
settingsConfig: SettingsConfig;
|
|
45
|
+
userProfile: UserProfileConfig;
|
|
46
|
+
accountConfig: AccountScreenConfig;
|
|
47
|
+
translatedFaqData: FAQData | undefined;
|
|
48
|
+
isLoading: boolean;
|
|
49
|
+
isAuthReady: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const useSettingsScreenConfig = (
|
|
53
|
+
params: UseSettingsScreenConfigParams
|
|
54
|
+
): SettingsScreenConfigResult => {
|
|
55
|
+
const { appInfo, faqData, isPremium, onFeedbackSubmit } = params;
|
|
56
|
+
|
|
57
|
+
const { t } = useLocalization();
|
|
58
|
+
const { user, loading, isAuthReady, signOut } = useAuth();
|
|
59
|
+
const { deleteAccount } = useAccountManagement();
|
|
60
|
+
const userProfileData = useUserProfile({});
|
|
61
|
+
const { showAuthModal } = useAuthModalStore();
|
|
62
|
+
|
|
63
|
+
const handleRatePress = useCallback(async () => {
|
|
64
|
+
const url = appInfo.appStoreUrl;
|
|
65
|
+
if (url && (await Linking.canOpenURL(url))) {
|
|
66
|
+
await Linking.openURL(url);
|
|
67
|
+
}
|
|
68
|
+
}, [appInfo.appStoreUrl]);
|
|
69
|
+
|
|
70
|
+
const handleSignOut = useCallback(async () => {
|
|
71
|
+
try {
|
|
72
|
+
await signOut();
|
|
73
|
+
} catch {
|
|
74
|
+
AlertService.createErrorAlert(t("common.error"), t("auth.errors.unknownError"));
|
|
75
|
+
}
|
|
76
|
+
}, [signOut, t]);
|
|
77
|
+
|
|
78
|
+
const handleDeleteAccount = useCallback(async () => {
|
|
79
|
+
try {
|
|
80
|
+
await deleteAccount();
|
|
81
|
+
} catch {
|
|
82
|
+
AlertService.createErrorAlert(t("common.error"), t("settings.account.deleteError"));
|
|
83
|
+
}
|
|
84
|
+
}, [deleteAccount, t]);
|
|
85
|
+
|
|
86
|
+
const handleSignIn = useCallback(() => {
|
|
87
|
+
showAuthModal(() => {}, "login");
|
|
88
|
+
}, [showAuthModal]);
|
|
89
|
+
|
|
90
|
+
const settingsConfig = useMemo((): SettingsConfig => ({
|
|
91
|
+
appearance: createAppearanceConfig(t),
|
|
92
|
+
language: createLanguageConfig(t),
|
|
93
|
+
notifications: createNotificationsConfig(t),
|
|
94
|
+
feedback: createFeedbackConfig(t, onFeedbackSubmit),
|
|
95
|
+
about: createAboutConfig(t),
|
|
96
|
+
legal: createLegalConfig(t),
|
|
97
|
+
faqs: createFAQConfig(t),
|
|
98
|
+
rating: createRatingConfig(t, handleRatePress, appInfo.appStoreUrl || ""),
|
|
99
|
+
subscription: createSubscriptionConfig(t, isPremium, "SubscriptionDetail"),
|
|
100
|
+
disclaimer: false,
|
|
101
|
+
}), [t, onFeedbackSubmit, handleRatePress, appInfo.appStoreUrl, isPremium]);
|
|
102
|
+
|
|
103
|
+
const userProfile = useMemo((): UserProfileConfig => {
|
|
104
|
+
const isAnonymous = userProfileData?.isAnonymous ?? true;
|
|
105
|
+
return {
|
|
106
|
+
displayName: userProfileData?.displayName || t("settings.profile.anonymousName"),
|
|
107
|
+
userId: userProfileData?.userId,
|
|
108
|
+
isAnonymous,
|
|
109
|
+
avatarUrl: userProfileData?.avatarUrl,
|
|
110
|
+
onPress: isAnonymous ? handleSignIn : undefined,
|
|
111
|
+
accountSettingsRoute: isAnonymous ? undefined : "Account",
|
|
112
|
+
};
|
|
113
|
+
}, [userProfileData, t, handleSignIn]);
|
|
114
|
+
|
|
115
|
+
const accountConfig = useMemo((): AccountScreenConfig => {
|
|
116
|
+
const isAnonymous = user?.isAnonymous ?? true;
|
|
117
|
+
return {
|
|
118
|
+
profile: {
|
|
119
|
+
displayName: userProfileData?.displayName || user?.displayName || t("settings.profile.anonymousName"),
|
|
120
|
+
userId: userProfileData?.userId || user?.uid,
|
|
121
|
+
isAnonymous,
|
|
122
|
+
avatarUrl: userProfileData?.avatarUrl || user?.photoURL || undefined,
|
|
123
|
+
benefits: isAnonymous ? [
|
|
124
|
+
t("settings.profile.benefits.freeCredits"),
|
|
125
|
+
t("settings.profile.benefits.saveHistory"),
|
|
126
|
+
t("settings.profile.benefits.syncDevices"),
|
|
127
|
+
t("settings.profile.benefits.cloudSync"),
|
|
128
|
+
t("settings.profile.benefits.secureBackup"),
|
|
129
|
+
] : undefined,
|
|
130
|
+
},
|
|
131
|
+
isAnonymous,
|
|
132
|
+
editProfileText: t("settings.account.editProfile"),
|
|
133
|
+
onSignIn: handleSignIn,
|
|
134
|
+
accountActions: {
|
|
135
|
+
onLogout: handleSignOut,
|
|
136
|
+
onDeleteAccount: handleDeleteAccount,
|
|
137
|
+
logoutText: t("settings.account.logout"),
|
|
138
|
+
logoutConfirmTitle: t("settings.account.logoutConfirmTitle"),
|
|
139
|
+
logoutConfirmMessage: t("settings.account.logoutConfirmMessage"),
|
|
140
|
+
deleteAccountText: t("settings.account.deleteAccount"),
|
|
141
|
+
deleteConfirmTitle: t("settings.account.deleteConfirmTitle"),
|
|
142
|
+
deleteConfirmMessage: t("settings.account.deleteConfirmMessage"),
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}, [user, userProfileData, handleSignIn, handleSignOut, handleDeleteAccount, t]);
|
|
146
|
+
|
|
147
|
+
const translatedFaqData = useMemo((): FAQData | undefined => {
|
|
148
|
+
if (!faqData) return undefined;
|
|
149
|
+
return {
|
|
150
|
+
categories: faqData.categories.map((category) => ({
|
|
151
|
+
id: category.id,
|
|
152
|
+
title: t(category.title),
|
|
153
|
+
items: category.items.map((item) => ({
|
|
154
|
+
id: item.id,
|
|
155
|
+
question: t(item.question, { appName: appInfo.name }),
|
|
156
|
+
answer: t(item.answer, { appName: appInfo.name }),
|
|
157
|
+
})),
|
|
158
|
+
})),
|
|
159
|
+
};
|
|
160
|
+
}, [faqData, t, appInfo.name]);
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
settingsConfig,
|
|
164
|
+
userProfile,
|
|
165
|
+
accountConfig,
|
|
166
|
+
translatedFaqData,
|
|
167
|
+
isLoading: loading,
|
|
168
|
+
isAuthReady,
|
|
169
|
+
};
|
|
170
|
+
};
|