home changes

This commit is contained in:
Abin Toppo
2025-10-16 15:33:23 +05:30
parent fb29805edc
commit 7e1c90de69
13 changed files with 380 additions and 110 deletions
+70 -7
View File
@@ -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>
);
};