@umituz/react-native-onboarding 3.0.1 → 3.0.3
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-onboarding",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Advanced onboarding flow for React Native apps with personalization questions, theme-aware colors, animations, and customizable slides. SOLID, DRY, KISS principles applied.",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -3,16 +3,12 @@
|
|
|
3
3
|
* Single Responsibility: Async store actions
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
storageRepository,
|
|
8
|
-
StorageKey,
|
|
9
|
-
unwrap,
|
|
10
|
-
} from "@umituz/react-native-storage";
|
|
6
|
+
import { storageRepository, unwrap } from "@umituz/react-native-storage";
|
|
11
7
|
import type { OnboardingUserData } from "../../domain/entities/OnboardingUserData";
|
|
12
8
|
import type { OnboardingStoreState } from "./OnboardingStoreState";
|
|
13
9
|
|
|
14
|
-
const DEFAULT_STORAGE_KEY =
|
|
15
|
-
const USER_DATA_STORAGE_KEY = "@
|
|
10
|
+
const DEFAULT_STORAGE_KEY = "@onboarding:completed";
|
|
11
|
+
const USER_DATA_STORAGE_KEY = "@onboarding:user_data";
|
|
16
12
|
|
|
17
13
|
export interface OnboardingStoreActions {
|
|
18
14
|
initialize: (storageKey?: string) => Promise<void>;
|
|
@@ -67,22 +63,32 @@ export function createOnboardingStoreActions(
|
|
|
67
63
|
try {
|
|
68
64
|
set({ loading: true, error: null });
|
|
69
65
|
|
|
66
|
+
// Ensure storage write completes before proceeding
|
|
70
67
|
const result = await storageRepository.setString(storageKey, "true");
|
|
71
68
|
|
|
69
|
+
if (!result.success) {
|
|
70
|
+
throw new Error("Failed to save completion status to storage");
|
|
71
|
+
}
|
|
72
|
+
|
|
72
73
|
const userData = { ...get().userData };
|
|
73
74
|
userData.completedAt = new Date().toISOString();
|
|
74
75
|
|
|
75
|
-
await storageRepository.setItem(USER_DATA_STORAGE_KEY, userData);
|
|
76
|
+
const userDataResult = await storageRepository.setItem(USER_DATA_STORAGE_KEY, userData);
|
|
76
77
|
|
|
78
|
+
if (!userDataResult.success) {
|
|
79
|
+
throw new Error("Failed to save user data to storage");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Only update state after storage write is confirmed
|
|
77
83
|
set({
|
|
78
|
-
isOnboardingComplete:
|
|
84
|
+
isOnboardingComplete: true,
|
|
79
85
|
userData,
|
|
80
86
|
loading: false,
|
|
81
|
-
error:
|
|
87
|
+
error: null,
|
|
82
88
|
});
|
|
83
89
|
|
|
84
90
|
if (__DEV__) {
|
|
85
|
-
console.log('[OnboardingStore] Onboarding completed successfully');
|
|
91
|
+
console.log('[OnboardingStore] Onboarding completed and persisted successfully');
|
|
86
92
|
}
|
|
87
93
|
} catch (error) {
|
|
88
94
|
set({
|
|
@@ -93,6 +99,8 @@ export function createOnboardingStoreActions(
|
|
|
93
99
|
if (__DEV__) {
|
|
94
100
|
console.error('[OnboardingStore] Completion error:', error);
|
|
95
101
|
}
|
|
102
|
+
|
|
103
|
+
throw error;
|
|
96
104
|
}
|
|
97
105
|
},
|
|
98
106
|
|
|
@@ -100,22 +108,33 @@ export function createOnboardingStoreActions(
|
|
|
100
108
|
try {
|
|
101
109
|
set({ loading: true, error: null });
|
|
102
110
|
|
|
111
|
+
// Ensure storage write completes before proceeding
|
|
103
112
|
const result = await storageRepository.setString(storageKey, "true");
|
|
104
113
|
|
|
114
|
+
if (!result.success) {
|
|
115
|
+
throw new Error("Failed to save skip status to storage");
|
|
116
|
+
}
|
|
117
|
+
|
|
105
118
|
const userData = { ...get().userData };
|
|
106
119
|
userData.skipped = true;
|
|
107
120
|
userData.completedAt = new Date().toISOString();
|
|
108
|
-
await storageRepository.setItem(USER_DATA_STORAGE_KEY, userData);
|
|
109
121
|
|
|
122
|
+
const userDataResult = await storageRepository.setItem(USER_DATA_STORAGE_KEY, userData);
|
|
123
|
+
|
|
124
|
+
if (!userDataResult.success) {
|
|
125
|
+
throw new Error("Failed to save user data to storage");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Only update state after storage write is confirmed
|
|
110
129
|
set({
|
|
111
|
-
isOnboardingComplete:
|
|
130
|
+
isOnboardingComplete: true,
|
|
112
131
|
userData,
|
|
113
132
|
loading: false,
|
|
114
|
-
error:
|
|
133
|
+
error: null,
|
|
115
134
|
});
|
|
116
135
|
|
|
117
136
|
if (__DEV__) {
|
|
118
|
-
console.log('[OnboardingStore] Onboarding skipped successfully');
|
|
137
|
+
console.log('[OnboardingStore] Onboarding skipped and persisted successfully');
|
|
119
138
|
}
|
|
120
139
|
} catch (error) {
|
|
121
140
|
set({
|
|
@@ -126,6 +145,8 @@ export function createOnboardingStoreActions(
|
|
|
126
145
|
if (__DEV__) {
|
|
127
146
|
console.error('[OnboardingStore] Skip error:', error);
|
|
128
147
|
}
|
|
148
|
+
|
|
149
|
+
throw error;
|
|
129
150
|
}
|
|
130
151
|
},
|
|
131
152
|
|