import React, { useState } from 'react'; import { View, TouchableOpacity } from 'react-native'; import { MyText, tw, BottomDialog, MyTextInput } from 'common-ui'; import { trpc } from '@/src/trpc-client'; import MaterialIcons from '@expo/vector-icons/MaterialIcons'; import { Alert } from 'react-native'; interface CancelOrderDialogProps { orderId: number; open: boolean; onClose: () => void; onSuccess?: () => void; } export default function CancelOrderDialog({ orderId, open, onClose, onSuccess }: CancelOrderDialogProps) { const [cancelReason, setCancelReason] = useState(''); const cancelOrderMutation = trpc.admin.order.cancelOrder.useMutation(); const handleCancel = () => { if (!cancelReason.trim()) { Alert.alert('Error', 'Please enter a cancellation reason'); return; } Alert.alert( 'Cancel Order', 'Are you sure you want to cancel this order? This action cannot be undone.', [ { text: 'No', style: 'cancel' }, { text: 'Yes, Cancel', style: 'destructive', onPress: () => { cancelOrderMutation.mutate( { orderId, reason: cancelReason }, { onSuccess: () => { onClose(); setCancelReason(''); onSuccess?.(); }, onError: (error: any) => { Alert.alert('Error', error.message || 'Failed to cancel order'); }, } ); }, }, ] ); }; return ( Cancel Order This will cancel the order and mark it as cancelled by admin. A refund record will be created. Keep Order {cancelOrderMutation.isPending ? 'Cancelling...' : 'Cancel Order'} ); }