handle user profile session
This commit is contained in:
+94
-76
@@ -42,8 +42,8 @@ export default function LoginScreen() {
|
||||
const fade = useRef(new Animated.Value(0)).current;
|
||||
const slide = useRef(new Animated.Value(24)).current;
|
||||
const ctaScale = useRef(new Animated.Value(1)).current;
|
||||
const user = useSelector((state:any) => state.user)
|
||||
console.log("current user ----",user)
|
||||
const user = useSelector((state: any) => state.user)
|
||||
console.log("current user ----", user)
|
||||
useEffect(() => {
|
||||
Animated.parallel([
|
||||
Animated.timing(fade, { toValue: 1, duration: 600, useNativeDriver: true }),
|
||||
@@ -51,91 +51,109 @@ export default function LoginScreen() {
|
||||
]).start();
|
||||
}, []);
|
||||
|
||||
const handleContinue = async () => {
|
||||
if (mobile.length === 10) {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await axios.get(LOGIN_URL + mobile);
|
||||
console.log("OTP sent response:", res)
|
||||
|
||||
if (res.data.statusCode === 200) {
|
||||
navigation.navigate("OtpVarify", { mobile });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Login error:", error);
|
||||
Alert.alert("Error", "Failed to send OTP. Please try again.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
const handleContinue = async () => {
|
||||
if (mobile.length === 10) {
|
||||
setLoading(true);
|
||||
try {
|
||||
console.log("LOGIN_URL console:", LOGIN_URL, "mobile:", mobile);
|
||||
|
||||
const res = await axios.get(LOGIN_URL, {
|
||||
params: { mobile },
|
||||
});
|
||||
|
||||
console.log("OTP sent response:", res.data);
|
||||
|
||||
if (res.data.statusCode === 200) {
|
||||
navigation.navigate("OtpVarify", { mobile });
|
||||
} else {
|
||||
Alert.alert("Error", res.data.message || "Failed to send OTP");
|
||||
}
|
||||
} else {
|
||||
Alert.alert("Please enter a valid 10-digit mobile number");
|
||||
} catch (error: any) {
|
||||
console.error("Login error:", error);
|
||||
|
||||
if (axios.isAxiosError(error)) {
|
||||
console.log("Error message:", error.message);
|
||||
console.log("Error response:", error.response?.data);
|
||||
console.log("Error status:", error.response?.status);
|
||||
console.log("Error headers:", error.response?.headers);
|
||||
} else {
|
||||
console.log("Unexpected error:", error);
|
||||
}
|
||||
|
||||
Alert.alert("Error", "Failed to send OTP. Please try again.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
Alert.alert("Please enter a valid 10-digit mobile number");
|
||||
}
|
||||
};
|
||||
|
||||
const onPressIn = () =>
|
||||
Animated.spring(ctaScale, {
|
||||
toValue: 0.97,
|
||||
useNativeDriver: true,
|
||||
speed: 20,
|
||||
bounciness: 0,
|
||||
}).start();
|
||||
|
||||
const onPressOut = () =>
|
||||
Animated.spring(ctaScale, {
|
||||
toValue: 1,
|
||||
useNativeDriver: true,
|
||||
speed: 20,
|
||||
bounciness: 6,
|
||||
}).start();
|
||||
const onPressIn = () =>
|
||||
Animated.spring(ctaScale, {
|
||||
toValue: 0.97,
|
||||
useNativeDriver: true,
|
||||
speed: 20,
|
||||
bounciness: 0,
|
||||
}).start();
|
||||
|
||||
return (
|
||||
<KeyboardAvoidingView
|
||||
style={styles.container}
|
||||
behavior={Platform.OS === "ios" ? "padding" : undefined}
|
||||
>
|
||||
<StatusBar barStyle="dark-content" backgroundColor={theme.background} />
|
||||
const onPressOut = () =>
|
||||
Animated.spring(ctaScale, {
|
||||
toValue: 1,
|
||||
useNativeDriver: true,
|
||||
speed: 20,
|
||||
bounciness: 6,
|
||||
}).start();
|
||||
|
||||
{/* Top content */}
|
||||
<View style={styles.topSection}>
|
||||
<Text style={styles.brand}>CircleCollect</Text>
|
||||
<Text style={styles.title}>Welcome Back 👋</Text>
|
||||
<Text style={styles.subtitle}>
|
||||
Enter your mobile number to sign in and continue.
|
||||
</Text>
|
||||
return (
|
||||
<KeyboardAvoidingView
|
||||
style={styles.container}
|
||||
behavior={Platform.OS === "ios" ? "padding" : undefined}
|
||||
>
|
||||
<StatusBar barStyle="dark-content" backgroundColor={theme.background} />
|
||||
|
||||
<Animated.View
|
||||
style={[
|
||||
styles.inputWrapper,
|
||||
{ opacity: fade, transform: [{ translateY: slide }] },
|
||||
]}
|
||||
>
|
||||
<CustomInput
|
||||
label="Mobile Number"
|
||||
placeholder="Enter Mobile Number"
|
||||
value={mobile}
|
||||
onChangeText={setMobile}
|
||||
keyboardType="phone-pad"
|
||||
maxLength={10}
|
||||
icon="call-outline"
|
||||
/>
|
||||
</Animated.View>
|
||||
</View>
|
||||
{/* Top content */}
|
||||
<View style={styles.topSection}>
|
||||
<Text style={styles.brand}>CircleCollect</Text>
|
||||
<Text style={styles.title}>Welcome Back 👋</Text>
|
||||
<Text style={styles.subtitle}>
|
||||
Enter your mobile number to sign in and continue.
|
||||
</Text>
|
||||
|
||||
{/* Bottom Button */}
|
||||
<Animated.View
|
||||
style={[styles.bottomSection, { transform: [{ scale: ctaScale }] }]}
|
||||
style={[
|
||||
styles.inputWrapper,
|
||||
{ opacity: fade, transform: [{ translateY: slide }] },
|
||||
]}
|
||||
>
|
||||
<CustomButton title={loading ? "Loading..." : "Continue"} onPress={handleContinue} icon="arrow-forward" />
|
||||
|
||||
<Text style={styles.footerText}>
|
||||
By continuing, you agree to our{" "}
|
||||
<Text style={{ color: theme.accent, fontWeight: "600" }}>
|
||||
Terms & Privacy
|
||||
</Text>
|
||||
</Text>
|
||||
<CustomInput
|
||||
label="Mobile Number"
|
||||
placeholder="Enter Mobile Number"
|
||||
value={mobile}
|
||||
onChangeText={setMobile}
|
||||
keyboardType="phone-pad"
|
||||
maxLength={10}
|
||||
icon="call-outline"
|
||||
/>
|
||||
</Animated.View>
|
||||
</KeyboardAvoidingView>
|
||||
);
|
||||
</View>
|
||||
|
||||
{/* Bottom Button */}
|
||||
<Animated.View
|
||||
style={[styles.bottomSection, { transform: [{ scale: ctaScale }] }]}
|
||||
>
|
||||
<CustomButton title={loading ? "Loading..." : "Continue"} onPress={handleContinue} icon="arrow-forward" />
|
||||
|
||||
<Text style={styles.footerText}>
|
||||
By continuing, you agree to our{" "}
|
||||
<Text style={{ color: theme.accent, fontWeight: "600" }}>
|
||||
Terms & Privacy
|
||||
</Text>
|
||||
</Text>
|
||||
</Animated.View>
|
||||
</KeyboardAvoidingView>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
|
||||
Reference in New Issue
Block a user