freshyo/apps/user-ui/components/CheckoutAddressDisplay.tsx
2026-11-08 13:49:17 +05:30

54 lines
2.3 KiB
TypeScript

import React from 'react'
import { View } from 'react-native'
import MaterialIcons from '@expo/vector-icons/MaterialIcons'
import { tw, MyText } from 'common-ui'
import { useRegionNeo } from '@/src/hooks/useRegionNeo'
import { addressIconName } from '@/src/lib/neo-address'
/**
* Read-only delivery address card for the checkout page. The address is chosen
* on the cart page (CheckoutAddressSelector); checkout only shows it.
*/
const CheckoutAddressDisplay: React.FC = () => {
// The hook guarantees the selection belongs to the current region, so this
// is the one address the order will use.
const address = useRegionNeo().selectedAddress
return (
<View testID="checkout-address" style={tw`bg-white p-5 rounded-2xl shadow-sm mb-4 border border-gray-100`}>
<View style={tw`flex-row items-center mb-3`}>
<View style={tw`w-8 h-8 bg-blue-50 rounded-full items-center justify-center mr-3`}>
<MaterialIcons name="location-on" size={18} color="#3B82F6" />
</View>
<MyText style={tw`text-base font-bold text-gray-900`}>Delivery Address</MyText>
</View>
{address ? (
<View style={tw`bg-gray-50 p-4 rounded-xl border border-gray-200`}>
<View style={tw`flex-row items-center mb-2`}>
<MaterialIcons name={addressIconName(address.name)} size={20} color="#6B7280" />
<MyText testID="checkout-address-name" style={tw`font-bold ml-2 text-gray-900`}>{address.name}</MyText>
</View>
<MyText style={tw`text-gray-600 text-sm leading-5 mb-1`} numberOfLines={2}>
{address.addressLine1}
{address.addressLine2 ? `, ${address.addressLine2}` : ''}
</MyText>
<MyText style={tw`text-gray-600 text-sm mb-1`}>
{address.city}, {address.state}
</MyText>
<MyText style={tw`text-gray-500 text-xs mt-2`}>Phone: {address.phone}</MyText>
</View>
) : (
<View
testID="checkout-address-empty"
style={tw`bg-gray-50 p-6 rounded-xl border border-gray-200 border-dashed items-center justify-center`}
>
<MaterialIcons name="location-off" size={32} color="#9CA3AF" />
<MyText style={tw`text-gray-500 mt-2`}>No address selected</MyText>
</View>
)}
</View>
)
}
export default CheckoutAddressDisplay