Improve the frontend 3
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import { showToast } from '../../utils/toast';
|
||||
import { equipmentService } from '../services/equipment';
|
||||
import type { Equipment, EquipmentDeletionSummary } from '../types/equipment';
|
||||
|
||||
@@ -74,11 +74,11 @@ export function useCreateEquipment(tenantId: string) {
|
||||
newEquipment
|
||||
);
|
||||
|
||||
toast.success('Equipment created successfully');
|
||||
showToast.success('Equipment created successfully');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Error creating equipment:', error);
|
||||
toast.error(error.response?.data?.detail || 'Error creating equipment');
|
||||
showToast.error(error.response?.data?.detail || 'Error creating equipment');
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -104,11 +104,11 @@ export function useUpdateEquipment(tenantId: string) {
|
||||
// Invalidate lists to refresh
|
||||
queryClient.invalidateQueries({ queryKey: equipmentKeys.lists() });
|
||||
|
||||
toast.success('Equipment updated successfully');
|
||||
showToast.success('Equipment updated successfully');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Error updating equipment:', error);
|
||||
toast.error(error.response?.data?.detail || 'Error updating equipment');
|
||||
showToast.error(error.response?.data?.detail || 'Error updating equipment');
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -131,11 +131,11 @@ export function useDeleteEquipment(tenantId: string) {
|
||||
// Invalidate lists to refresh
|
||||
queryClient.invalidateQueries({ queryKey: equipmentKeys.lists() });
|
||||
|
||||
toast.success('Equipment deleted successfully');
|
||||
showToast.success('Equipment deleted successfully');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Error deleting equipment:', error);
|
||||
toast.error(error.response?.data?.detail || 'Error deleting equipment');
|
||||
showToast.error(error.response?.data?.detail || 'Error deleting equipment');
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -158,11 +158,11 @@ export function useHardDeleteEquipment(tenantId: string) {
|
||||
// Invalidate lists to refresh
|
||||
queryClient.invalidateQueries({ queryKey: equipmentKeys.lists() });
|
||||
|
||||
toast.success('Equipment permanently deleted');
|
||||
showToast.success('Equipment permanently deleted');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Error hard deleting equipment:', error);
|
||||
toast.error(error.response?.data?.detail || 'Error permanently deleting equipment');
|
||||
showToast.error(error.response?.data?.detail || 'Error permanently deleting equipment');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
28
frontend/src/api/hooks/orchestrator.ts
Normal file
28
frontend/src/api/hooks/orchestrator.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Orchestrator React Query hooks
|
||||
*/
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import * as orchestratorService from '../services/orchestrator';
|
||||
import { ApiError } from '../client';
|
||||
|
||||
// Mutations
|
||||
export const useRunDailyWorkflow = (
|
||||
options?: Parameters<typeof useMutation>[0]
|
||||
) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (tenantId: string) =>
|
||||
orchestratorService.runDailyWorkflow(tenantId),
|
||||
onSuccess: (_, tenantId) => {
|
||||
// Invalidate queries to refresh dashboard data after workflow execution
|
||||
queryClient.invalidateQueries({ queryKey: ['procurement', 'plans'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['production', 'batches'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['forecasts'] });
|
||||
// Also invalidate dashboard queries to refresh stats
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard', 'stats'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard'] });
|
||||
},
|
||||
...options,
|
||||
});
|
||||
};
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import { showToast } from '../../utils/toast';
|
||||
import { qualityTemplateService } from '../services/qualityTemplates';
|
||||
import type {
|
||||
QualityCheckTemplate,
|
||||
@@ -114,11 +114,11 @@ export function useCreateQualityTemplate(tenantId: string) {
|
||||
newTemplate
|
||||
);
|
||||
|
||||
toast.success('Plantilla de calidad creada exitosamente');
|
||||
showToast.success('Plantilla de calidad creada exitosamente');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Error creating quality template:', error);
|
||||
toast.error(error.response?.data?.detail || 'Error al crear la plantilla de calidad');
|
||||
showToast.error(error.response?.data?.detail || 'Error al crear la plantilla de calidad');
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -144,11 +144,11 @@ export function useUpdateQualityTemplate(tenantId: string) {
|
||||
// Invalidate lists to refresh
|
||||
queryClient.invalidateQueries({ queryKey: qualityTemplateKeys.lists() });
|
||||
|
||||
toast.success('Plantilla de calidad actualizada exitosamente');
|
||||
showToast.success('Plantilla de calidad actualizada exitosamente');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Error updating quality template:', error);
|
||||
toast.error(error.response?.data?.detail || 'Error al actualizar la plantilla de calidad');
|
||||
showToast.error(error.response?.data?.detail || 'Error al actualizar la plantilla de calidad');
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -171,11 +171,11 @@ export function useDeleteQualityTemplate(tenantId: string) {
|
||||
// Invalidate lists to refresh
|
||||
queryClient.invalidateQueries({ queryKey: qualityTemplateKeys.lists() });
|
||||
|
||||
toast.success('Plantilla de calidad eliminada exitosamente');
|
||||
showToast.success('Plantilla de calidad eliminada exitosamente');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Error deleting quality template:', error);
|
||||
toast.error(error.response?.data?.detail || 'Error al eliminar la plantilla de calidad');
|
||||
showToast.error(error.response?.data?.detail || 'Error al eliminar la plantilla de calidad');
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -199,11 +199,11 @@ export function useDuplicateQualityTemplate(tenantId: string) {
|
||||
// Invalidate lists to refresh
|
||||
queryClient.invalidateQueries({ queryKey: qualityTemplateKeys.lists() });
|
||||
|
||||
toast.success('Plantilla de calidad duplicada exitosamente');
|
||||
showToast.success('Plantilla de calidad duplicada exitosamente');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Error duplicating quality template:', error);
|
||||
toast.error(error.response?.data?.detail || 'Error al duplicar la plantilla de calidad');
|
||||
showToast.error(error.response?.data?.detail || 'Error al duplicar la plantilla de calidad');
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -233,14 +233,14 @@ export function useExecuteQualityCheck(tenantId: string) {
|
||||
: 'Control de calidad completado con observaciones';
|
||||
|
||||
if (result.overall_pass) {
|
||||
toast.success(message);
|
||||
showToast.success(message);
|
||||
} else {
|
||||
toast.error(message);
|
||||
showToast.error(message);
|
||||
}
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Error executing quality check:', error);
|
||||
toast.error(error.response?.data?.detail || 'Error al ejecutar el control de calidad');
|
||||
showToast.error(error.response?.data?.detail || 'Error al ejecutar el control de calidad');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import { useQuery, useMutation, useQueryClient, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { settingsApi } from '../services/settings';
|
||||
import { useToast } from '../../hooks/ui/useToast';
|
||||
import { showToast } from '../../utils/toast';
|
||||
import type {
|
||||
TenantSettings,
|
||||
TenantSettingsUpdate,
|
||||
@@ -58,7 +58,6 @@ export const useCategorySettings = (
|
||||
*/
|
||||
export const useUpdateSettings = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { addToast } = useToast();
|
||||
|
||||
return useMutation<
|
||||
TenantSettings,
|
||||
@@ -69,11 +68,11 @@ export const useUpdateSettings = () => {
|
||||
onSuccess: (data, variables) => {
|
||||
// Invalidate all settings queries for this tenant
|
||||
queryClient.invalidateQueries({ queryKey: settingsKeys.tenant(variables.tenantId) });
|
||||
addToast('Ajustes guardados correctamente', { type: 'success' });
|
||||
showToast.success('Ajustes guardados correctamente');
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error('Failed to update settings:', error);
|
||||
addToast('Error al guardar los ajustes', { type: 'error' });
|
||||
showToast.error('Error al guardar los ajustes');
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -83,7 +82,6 @@ export const useUpdateSettings = () => {
|
||||
*/
|
||||
export const useUpdateCategorySettings = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { addToast } = useToast();
|
||||
|
||||
return useMutation<
|
||||
TenantSettings,
|
||||
@@ -99,11 +97,11 @@ export const useUpdateCategorySettings = () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: settingsKeys.category(variables.tenantId, variables.category),
|
||||
});
|
||||
addToast('Ajustes de categoría guardados correctamente', { type: 'success' });
|
||||
showToast.success('Ajustes de categoría guardados correctamente');
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error('Failed to update category settings:', error);
|
||||
addToast('Error al guardar los ajustes de categoría', { type: 'error' });
|
||||
showToast.error('Error al guardar los ajustes de categoría');
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -113,7 +111,6 @@ export const useUpdateCategorySettings = () => {
|
||||
*/
|
||||
export const useResetCategory = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { addToast } = useToast();
|
||||
|
||||
return useMutation<
|
||||
CategoryResetResponse,
|
||||
@@ -128,13 +125,11 @@ export const useResetCategory = () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: settingsKeys.category(variables.tenantId, variables.category),
|
||||
});
|
||||
addToast(`Categoría '${variables.category}' restablecida a valores predeterminados`, {
|
||||
type: 'success',
|
||||
});
|
||||
showToast.success(`Categoría '${variables.category}' restablecida a valores predeterminados`);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error('Failed to reset category:', error);
|
||||
addToast('Error al restablecer la categoría', { type: 'error' });
|
||||
showToast.error('Error al restablecer la categoría');
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ export const useSubscription = () => {
|
||||
const currentTenant = useCurrentTenant();
|
||||
const user = useAuthUser();
|
||||
const tenantId = currentTenant?.id || user?.tenant_id;
|
||||
const { notifySubscriptionChanged } = useSubscriptionEvents();
|
||||
const { notifySubscriptionChanged, subscriptionVersion } = useSubscriptionEvents();
|
||||
|
||||
// Load subscription data
|
||||
const loadSubscriptionData = useCallback(async () => {
|
||||
@@ -64,9 +64,6 @@ export const useSubscription = () => {
|
||||
features: usageSummary.usage || {},
|
||||
loading: false,
|
||||
});
|
||||
|
||||
// Notify subscribers that subscription data has changed
|
||||
notifySubscriptionChanged();
|
||||
} catch (error) {
|
||||
console.error('Error loading subscription data:', error);
|
||||
setSubscriptionInfo(prev => ({
|
||||
@@ -79,7 +76,7 @@ export const useSubscription = () => {
|
||||
|
||||
useEffect(() => {
|
||||
loadSubscriptionData();
|
||||
}, [loadSubscriptionData]);
|
||||
}, [loadSubscriptionData, subscriptionVersion]);
|
||||
|
||||
// Check if user has a specific feature
|
||||
const hasFeature = useCallback(async (featureName: string): Promise<SubscriptionFeature> => {
|
||||
|
||||
Reference in New Issue
Block a user