Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 1x 4x 2x 2x 4x | import React, { useMemo } from 'react';
import {
View,
Text,
StyleSheet,
FlatList,
ActivityIndicator,
TouchableOpacity,
RefreshControl,
} from 'react-native';
import { useInvitationsViewModel } from '@/viewmodels/invitation/useInvitationsViewModel';
import InvitationCard from '@/components/invitation/InvitationCard';
import { MaterialIcons } from '@expo/vector-icons';
import { SafeAreaView } from 'react-native-safe-area-context';
import { router, Href } from 'expo-router';
import { useTheme } from '@/theme';
import type { Theme } from '@/theme';
import { useTranslation } from 'react-i18next';
export default function InvitationsView() {
const vm = useInvitationsViewModel();
const { theme } = useTheme();
const { t } = useTranslation();
const styles = useMemo(() => makeStyles(theme), [theme]);
const renderEmpty = () => (
<View style={styles.emptyContainer}>
<View style={styles.emptyIconContainer}>
<MaterialIcons name="mail-outline" size={48} color={theme.textTertiary} />
</View>
<Text style={styles.emptyTitle}>{t('profile.invitations.empty')}</Text>
<Text style={styles.emptySubtitle}>
{t('profile.invitations.emptySubtitle')}
</Text>
</View>
);
return (
<SafeAreaView style={styles.container} edges={['top']}>
<View style={styles.header}>
<TouchableOpacity
onPress={() => router.back()}
style={styles.backButton}
accessibilityLabel="Go back"
>
<MaterialIcons name="arrow-back" size={24} color={theme.text} />
</TouchableOpacity>
<Text style={styles.headerTitle}>{t('profile.invitations.title')}</Text>
<View style={styles.headerRight} />
</View>
{vm.isLoading && vm.invitations.length === 0 ? (
<View style={styles.centerContainer}>
<ActivityIndicator size="large" color="#6366F1" />
</View>
) : vm.error && vm.invitations.length === 0 ? (
<View style={styles.centerContainer}>
<MaterialIcons name="error-outline" size={48} color={theme.errorText} />
<Text style={styles.errorText}>{vm.error}</Text>
<TouchableOpacity style={styles.retryButton} onPress={vm.fetchInvitations}>
<Text style={styles.retryButtonText}>{t('profile.invitations.retry')}</Text>
</TouchableOpacity>
</View>
) : (
<FlatList
data={vm.invitations}
keyExtractor={(item) => item.invitation_id}
renderItem={({ item }) => (
<InvitationCard
invitation={item}
onAccept={vm.handleAccept}
onDecline={vm.handleDecline}
onPress={(eventId) => router.push(`/event/${eventId}` as Href)}
isActionLoading={vm.isActionLoading === item.invitation_id}
/>
)}
contentContainerStyle={styles.listContent}
ListEmptyComponent={renderEmpty}
refreshControl={
<RefreshControl
refreshing={vm.isLoading}
onRefresh={vm.fetchInvitations}
colors={['#6366F1']}
/>
}
/>
)}
</SafeAreaView>
);
}
function makeStyles(t: Theme) {
return StyleSheet.create({
container: {
flex: 1,
backgroundColor: t.background,
},
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: 16,
paddingVertical: 12,
backgroundColor: t.surface,
borderBottomWidth: 1,
borderBottomColor: t.border,
},
backButton: {
padding: 4,
},
headerTitle: {
fontSize: 18,
fontWeight: '700',
color: t.text,
},
headerRight: {
width: 32,
},
centerContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 32,
},
listContent: {
padding: 16,
flexGrow: 1,
},
emptyContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingTop: 100,
},
emptyIconContainer: {
width: 80,
height: 80,
borderRadius: 40,
backgroundColor: t.surfaceAlt,
alignItems: 'center',
justifyContent: 'center',
marginBottom: 16,
},
emptyTitle: {
fontSize: 18,
fontWeight: '700',
color: t.text,
marginBottom: 8,
},
emptySubtitle: {
fontSize: 14,
color: t.textSecondary,
textAlign: 'center',
lineHeight: 20,
paddingHorizontal: 32,
},
errorText: {
fontSize: 16,
color: t.textSecondary,
textAlign: 'center',
marginTop: 16,
marginBottom: 24,
},
retryButton: {
backgroundColor: '#6366F1',
paddingHorizontal: 24,
paddingVertical: 12,
borderRadius: 12,
},
retryButtonText: {
color: '#FFFFFF',
fontWeight: '600',
fontSize: 16,
},
});
}
|