119 lines
No EOL
4.3 KiB
TypeScript
119 lines
No EOL
4.3 KiB
TypeScript
import React from 'react';
|
|
import { View, ScrollView } from 'react-native';
|
|
import { AppContainer, MyText, tw, MyTouchableOpacity } from 'common-ui';
|
|
import { trpc } from '@/src/trpc-client';
|
|
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
|
|
import dayjs from "dayjs";
|
|
import { useRouter, useLocalSearchParams } from 'expo-router';
|
|
import { LinearGradient } from 'expo-linear-gradient';
|
|
|
|
export default function SlotDetails() {
|
|
const router = useRouter();
|
|
const { slotId } = useLocalSearchParams();
|
|
|
|
const { data: slotData, isLoading, error } = trpc.admin.slots.getSlotById.useQuery({
|
|
id: parseInt(slotId as string),
|
|
});
|
|
|
|
const slot = slotData?.slot;
|
|
const products = slot?.products || [];
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<AppContainer>
|
|
<View style={tw`flex-1 justify-center items-center`}>
|
|
<MyText style={tw`text-gray-600`}>Loading slot details...</MyText>
|
|
</View>
|
|
</AppContainer>
|
|
);
|
|
}
|
|
|
|
if (error || !slot) {
|
|
return (
|
|
<AppContainer>
|
|
<View style={tw`flex-1 justify-center items-center`}>
|
|
<MyText style={tw`text-red-600`}>Error loading slot details</MyText>
|
|
</View>
|
|
</AppContainer>
|
|
);
|
|
}
|
|
|
|
return (
|
|
|
|
<View style={tw`flex-1 bg-white px-4 relative`}>
|
|
<ScrollView
|
|
style={tw`flex-1`}
|
|
contentContainerStyle={tw`pb-32`}
|
|
showsVerticalScrollIndicator={false}
|
|
>
|
|
{/* Header */}
|
|
<View style={tw`mb-6`}>
|
|
<MyText style={tw`text-2xl font-black text-gray-900 mb-2`}>
|
|
Slot #{slot.id}
|
|
</MyText>
|
|
<View style={tw`flex-row items-center justify-between`}>
|
|
<View style={tw`flex-1`}>
|
|
<MyText style={tw`text-sm text-gray-600 mb-1`}>
|
|
Delivery: {dayjs(slot.deliveryTime).format('MMM DD, YYYY hh:mm A')}
|
|
</MyText>
|
|
<MyText style={tw`text-sm text-gray-600`}>
|
|
Freeze: {dayjs(slot.freezeTime).format('MMM DD, YYYY hh:mm A')}
|
|
</MyText>
|
|
</View>
|
|
<View style={tw`px-3 py-1 rounded-full ${slot.isActive ? 'bg-green-100' : 'bg-red-100'}`}>
|
|
<MyText style={tw`text-xs font-bold ${slot.isActive ? 'text-green-700' : 'text-red-700'}`}>
|
|
{slot.isActive ? 'Active' : 'Inactive'}
|
|
</MyText>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
|
|
{/* Products Section */}
|
|
<View style={tw`mb-8`}>
|
|
<View style={tw`flex-row items-center justify-between mb-4`}>
|
|
<MyText style={tw`text-lg font-bold text-gray-900`}>Products</MyText>
|
|
<View style={tw`bg-gray-100 px-2 py-1 rounded-full`}>
|
|
<MyText style={tw`text-xs font-medium text-gray-600`}>{products.length} items</MyText>
|
|
</View>
|
|
</View>
|
|
|
|
{products.length === 0 ? (
|
|
<View style={tw`bg-gray-50 p-6 rounded-lg items-center`}>
|
|
<MaterialIcons name="inventory" size={32} color="#9CA3AF" />
|
|
<MyText style={tw`text-gray-500 text-center mt-2`}>No products in this slot</MyText>
|
|
</View>
|
|
) : (
|
|
<View style={tw`flex-row flex-wrap gap-2 py-2`}>
|
|
{products.map((product) => (
|
|
<View key={product.id} style={tw`bg-blue-50 px-3 py-2 rounded-full border border-blue-200`}>
|
|
<MyText style={tw`text-sm font-medium text-blue-700`} numberOfLines={1}>
|
|
{product.name}
|
|
</MyText>
|
|
</View>
|
|
))}
|
|
</View>
|
|
)}
|
|
</View>
|
|
</ScrollView>
|
|
|
|
{/* FAB for Edit Slot */}
|
|
<MyTouchableOpacity
|
|
testID="edit-slot-fab"
|
|
onPress={() => router.push(`/(drawer)/dashboard/slots/edit/${slot.id}` as any)}
|
|
activeOpacity={0.95}
|
|
style={{ position: 'absolute', bottom: 32, right: 24, zIndex: 100 }}
|
|
>
|
|
<LinearGradient
|
|
colors={['#F83758', '#E91E63']}
|
|
start={{ x: 0, y: 0 }}
|
|
end={{ x: 1, y: 1 }}
|
|
style={tw`w-16 h-16 rounded-[24px] items-center justify-center shadow-lg shadow-pink300`}
|
|
>
|
|
<MaterialIcons name="edit" size={24} color="white" />
|
|
</LinearGradient>
|
|
</MyTouchableOpacity>
|
|
|
|
</View>
|
|
|
|
);
|
|
} |