Refactor components and modals
This commit is contained in:
@@ -7,8 +7,8 @@ import {
|
||||
Card,
|
||||
Badge
|
||||
} from '../../ui';
|
||||
import { StatusModal } from '../../ui/StatusModal';
|
||||
import type { StatusModalSection } from '../../ui/StatusModal';
|
||||
import { EditViewModal } from '../../ui/EditViewModal';
|
||||
import type { StatusModalSection } from '../../ui/EditViewModal';
|
||||
import {
|
||||
OrderCreate,
|
||||
OrderItemCreate,
|
||||
@@ -29,7 +29,7 @@ import { useIngredients } from '../../../api/hooks/inventory';
|
||||
import { ProductType, ProductCategory } from '../../../api/types/inventory';
|
||||
import { useCurrentTenant } from '../../../stores/tenant.store';
|
||||
import { useAuthUser } from '../../../stores/auth.store';
|
||||
import { useOrderEnums } from '../../../utils/enumHelpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
interface OrderFormModalProps {
|
||||
isOpen: boolean;
|
||||
@@ -46,7 +46,28 @@ export const OrderFormModal: React.FC<OrderFormModalProps> = ({
|
||||
const currentTenant = useCurrentTenant();
|
||||
const user = useAuthUser();
|
||||
const tenantId = currentTenant?.id || user?.tenant_id || '';
|
||||
const orderEnums = useOrderEnums();
|
||||
const { t } = useTranslation(['orders', 'common']);
|
||||
|
||||
// Create enum options using direct i18n
|
||||
const orderTypeOptions = Object.values(OrderType).map(value => ({
|
||||
value,
|
||||
label: t(`orders:order_types.${value}`)
|
||||
}));
|
||||
|
||||
const priorityLevelOptions = Object.values(PriorityLevel).map(value => ({
|
||||
value,
|
||||
label: t(`orders:priority_levels.${value}`)
|
||||
}));
|
||||
|
||||
const deliveryMethodOptions = Object.values(DeliveryMethod).map(value => ({
|
||||
value,
|
||||
label: t(`orders:delivery_methods.${value}`)
|
||||
}));
|
||||
|
||||
const customerTypeOptions = Object.values(CustomerType).map(value => ({
|
||||
value,
|
||||
label: t(`orders:customer_types.${value}`)
|
||||
}));
|
||||
|
||||
// Form state
|
||||
const [selectedCustomer, setSelectedCustomer] = useState<CustomerResponse | null>(null);
|
||||
@@ -265,21 +286,21 @@ export const OrderFormModal: React.FC<OrderFormModalProps> = ({
|
||||
value: orderData.order_type || OrderType.STANDARD,
|
||||
type: 'select',
|
||||
editable: true,
|
||||
options: orderEnums.getOrderTypeOptions()
|
||||
options: orderTypeOptions
|
||||
},
|
||||
{
|
||||
label: 'Prioridad',
|
||||
value: orderData.priority || PriorityLevel.NORMAL,
|
||||
type: 'select',
|
||||
editable: true,
|
||||
options: orderEnums.getPriorityLevelOptions()
|
||||
options: priorityLevelOptions
|
||||
},
|
||||
{
|
||||
label: 'Método de Entrega',
|
||||
value: orderData.delivery_method || DeliveryMethod.PICKUP,
|
||||
type: 'select',
|
||||
editable: true,
|
||||
options: orderEnums.getDeliveryMethodOptions()
|
||||
options: deliveryMethodOptions
|
||||
},
|
||||
{
|
||||
label: 'Fecha de Entrega',
|
||||
@@ -442,7 +463,7 @@ export const OrderFormModal: React.FC<OrderFormModalProps> = ({
|
||||
|
||||
return (
|
||||
<>
|
||||
<StatusModal
|
||||
<EditViewModal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
mode="edit"
|
||||
@@ -474,7 +495,7 @@ export const OrderFormModal: React.FC<OrderFormModalProps> = ({
|
||||
|
||||
|
||||
{/* New Customer Modal - Using StatusModal for consistency */}
|
||||
<StatusModal
|
||||
<EditViewModal
|
||||
isOpen={showCustomerForm}
|
||||
onClose={() => setShowCustomerForm(false)}
|
||||
mode="edit"
|
||||
@@ -515,14 +536,14 @@ export const OrderFormModal: React.FC<OrderFormModalProps> = ({
|
||||
value: newCustomerData.customer_type || CustomerType.INDIVIDUAL,
|
||||
type: 'select',
|
||||
editable: true,
|
||||
options: orderEnums.getCustomerTypeOptions()
|
||||
options: customerTypeOptions
|
||||
},
|
||||
{
|
||||
label: 'Método de Entrega Preferido',
|
||||
value: newCustomerData.preferred_delivery_method || DeliveryMethod.PICKUP,
|
||||
type: 'select',
|
||||
editable: true,
|
||||
options: orderEnums.getDeliveryMethodOptions()
|
||||
options: deliveryMethodOptions
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -574,7 +595,7 @@ export const OrderFormModal: React.FC<OrderFormModalProps> = ({
|
||||
/>
|
||||
|
||||
{/* Customer Selector Modal */}
|
||||
<StatusModal
|
||||
<EditViewModal
|
||||
isOpen={showCustomerSelector}
|
||||
onClose={() => setShowCustomerSelector(false)}
|
||||
mode="view"
|
||||
|
||||
Reference in New Issue
Block a user