58 lines
2.5 KiB
TypeScript
58 lines
2.5 KiB
TypeScript
import React from 'react';
|
||
import { View } from 'react-native';
|
||
import dayjs from 'dayjs';
|
||
import { MyText, MyTouchableOpacity, BottomDialog, LoadingDialog, tw } from 'common-ui';
|
||
import { useRegionSwitchContext } from '../src/hooks/useRegionSwitch';
|
||
|
||
const RegionSwitchDialogs: React.FC = () => {
|
||
const { isSwitching, switchMessage, results, clearResults } = useRegionSwitchContext();
|
||
|
||
return (
|
||
<>
|
||
<LoadingDialog open={isSwitching} message={switchMessage} />
|
||
<BottomDialog open={results != null} onClose={clearResults}>
|
||
<View style={tw`p-6`}>
|
||
<MyText style={tw`text-lg font-extrabold text-gray-900`}>
|
||
{results?.error ? 'Region switch failed' : `Cart updated for ${results?.regionName ?? ''}`}
|
||
</MyText>
|
||
{results?.error ? (
|
||
<MyText style={tw`text-gray-500 mt-2`}>{results.error}</MyText>
|
||
) : (
|
||
<View style={tw`mt-3`}>
|
||
{results?.lines.length === 0 && (
|
||
<MyText style={tw`text-gray-500`}>Your cart is empty in this region.</MyText>
|
||
)}
|
||
{(results?.lines ?? []).map((line, index) => (
|
||
<View key={`${line.cartType}-${line.skuId}-${index}`} style={tw`py-2 border-b border-gray-100`}>
|
||
<MyText style={tw`text-gray-900 font-bold`} numberOfLines={1}>
|
||
{line.name} × {line.quantity}
|
||
</MyText>
|
||
{line.outcome === 'kept' && (
|
||
<MyText style={tw`text-gray-500 text-sm`}>No change</MyText>
|
||
)}
|
||
{line.outcome === 'moved' && (
|
||
<MyText style={tw`text-gray-500 text-sm`}>
|
||
Slot moved: {line.oldSlotTime ? dayjs(line.oldSlotTime).format('ddd h:mm A') : 'previous slot'} → {line.newSlotTime ? dayjs(line.newSlotTime).format('ddd h:mm A') : ''}
|
||
</MyText>
|
||
)}
|
||
{line.outcome === 'removed' && (
|
||
<MyText style={tw`text-red-500 text-sm`}>Removed{line.reason ? ` — ${line.reason}` : ''}</MyText>
|
||
)}
|
||
</View>
|
||
))}
|
||
</View>
|
||
)}
|
||
<MyTouchableOpacity
|
||
testID="region-switch-dialog-close"
|
||
style={tw`mt-5 bg-brand500 rounded-xl py-3`}
|
||
onPress={clearResults}
|
||
>
|
||
<MyText style={tw`text-white text-center font-bold`}>Done</MyText>
|
||
</MyTouchableOpacity>
|
||
</View>
|
||
</BottomDialog>
|
||
</>
|
||
);
|
||
};
|
||
|
||
export default RegionSwitchDialogs;
|