Skip to content

Commit

Permalink
admin panel v1
Browse files Browse the repository at this point in the history
  • Loading branch information
cangndz75 committed Dec 9, 2024
1 parent 22632ca commit 2052154
Show file tree
Hide file tree
Showing 13 changed files with 741 additions and 491 deletions.
7 changes: 5 additions & 2 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import AntDesign from 'react-native-vector-icons/AntDesign';
import StackNavigator from './navigation/StackNavigator';
import {AuthProvider} from './AuthContext';
import {ModalPortal} from 'react-native-modals';
import { EventProvider } from './EventContext';

function Section({children, title}) {
const isDarkMode = useColorScheme() === 'dark';
Expand Down Expand Up @@ -63,8 +64,10 @@ function App() {

return (
<AuthProvider>
<StackNavigator />
<ModalPortal />
<EventProvider>
<StackNavigator />
<ModalPortal />
</EventProvider>
</AuthProvider>
);
}
Expand Down
7 changes: 1 addition & 6 deletions AuthContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ const AuthProvider = ({children}) => {

const saveUserData = async (userId, role, user) => {
try {
if (!userId || !role) {
throw new Error('User ID or Role is undefined. Cannot save.');
}

const safeUser = user ? JSON.stringify(user) : JSON.stringify({});
await AsyncStorage.multiSet([
['userId', String(userId)],
['role', String(role)],
['user', safeUser],
]);

setUserId(userId);
setRole(role);
setUser(user || {});
Expand Down Expand Up @@ -50,10 +45,10 @@ const AuthProvider = ({children}) => {

const clearUserData = async () => {
try {
await AsyncStorage.multiRemove(['userId', 'role', 'user']);
setUserId(null);
setRole('user');
setUser(null);
await AsyncStorage.multiRemove(['userId', 'role', 'user']);
} catch (error) {
console.error('Error clearing user data:', error);
}
Expand Down
203 changes: 132 additions & 71 deletions components/UpComingEvent.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import React, {useContext, useState, useCallback} from 'react';
import {
Image,
Pressable,
Text,
View,
Text,
Image,
ActivityIndicator,
FlatList,
RefreshControl,
Alert,
StyleSheet,
TouchableOpacity,
} from 'react-native';
import {useNavigation, useFocusEffect} from '@react-navigation/native';
import axios from 'axios';
import {AuthContext} from '../AuthContext';
import Ionicons from 'react-native-vector-icons/Ionicons';

const UpComingEvent = ({item}) => {
const navigation = useNavigation();
const {userId} = useContext(AuthContext);
const [isBooked, setIsBooked] = useState(false);
const {userId, role} = useContext(AuthContext);
const [eventData, setEventData] = useState(null);
const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
Expand All @@ -33,15 +32,10 @@ const UpComingEvent = ({item}) => {
try {
const response = await axios.get(
`https://biletixai.onrender.com/events/${item?._id}`,
{
params: { userId }, // userId'yi parametre olarak gönder
}
);
setEventData(response.data);
setIsBooked(response.data?.attendees?.some(att => att._id === userId));
} catch (error) {
console.error('Error fetching event data:', error.response?.data || error.message);
Alert.alert('Server Error', 'Unable to fetch event data. Please try again later.');
Alert.alert('Error', 'Unable to fetch event data.');
} finally {
setLoading(false);
}
Expand All @@ -53,90 +47,157 @@ const UpComingEvent = ({item}) => {
setRefreshing(false);
};

const handleNavigation = () => {
const targetScreen = 'EventSetUp';
navigation.navigate(targetScreen, {
item: eventData,
const handleEdit = () => {
navigation.navigate('AdminEventSetUp', {item: eventData});
};

const handleManage = () => {
navigation.navigate('ManageRequest', {
eventId: eventData?._id,
userId,
});
};

if (loading) {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<View style={styles.centered}>
<ActivityIndicator size="large" color="#07bc0c" />
</View>
);
}

if (!eventData) {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Ionicons name="calendar-outline" size={48} color="#888" />
<Text style={{fontSize: 18, color: '#888', marginTop: 8}}>
No Events
</Text>
<View style={styles.centered}>
<Text style={styles.noEventText}>No Events</Text>
</View>
);
}

const renderEventItem = () => (
<Pressable
onPress={handleNavigation}
style={{
backgroundColor: '#fff',
padding: 16,
borderRadius: 16,
marginBottom: 20,
marginHorizontal: 10,
shadowColor: '#000',
shadowOffset: {width: 0, height: 4},
shadowOpacity: 0.15,
shadowRadius: 6,
elevation: 8,
}}>
<Text
style={{
fontSize: 14,
fontWeight: '700',
color: '#FF6347',
marginBottom: 8,
}}>
{new Date(eventData?.date).toDateString()}
</Text>

<View style={{flexDirection: 'row', alignItems: 'center'}}>
<Image
style={{width: 80, height: 80, borderRadius: 12, marginRight: 12}}
source={{
uri: eventData?.images?.[0] || 'https://via.placeholder.com/100',
}}
/>

<View style={{flex: 1}}>
<Text style={{fontSize: 18, fontWeight: 'bold', color: '#333'}}>
{eventData?.title}
</Text>
<Text style={{fontSize: 14, color: '#777', marginVertical: 4}}>
{eventData?.location}
</Text>
<Text style={{fontSize: 14, color: '#999'}}>
Hosted by {eventData?.organizerName}
</Text>
</View>
</View>
</Pressable>
);

return (
<FlatList
data={[eventData]}
renderItem={renderEventItem}
keyExtractor={item => item._id}
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
}
renderItem={({item}) => (
<View style={styles.eventCard}>
<Text style={styles.dateText}>
{new Date(item.date).toDateString()}
</Text>
<View style={styles.row}>
<Image
style={styles.eventImage}
source={{
uri: item.images?.[0] || 'https://via.placeholder.com/100',
}}
/>
<View style={styles.eventDetails}>
<Text style={styles.eventTitle}>{item.title}</Text>
<Text style={styles.eventLocation}>{item.location}</Text>
<Text style={styles.hostedBy}>
Hosted by {item.organizerName}
</Text>
</View>
</View>
{role === 'organizer' && (
<View style={styles.actionButtons}>
<TouchableOpacity style={styles.editButton} onPress={handleEdit}>
<Text style={styles.buttonText}>Edit</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.manageButton}
onPress={handleManage}>
<Text style={styles.buttonText}>Manage</Text>
</TouchableOpacity>
</View>
)}
</View>
)}
/>
);
};

export default UpComingEvent;

const styles = StyleSheet.create({
centered: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
noEventText: {
fontSize: 18,
color: '#888',
marginTop: 8,
},
eventCard: {
backgroundColor: '#fff',
borderRadius: 10,
padding: 16,
marginVertical: 10,
marginHorizontal: 15,
shadowColor: '#000',
shadowOffset: {width: 0, height: 2},
shadowOpacity: 0.1,
shadowRadius: 4,
elevation: 4,
},
dateText: {
fontSize: 14,
fontWeight: 'bold',
color: '#FF6347',
marginBottom: 10,
},
row: {
flexDirection: 'row',
alignItems: 'center',
},
eventImage: {
width: 80,
height: 80,
borderRadius: 10,
marginRight: 12,
},
eventDetails: {
flex: 1,
},
eventTitle: {
fontSize: 18,
fontWeight: 'bold',
color: '#333',
},
eventLocation: {
fontSize: 14,
color: '#777',
marginVertical: 4,
},
hostedBy: {
fontSize: 14,
color: '#999',
},
actionButtons: {
flexDirection: 'row',
justifyContent: 'space-between',
marginTop: 16,
},
editButton: {
backgroundColor: '#5c6bc0',
paddingVertical: 8,
paddingHorizontal: 20,
borderRadius: 8,
},
manageButton: {
backgroundColor: '#ff6b6b',
paddingVertical: 8,
paddingHorizontal: 20,
borderRadius: 8,
},
buttonText: {
color: '#fff',
fontSize: 16,
fontWeight: 'bold',
textAlign: 'center',
},
});
Loading

0 comments on commit 2052154

Please sign in to comment.