handle notification type and navigate using deeplinking

This commit is contained in:
Jaanu423
2025-10-08 16:36:37 +05:30
25 changed files with 1228 additions and 530 deletions
+180 -174
View File
@@ -29,7 +29,7 @@ import { clearUser, setUserData } from "../../redux/userSlice";
import { StackNavigationProp } from "@react-navigation/stack";
import { RootStackParamList } from "../../navigation/AppNavigator";
import { firebase } from "@react-native-firebase/messaging";
import FirebaseService from "../../utils/firebase/firebaseServices";
import FirebaseService, { deleteFcmToken } from "../../utils/firebase/firebaseServices";
type UserProfile = {
@@ -157,13 +157,17 @@ const Profile = () => {
const result = await response.json();
if (result.status === "success") {
Alert.alert("Success", "Profile updated successfully");
setEditing(false);
fetchUserProfile(); // reload updated data
} else {
Alert.alert("Error", "Failed to update profile");
}
console.log("result for profile update :", result);
// Alert.alert("Success", "Profile updated successfully");
// setEditing(false);
// fetchUserProfile();
// if (result.status === "success") {
// Alert.alert("Success", "Profile updated successfully");
// setEditing(false);
// fetchUserProfile(); // reload updated data
// } else {
// Alert.alert("Error", "Failed to update profile");
// }
} catch (error) {
console.error("❌ Error updating profile:", error);
// Alert.alert("Error", "Could not update profile");
@@ -305,7 +309,7 @@ const Profile = () => {
return;
}
await FirebaseService.deleteFcmToken();
await deleteFcmToken();
// Clear stored credentials
await Keychain.resetGenericPassword();
@@ -478,194 +482,196 @@ const Profile = () => {
/>
</View>
</View>
<View style ={{backgroundColor:colors.pastelBlue,borderRadius:20,elevation:5,paddingVertical:10}}>
<View style={styles.detailRow}>
<Ionicons name="person" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Name</Text>
<Text style={styles.detailText}>{user?.firstName} {user?.lastName}</Text>
<View style={{ backgroundColor: colors.pastelBlue, borderRadius: 20, elevation: 5, paddingVertical: 10 }}>
<View style={styles.detailRow}>
<Ionicons name="person" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Name</Text>
<Text style={styles.detailText}>{user?.firstName} {user?.lastName}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="mail" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Email</Text>
<Text style={styles.detailText}>{user?.email || "Not provided"}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="call" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Mobile</Text>
<Text style={styles.detailText}>{user?.mobile || "Not provided"}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="at-circle" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Usernames</Text>
<Text style={styles.detailText}>{user?.username}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="location" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Address</Text>
<Text style={styles.detailText}>{user?.address || "Not provided"}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="male-female" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Gender</Text>
<Text style={styles.detailText}>{user?.gender || "Not specified"}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="key" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Role</Text>
<Text style={styles.detailText}>{user?.role || "User"}</Text>
</View>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="mail" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Email</Text>
<Text style={styles.detailText}>{user?.email || "Not provided"}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="call" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Mobile</Text>
<Text style={styles.detailText}>{user?.mobile || "Not provided"}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="at-circle" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Usernames</Text>
<Text style={styles.detailText}>{user?.username}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="location" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Address</Text>
<Text style={styles.detailText}>{user?.address || "Not provided"}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="male-female" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Gender</Text>
<Text style={styles.detailText}>{user?.gender || "Not specified"}</Text>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="key" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Role</Text>
<Text style={styles.detailText}>{user?.role || "User"}</Text>
</View>
</View>
</View>
{/* BANK DETAILS SECTION */}
<View style={{ marginTop: 20 }}>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<Text style={styles.sectionTitle}>Bank Information</Text>
{/* Navigate to a screen you will create for editing bank details */}
<CustomButton
title="Edit Bank Details"
onPress={() =>{ navigation.navigate("EditBankDetails", {
currentBankName: user?.bankName,
currentAccountNumber: user?.bankAccountNumber,
currentBranchCode: user?.branchCode,
})}}
onPress={() => {
navigation.navigate("EditBankDetails", {
currentBankName: user?.bankName,
currentAccountNumber: user?.bankAccountNumber,
currentBranchCode: user?.branchCode,
})
}}
icon="create-outline"
style={styles.editButton}
buttonBackground={colors.white}
buttonBackground={colors.white}
/>
</View>
<View style ={{backgroundColor:colors.pastelBlue,borderRadius:20,elevation:5,paddingVertical:10}}>
<View style={styles.detailRow}>
<Ionicons name="business" size={20} color={colors.black}style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Bank Name</Text>
<Text style={styles.detailText}>{user?.bankName || "Not provided"}</Text>
<View style={{ backgroundColor: colors.pastelBlue, borderRadius: 20, elevation: 5, paddingVertical: 10 }}>
<View style={styles.detailRow}>
<Ionicons name="business" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Bank Name</Text>
<Text style={styles.detailText}>{user?.bankName || "Not provided"}</Text>
</View>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="barcode" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Branch Code</Text>
<Text style={styles.detailText}>{user?.branchCode || "Not provided"}</Text>
<View style={styles.detailRow}>
<Ionicons name="barcode" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Branch Code</Text>
<Text style={styles.detailText}>{user?.branchCode || "Not provided"}</Text>
</View>
</View>
</View>
<View style={styles.detailRow}>
<Ionicons name="card" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Account Number</Text>
<Text style={styles.detailText}>{user?.bankAccountNumber || "Not provided"}</Text>
<View style={styles.detailRow}>
<Ionicons name="card" size={20} color={colors.black} style={styles.detailIcon} />
<View>
<Text style={styles.detailLabel}>Account Number</Text>
<Text style={styles.detailText}>{user?.bankAccountNumber || "Not provided"}</Text>
</View>
</View>
</View>
</View>
</View>
</View>
</>
) : (
<>
{/* Edit Form */}
<View style={styles.editSection}>
<Text style={styles.sectionTitle}>Edit Profile</Text>
<>
{/* Edit Form */}
<View style={styles.editSection}>
<Text style={styles.sectionTitle}>Edit Profile</Text>
<CustomInput
error=""
label="First Name"
placeholder="Enter first name"
value={user?.firstName ?? ""}
onChangeText={(text) => setUser({ ...user, firstName: text })}
icon="person"
/>
<CustomInput
error=""
label="First Name"
placeholder="Enter first name"
value={user?.firstName ?? ""}
onChangeText={(text) => setUser({ ...user, firstName: text })}
icon="person"
/>
<CustomInput
error=""
label="Last Name"
placeholder="Enter last name"
value={user?.lastName ?? ""}
onChangeText={(text) => setUser({ ...user, lastName: text })}
icon="person"
/>
<CustomInput
error=""
label="Last Name"
placeholder="Enter last name"
value={user?.lastName ?? ""}
onChangeText={(text) => setUser({ ...user, lastName: text })}
icon="person"
/>
<CustomInput
error=""
label="Email"
placeholder="Enter email"
value={user?.email ?? ""}
onChangeText={(text) => setUser({ ...user, email: text })}
icon="mail"
keyboardType="email-address"
/>
<CustomInput
error=""
label="Email"
placeholder="Enter email"
value={user?.email ?? ""}
onChangeText={(text) => setUser({ ...user, email: text })}
icon="mail"
keyboardType="email-address"
/>
<CustomInput
error=""
label="Username"
placeholder="Enter username"
value={user?.username ?? ""}
onChangeText={(text) => setUser({ ...user, username: text })}
icon="at"
/>
<CustomInput
error=""
label="Username"
placeholder="Enter username"
value={user?.username ?? ""}
onChangeText={(text) => setUser({ ...user, username: text })}
icon="at"
/>
<CustomInput
error=""
label="Address"
placeholder="Enter address"
value={user?.address ?? ""}
onChangeText={(text) => setUser({ ...user, address: text })}
icon="location"
multiline
/>
<CustomInput
error=""
label="Address"
placeholder="Enter address"
value={user?.address ?? ""}
onChangeText={(text) => setUser({ ...user, address: text })}
icon="location"
multiline
/>
<CustomInput
error=""
label="Gender"
placeholder="Enter gender"
value={user?.gender ?? ""}
onChangeText={(text) => setUser({ ...user, gender: text })}
icon="male-female"
/>
<CustomInput
error=""
label="Gender"
placeholder="Enter gender"
value={user?.gender ?? ""}
onChangeText={(text) => setUser({ ...user, gender: text })}
icon="male-female"
/>
<View style={styles.editButtons}>
<CustomButton
title="Save Changes"
onPress={updateProfile}
icon="save"
style={styles.saveButton}
buttonBackground={colors.pastelBlue}
/>
<CustomButton
title="Cancel"
onPress={() => setEditing(false)}
icon="close"
style={styles.cancelButton}
buttonBackground={colors.white}
/>
</View>
</View>
</>
<View style={styles.editButtons}>
<CustomButton
title="Save Changes"
onPress={updateProfile}
icon="save"
style={styles.saveButton}
buttonBackground={colors.pastelBlue}
/>
<CustomButton
title="Cancel"
onPress={() => setEditing(false)}
icon="close"
style={styles.cancelButton}
buttonBackground={colors.white}
/>
</View>
</View>
</>
)}
</View>
</ScrollView>
@@ -762,7 +768,7 @@ const styles = StyleSheet.create({
marginBottom: "40%",
},
sectionTitle: {
fontSize: 18,
fontSize: 18,
fontWeight: "700",
color: "#1e293b",
// marginBottom: 16,
@@ -778,7 +784,7 @@ const styles = StyleSheet.create({
},
detailIcon: {
marginRight: 20,
elevation:5
elevation: 5
},
detailLabel: {
fontSize: 12,
@@ -791,12 +797,12 @@ const styles = StyleSheet.create({
fontWeight: "500",
},
editButton: {
elevation:5,
elevation: 5,
paddingHorizontal: 10,
paddingVertical:4,
paddingVertical: 4,
borderRadius: 15,
borderWidth:2,
borderColor:colors.pastelBlue
borderWidth: 2,
borderColor: colors.pastelBlue
},
editSection: {
marginBottom: '100%',