Improve the production frontend
This commit is contained in:
@@ -13,8 +13,7 @@ import {
|
||||
DeliveryStatus,
|
||||
QualityRating,
|
||||
DeliveryRating,
|
||||
InvoiceStatus,
|
||||
type EnumOption
|
||||
InvoiceStatus
|
||||
} from '../api/types/suppliers';
|
||||
|
||||
import {
|
||||
@@ -31,6 +30,13 @@ import {
|
||||
SalesChannel
|
||||
} from '../api/types/orders';
|
||||
|
||||
import {
|
||||
ProductionStatusEnum,
|
||||
ProductionPriorityEnum,
|
||||
ProductionBatchStatus,
|
||||
QualityCheckStatus
|
||||
} from '../api/types/production';
|
||||
|
||||
/**
|
||||
* Generic function to convert enum to select options with i18n translations
|
||||
*/
|
||||
@@ -44,7 +50,7 @@ export function enumToSelectOptions<T extends Record<string, string | number>>(
|
||||
sortAlphabetically?: boolean;
|
||||
}
|
||||
): SelectOption[] {
|
||||
const selectOptions = Object.entries(enumObject).map(([key, value]) => ({
|
||||
const selectOptions = Object.entries(enumObject).map(([_, value]) => ({
|
||||
value,
|
||||
label: t(`${translationKey}.${value}`),
|
||||
...(options?.includeDescription && options?.descriptionKey && {
|
||||
@@ -298,6 +304,107 @@ export function useOrderEnums() {
|
||||
return t(`sales_channels.${channel}`);
|
||||
},
|
||||
|
||||
// Field Labels
|
||||
getFieldLabel: (field: string): string =>
|
||||
t(`labels.${field}`),
|
||||
|
||||
getFieldDescription: (field: string): string =>
|
||||
t(`descriptions.${field}`)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for production enum utilities
|
||||
*/
|
||||
export function useProductionEnums() {
|
||||
const { t } = useTranslation('production');
|
||||
|
||||
return {
|
||||
// Production Status
|
||||
getProductionStatusOptions: (): SelectOption[] =>
|
||||
enumToSelectOptions(ProductionStatusEnum, 'production_status', t),
|
||||
|
||||
getProductionStatusLabel: (status: ProductionStatusEnum): string => {
|
||||
if (!status) return 'Estado no definido';
|
||||
const translated = t(`production_status.${status}`);
|
||||
// If translation failed, return a fallback
|
||||
if (translated === `production_status.${status}`) {
|
||||
const fallbacks = {
|
||||
[ProductionStatusEnum.PENDING]: 'Pendiente',
|
||||
[ProductionStatusEnum.IN_PROGRESS]: 'En Proceso',
|
||||
[ProductionStatusEnum.COMPLETED]: 'Completado',
|
||||
[ProductionStatusEnum.CANCELLED]: 'Cancelado',
|
||||
[ProductionStatusEnum.ON_HOLD]: 'En Pausa',
|
||||
[ProductionStatusEnum.QUALITY_CHECK]: 'Control Calidad',
|
||||
[ProductionStatusEnum.FAILED]: 'Fallido'
|
||||
};
|
||||
return fallbacks[status] || status;
|
||||
}
|
||||
return translated;
|
||||
},
|
||||
|
||||
// Production Priority
|
||||
getProductionPriorityOptions: (): SelectOption[] =>
|
||||
enumToSelectOptions(ProductionPriorityEnum, 'production_priority', t),
|
||||
|
||||
getProductionPriorityLabel: (priority: ProductionPriorityEnum): string => {
|
||||
if (!priority) return 'Prioridad no definida';
|
||||
const translated = t(`production_priority.${priority}`);
|
||||
// If translation failed, return a fallback
|
||||
if (translated === `production_priority.${priority}`) {
|
||||
const fallbacks = {
|
||||
[ProductionPriorityEnum.LOW]: 'Baja',
|
||||
[ProductionPriorityEnum.MEDIUM]: 'Media',
|
||||
[ProductionPriorityEnum.HIGH]: 'Alta',
|
||||
[ProductionPriorityEnum.URGENT]: 'Urgente'
|
||||
};
|
||||
return fallbacks[priority] || priority;
|
||||
}
|
||||
return translated;
|
||||
},
|
||||
|
||||
// Production Batch Status
|
||||
getProductionBatchStatusOptions: (): SelectOption[] =>
|
||||
enumToSelectOptions(ProductionBatchStatus, 'batch_status', t),
|
||||
|
||||
getProductionBatchStatusLabel: (status: ProductionBatchStatus): string => {
|
||||
if (!status) return 'Estado no definido';
|
||||
const translated = t(`batch_status.${status}`);
|
||||
// If translation failed, return a fallback
|
||||
if (translated === `batch_status.${status}`) {
|
||||
const fallbacks = {
|
||||
[ProductionBatchStatus.PLANNED]: 'Planificado',
|
||||
[ProductionBatchStatus.IN_PROGRESS]: 'En Proceso',
|
||||
[ProductionBatchStatus.COMPLETED]: 'Completado',
|
||||
[ProductionBatchStatus.CANCELLED]: 'Cancelado',
|
||||
[ProductionBatchStatus.ON_HOLD]: 'En Pausa'
|
||||
};
|
||||
return fallbacks[status] || status;
|
||||
}
|
||||
return translated;
|
||||
},
|
||||
|
||||
// Quality Check Status
|
||||
getQualityCheckStatusOptions: (): SelectOption[] =>
|
||||
enumToSelectOptions(QualityCheckStatus, 'quality_check_status', t),
|
||||
|
||||
getQualityCheckStatusLabel: (status: QualityCheckStatus): string => {
|
||||
if (!status) return 'Estado no definido';
|
||||
const translated = t(`quality_check_status.${status}`);
|
||||
// If translation failed, return a fallback
|
||||
if (translated === `quality_check_status.${status}`) {
|
||||
const fallbacks = {
|
||||
[QualityCheckStatus.PENDING]: 'Pendiente',
|
||||
[QualityCheckStatus.IN_PROGRESS]: 'En Proceso',
|
||||
[QualityCheckStatus.PASSED]: 'Aprobado',
|
||||
[QualityCheckStatus.FAILED]: 'Reprobado',
|
||||
[QualityCheckStatus.REQUIRES_ATTENTION]: 'Requiere Atención'
|
||||
};
|
||||
return fallbacks[status] || status;
|
||||
}
|
||||
return translated;
|
||||
},
|
||||
|
||||
// Field Labels
|
||||
getFieldLabel: (field: string): string =>
|
||||
t(`labels.${field}`),
|
||||
|
||||
Reference in New Issue
Block a user