home changes
This commit is contained in:
@@ -19,7 +19,7 @@ import type { StackNavigationProp } from '@react-navigation/stack';
|
||||
import { RootStackParamList } from '../navigation/AppNavigator';
|
||||
import LinearGradient from 'react-native-linear-gradient';
|
||||
import Ionicons from '@react-native-vector-icons/ionicons';
|
||||
import MaterialRipple from 'react-native-material-ripple'; // For the button ripple effect
|
||||
import MaterialRipple from 'react-native-material-ripple';
|
||||
import CustomAlert from '../components/CostomAlart';
|
||||
import colors from '../components/colors';
|
||||
|
||||
@@ -310,4 +310,4 @@ const styles = StyleSheet.create({
|
||||
textAlign: 'center',
|
||||
maxWidth: 300,
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -22,6 +22,7 @@ import UserProfileStatus from "./UserProfileStatus";
|
||||
import AnimatedCard from "../../components/common/AnimatedCard";
|
||||
import { Ionicons, IoniconsIconName } from "@react-native-vector-icons/ionicons";
|
||||
import { apiCall } from "../../utils/ApiHelper";
|
||||
import CustomAlert, { CustomAlertProps } from "../../components/CostomAlart";
|
||||
|
||||
if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) {
|
||||
UIManager.setLayoutAnimationEnabledExperimental(true);
|
||||
@@ -34,6 +35,7 @@ type UserProfile = {
|
||||
lastName: string | null;
|
||||
imageBlob: string | null;
|
||||
role?: string;
|
||||
organizerStatus?: string;
|
||||
};
|
||||
|
||||
interface ActionItem {
|
||||
@@ -65,18 +67,21 @@ const userActions: ActionItem[] = [
|
||||
const Home: React.FC = () => {
|
||||
const user = useSelector((state: any) => state.user);
|
||||
const notifications = useSelector(
|
||||
(state: any) => state.notifications.notifications
|
||||
);
|
||||
(state: any) => state.notifications.notifications
|
||||
);
|
||||
const navigation = useNavigation<TabNavigationProp>();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const actions = user.role === 'ORGANIZER' ? organizerActions : userActions;
|
||||
const [apiUser, setApiUser] = useState<UserProfile | null>(null);
|
||||
const [alartVisible, setalartVisible] = useState<boolean>(false)
|
||||
const [alartAction, setAlartAction] = useState<CustomAlertProps | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUserProfile = async () => {
|
||||
try {
|
||||
const result = await apiCall(PROFILE_URL, "GET") as any;
|
||||
console.log(PROFILE_URL, result)
|
||||
if (result.status === "success") {
|
||||
setApiUser(result.data);
|
||||
dispatch(setUserData({ ...result.data, profileStatus: true }));
|
||||
@@ -96,10 +101,61 @@ const Home: React.FC = () => {
|
||||
} else if (item.action === "TRANSACTION") {
|
||||
navigation.navigate("TransactionList" as never);
|
||||
} else if (item.action === "NAVIGATE_CREATE_GROUP") {
|
||||
|
||||
navigation.navigate("GroupCreation" as never);
|
||||
} else {
|
||||
Alert.alert("Unknown action", item.title);
|
||||
switch (apiUser?.organizerStatus) {
|
||||
case 'NOT_APPLIED':
|
||||
setalartVisible(true);
|
||||
setAlartAction({
|
||||
visible: true,
|
||||
title: "Become organizer",
|
||||
message: "You have to become organizer for creating groups",
|
||||
buttons: [
|
||||
{
|
||||
text: "Continue",
|
||||
onPress: () => {
|
||||
setalartVisible(false);
|
||||
navigation.navigate("BecomeOrg" as never);
|
||||
},
|
||||
style: "default",
|
||||
},
|
||||
{
|
||||
text: "Close",
|
||||
onPress: () => {
|
||||
setalartVisible(false);
|
||||
},
|
||||
style: "cancel",
|
||||
},
|
||||
],
|
||||
alertType: 'error',
|
||||
onClose: () => setAlartAction(null),
|
||||
});
|
||||
break;
|
||||
|
||||
case 'PENDING':
|
||||
setalartVisible(true);
|
||||
setAlartAction({
|
||||
visible: true,
|
||||
title: "Organizer Application Pending",
|
||||
message: "Your application to become an organizer is pending approval. You cannot create groups until it's approved.",
|
||||
buttons: [
|
||||
{
|
||||
text: "Close",
|
||||
onPress: () => {
|
||||
setalartVisible(false);
|
||||
},
|
||||
style: "cancel",
|
||||
},
|
||||
],
|
||||
alertType: 'info',
|
||||
onClose: () => setAlartAction(null),
|
||||
});
|
||||
break;
|
||||
case 'APPROVED':
|
||||
navigation.navigate("GroupCreation" as never);
|
||||
break;
|
||||
default:
|
||||
Alert.alert("Unknown action", item.title);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -133,7 +189,7 @@ const Home: React.FC = () => {
|
||||
</View>
|
||||
<TouchableOpacity onPress={() => navigation.navigate("Notification" as never)}>
|
||||
{/* <Image source={getProfileImageUri()} style={styles.profileImage} /> */}
|
||||
<Text style={{position: 'absolute', right: -6, top: -4, backgroundColor: colors.danger, color: colors.white, borderRadius: 8, width: 16, height: 16, textAlign: 'center', fontSize: 10, fontWeight: 'bold', lineHeight: 16, zIndex: 1}}>{unreadCount > 0 ? unreadCount : ''}</Text>
|
||||
<Text style={{ position: 'absolute', right: -6, top: -4, backgroundColor: colors.danger, color: colors.white, borderRadius: 8, width: 16, height: 16, textAlign: 'center', fontSize: 10, fontWeight: 'bold', lineHeight: 16, zIndex: 1 }}>{unreadCount > 0 ? unreadCount : ''}</Text>
|
||||
<Ionicons name="notifications-outline" size={30} color={colors.textDark} />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
@@ -149,6 +205,13 @@ const Home: React.FC = () => {
|
||||
numColumns={2}
|
||||
contentContainerStyle={{ paddingHorizontal: 8 }}
|
||||
/>
|
||||
{/* <CustomAlert
|
||||
visible={alartVisible}
|
||||
title={alartAction?.title as string}
|
||||
buttons={alartAction?.buttons}
|
||||
message={alartAction?.message as string}
|
||||
alertType={'error'}
|
||||
/> */}
|
||||
</AppView>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -74,6 +74,7 @@ const ManagementScreen: FC = () => {
|
||||
apiCall(GET_JOINED_GROUP_URL, "GET") as Promise<ApiResponse<JoinedGroup[]>>,
|
||||
apiCall(USER_REQUEST, "GET") as Promise<ApiResponse<UserJoinRequest[]>>,
|
||||
]);
|
||||
console.log("GET_JOINED_GROUP_URL",joinedGroupsRes)
|
||||
setJoinedGroups(joinedGroupsRes.data || []);
|
||||
setUserRequest(userRequestRes.data || []);
|
||||
}
|
||||
|
||||
@@ -361,15 +361,18 @@ const Profile = () => {
|
||||
|
||||
|
||||
console.log("user image :", user?.filePath);
|
||||
const getProfileImage = () => {
|
||||
if (user?.imageBlob) {
|
||||
return `data:image/jpeg;base64,${user?.imageBlob}`;
|
||||
}
|
||||
if (user?.filePath) {
|
||||
return user?.filePath;
|
||||
}
|
||||
return "https://randomuser?.me/api/portraits/men/1.jpg";
|
||||
};
|
||||
const getProfileImage = () => {
|
||||
return require('../../assets/images/placeholder.png');
|
||||
if (user?.imageBlob) {
|
||||
return { uri: `data:image/jpeg;base64,${user.imageBlob}` };
|
||||
}
|
||||
if (user?.filePath) {
|
||||
return { uri: user.filePath };
|
||||
}
|
||||
// Return a require for local asset if nothing is available
|
||||
return require('../../assets/images/placeholder.png');
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -381,6 +384,7 @@ const Profile = () => {
|
||||
<View style={styles.header}>
|
||||
<Text style={styles.headerTitle}>User Profile</Text>
|
||||
<TouchableOpacity onPress={() => confirmLogout(navigation)} style={styles.refreshButton}>
|
||||
<Text style={{ color: colors.black, marginRight: 8, fontSize: 16 }}>Logout</Text>
|
||||
<Ionicons name="log-out-outline" size={24} color={colors.black} />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
@@ -435,9 +439,10 @@ const Profile = () => {
|
||||
<View style={styles.profileImageSection}>
|
||||
<View style={styles.avatarContainer}>
|
||||
<Image
|
||||
source={{ uri: getProfileImage() }}
|
||||
source={getProfileImage()}
|
||||
style={styles.avatar}
|
||||
onError={() => console.log("Error loading image")}
|
||||
resizeMode='contain'
|
||||
/>
|
||||
<TouchableOpacity style={styles.cameraIcon} onPress={pickImage}>
|
||||
<Ionicons name="camera" size={18} color="#000" />
|
||||
@@ -465,9 +470,7 @@ const Profile = () => {
|
||||
<Text style={{ color: "#64748b", marginBottom: 16 }}>Become Organizer</Text>
|
||||
</View>
|
||||
<View>
|
||||
<TouchableOpacity onPress={() => navigation.navigate('Transaction')}>
|
||||
<Text>View Transaction</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<CustomButton
|
||||
title="Edit Profile"
|
||||
onPress={() => setEditing(true)}
|
||||
@@ -702,10 +705,11 @@ const styles = StyleSheet.create({
|
||||
borderBottomRightRadius: 20,
|
||||
},
|
||||
headerTitle: {
|
||||
fontSize: 22, fontWeight: "600", color: colors.black
|
||||
fontSize: 22, fontWeight: "600", color: colors.black
|
||||
},
|
||||
refreshButton: {
|
||||
padding: 4,
|
||||
flexDirection: "row",
|
||||
},
|
||||
|
||||
|
||||
@@ -733,7 +737,7 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
avatar: {
|
||||
width: 120,
|
||||
height: 120,
|
||||
height: 130,
|
||||
borderRadius: 60,
|
||||
borderWidth: 4,
|
||||
borderColor: "#e2e8f0",
|
||||
|
||||
Reference in New Issue
Block a user