themed css apply on home screen for both user

This commit is contained in:
Jaanu423
2025-09-26 10:14:33 +05:30
parent ced2134361
commit 8dbacb4ba5
3 changed files with 704 additions and 729 deletions
+545 -695
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -39,6 +39,7 @@ export type RootStackParamList = {
ManageJoinedGroup: { groupId: string | number }; ManageJoinedGroup: { groupId: string | number };
Invite: { groupId: string | number; code: string | number }; Invite: { groupId: string | number; code: string | number };
ManagementTabs:{ groupId: string | number;} ManagementTabs:{ groupId: string | number;}
TransactionList:undefined
}; };
const Stack = createNativeStackNavigator<RootStackParamList>(); const Stack = createNativeStackNavigator<RootStackParamList>();
+158 -34
View File
@@ -19,36 +19,108 @@ import { PROFILE_URL } from "../../utils/ApiUrls";
import * as Keychain from "react-native-keychain"; import * as Keychain from "react-native-keychain";
import { setUserData } from "../../redux/userSlice"; import { setUserData } from "../../redux/userSlice";
import { TabNavigationProp } from "../../navigation/BottomTabs"; import { TabNavigationProp } from "../../navigation/BottomTabs";
import GroupsTabs from "./GroupsTabs";
import UserProfileStatus from "./UserProfileStatus";
import UserHome from "./user-home/UserHome";
import AnimatedCard from "../../components/common/AnimatedCard";
import { IoniconsIconName } from "@react-native-vector-icons/ionicons";
// Enable layout animation for Android // Enable layout animation for Android
if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) { if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) {
UIManager.setLayoutAnimationEnabledExperimental(true); UIManager.setLayoutAnimationEnabledExperimental(true);
} }
type UserProfile = {
id: string;
userId: number;
firstName: string | null;
lastName: string | null;
imageBlob: string | null;
role?: string;
}
// --- TYPE DEFINITIONS --- // --- TYPE DEFINITIONS ---
interface ActionItem { interface ActionItem {
id: string; id: string;
title: string; title: string;
action: string; action: string;
tab?: "My Groups" | "Joined Groups" | "Requests" | "Your Requests"; tab?: "My Groups" | "Joined Groups" | "Requests" | "Your Requests";
imageUri: string;
iconName?: IoniconsIconName;
backOne?: string;
backTwo?: string;
subtitle?: string
} }
// Data for the grid items
// Organizer Actions
const organizerActions: ActionItem[] = [ const organizerActions: ActionItem[] = [
{ id: "1", title: "My Groups", action: "NAVIGATE_MANAGEMENT", tab: "My Groups", imageUri: "https://via.placeholder.com/60" }, {
{ id: "2", title: "Joined Groups", action: "NAVIGATE_MANAGEMENT", tab: "Joined Groups", imageUri: "https://via.placeholder.com/60" }, id: "1",
{ id: "3", title: "Requests", action: "NAVIGATE_MANAGEMENT", tab: "Requests", imageUri: "https://via.placeholder.com/60" }, title: "My Groups",
subtitle: "Manage your own groups",
action: "NAVIGATE_MANAGEMENT",
tab: "My Groups",
iconName: "people-outline",
backOne: "#4facfe",
backTwo: "#00f2fe",
},
{
id: "2",
title: "Joined Groups",
subtitle: "View groups you’ve joined",
action: "NAVIGATE_MANAGEMENT",
tab: "Joined Groups",
iconName: "person-outline",
backOne: "#43e97b",
backTwo: "#38f9d7",
},
{
id: "3",
title: "Requests",
subtitle: "Check group requests",
action: "NAVIGATE_MANAGEMENT",
tab: "Requests",
iconName: "notifications-outline",
backOne: "#fa709a",
backTwo: "#fee140",
},
]; ];
// User Actions
const userActions: ActionItem[] = [ const userActions: ActionItem[] = [
{ id: "1", title: "Joined Groups", action: "NAVIGATE_MANAGEMENT", tab: "Joined Groups", imageUri: "https://via.placeholder.com/60" }, {
{ id: "2", title: "Your Requests", action: "NAVIGATE_MANAGEMENT", tab: "Your Requests", imageUri: "https://via.placeholder.com/60" }, id: "1",
{ id: "3", title: "Action 3", action: "ACTION_3", imageUri: "https://via.placeholder.com/60" }, title: "Joined Groups",
{ id: "4", title: "Action 4", action: "ACTION_4", imageUri: "https://via.placeholder.com/60" }, subtitle: "See your joined groups",
action: "NAVIGATE_MANAGEMENT",
tab: "Joined Groups",
iconName: "person-outline",
backOne: "#43e97b",
backTwo: "#38f9d7",
},
{
id: "2",
title: "Your Requests",
subtitle: "Track your group requests",
action: "NAVIGATE_MANAGEMENT",
tab: "Your Requests",
iconName: "mail-outline",
backOne: "#ff9a9e",
backTwo: "#fad0c4",
},
{
id: "3",
title: "Transaction",
subtitle: "View your transaction history",
action: "TRANSACTION",
iconName: "calculator-outline",
backOne: "#4facfe",
backTwo: "#00f2fe",
},
]; ];
const Home: React.FC = () => { const Home: React.FC = () => {
const user = useSelector((state: any) => state.user); const user = useSelector((state: any) => state.user);
const navigation = useNavigation<TabNavigationProp>(); const navigation = useNavigation<TabNavigationProp>();
@@ -56,28 +128,66 @@ const Home: React.FC = () => {
// --- FIXED: Conditional logic moved inside the component --- // --- FIXED: Conditional logic moved inside the component ---
const actions = user.role === 'ORGANIZER' ? organizerActions : userActions; const actions = user.role === 'ORGANIZER' ? organizerActions : userActions;
const [apiUser, setApiUser] = useState<UserProfile | null | any>(null)
const fetchUserProfile = async () => { const fetchUserProfile = async () => {
try { try {
const credentials = await Keychain.getGenericPassword(); const credentials = await Keychain.getGenericPassword();
if (!credentials) return; if (!credentials) {
return;
}
const token = credentials.password; const token = credentials.password;
const response = await fetch(PROFILE_URL, { console.log("token : ", token)
method: "GET", const response = await fetch(
headers: { Accept: "*/*", Authorization: `Bearer ${token}` }, PROFILE_URL,
}); {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${token}`,
},
}
);
const result = await response.json(); const result = await response.json();
console.log("👤 Profile Response:", result);
if (result.status === "success") { if (result.status === "success") {
// No need for apiUser state, just dispatch to Redux setApiUser(result.data);
dispatch(setUserData({ ...result.data, profileStatus: true })); dispatch(
setUserData({
id: result.data.id,
userId: result.data.userId,
username: result.data.username,
firstName: result.data.firstName,
lastName: result.data.lastName,
gender: result.data.gender,
mobile: result.data.mobile,
email: result.data.email,
address: result.data.address,
bankAccountNumber: result.data.bankAccountNumber,
bankName: result.data.bankName,
branchCode: result.data.branchCode,
profilePicture: result.data.filePath,
filePath: result.data.filePath,
imageBlob: result.data.imageBlob,
role: result.data.role,
organizerId: result.data.organizerId,
organizerStatus: result.data.organizerStatus,
profileStatus: true,
})
);
} }
} catch (error) { } catch (error) {
console.error("❌ Error fetching profile:", error); console.error("❌ Error fetching profile:", error);
} }
}; };
useEffect(() => {
fetchUserProfile();
}, []);
useEffect(() => { useEffect(() => {
fetchUserProfile(); fetchUserProfile();
}, []); }, []);
@@ -86,8 +196,8 @@ const Home: React.FC = () => {
const handleActionPress = (item: ActionItem) => { const handleActionPress = (item: ActionItem) => {
if (item.action === "NAVIGATE_MANAGEMENT" && item.tab) { if (item.action === "NAVIGATE_MANAGEMENT" && item.tab) {
navigation.navigate('Management', { actionTab: item.tab }); navigation.navigate('Management', { actionTab: item.tab });
} else if (item.action === "ACTION_3") { } else if (item.action === "TRANSACTION") {
Alert.alert("Action 3 pressed"); navigation.navigate("TransactionList" as never)
} else if (item.action === "ACTION_4") { } else if (item.action === "ACTION_4") {
Alert.alert("Action 4 pressed"); Alert.alert("Action 4 pressed");
} else { } else {
@@ -97,29 +207,42 @@ const Home: React.FC = () => {
// Render function for each grid item // Render function for each grid item
const renderGridItem: ListRenderItem<ActionItem> = ({ item }) => ( const renderGridItem: ListRenderItem<ActionItem> = ({ item }) => (
<TouchableOpacity
style={styles.gridButton} <AnimatedCard
key={item.id}
title={item.title}
subtitle={item.subtitle}
iconName={item.iconName}
backOne={item.backOne}
backTwo={item.backTwo}
onPress={() => handleActionPress(item)} onPress={() => handleActionPress(item)}
> />
{/* FIXED: 'imageUri' was missing from your data objects */}
<Image source={{ uri: item.imageUri }} style={styles.gridIcon} />
<Text style={styles.gridLabel}>{item.title}</Text>
</TouchableOpacity>
); );
return ( return (
<AppView barStyle="dark-content" style={styles.container}> <AppView barStyle="dark-content" style={styles.container}>
<View style={styles.header}> <View style={styles.header}>
<Text style={styles.headerTitle}>Home</Text> <Text style={styles.greeting}>Hello, {user.firstName || apiUser?.firstName} {user.lastName || apiUser?.lastName}👋</Text>
<TouchableOpacity onPress={() => navigation.navigate("Profile" as never)}>
<Image
source={
user.imageBlob
&& { uri: user.imageBlob || apiUser?.imageBlob ? `data:image/jpeg;base64,${user.imageBlob || apiUser?.imageBlob}` : user.profilePicture || apiUser?.imageBlob }
}
style={{ width: 40, height: 40, borderRadius: 20, borderColor: colors.primary, borderWidth: 2 }}
/>
</TouchableOpacity>
</View> </View>
{/* Status */}
<UserProfileStatus />
{/* {user?.role === "USER" || apiUser?.role === "USER" ? <UserHome /> :
<GroupsTabs />} */}
<FlatList <FlatList
data={actions} data={actions}
renderItem={renderGridItem} renderItem={renderGridItem}
keyExtractor={(item) => item.id} keyExtractor={(item) => item.id}
numColumns={2} // columnWrapperStyle={styles.row}
columnWrapperStyle={styles.row} // contentContainerStyle={{ paddingHorizontal: 8 }}
contentContainerStyle={{ paddingHorizontal: 8 }}
/> />
</AppView> </AppView>
); );
@@ -133,10 +256,10 @@ const styles = StyleSheet.create({
backgroundColor: '#F4F6F8' backgroundColor: '#F4F6F8'
}, },
header: { header: {
justifyContent: "center", flexDirection: "row",
justifyContent: "space-between",
alignItems: "center", alignItems: "center",
paddingVertical: 12, marginBottom: 12,
marginBottom: 16,
}, },
headerTitle: { headerTitle: {
fontSize: 22, fontSize: 22,
@@ -147,6 +270,7 @@ const styles = StyleSheet.create({
flex: 1, flex: 1,
justifyContent: "space-around", justifyContent: "space-around",
}, },
greeting: { fontSize: 22, fontWeight: "600", color: colors.Home },
gridButton: { gridButton: {
flex: 1, flex: 1,
margin: 8, margin: 8,