Add frontend imporvements 2
This commit is contained in:
@@ -61,9 +61,9 @@ export const inventoryKeys = {
|
||||
export const useIngredients = (
|
||||
tenantId: string,
|
||||
filter?: InventoryFilter,
|
||||
options?: Omit<UseQueryOptions<PaginatedResponse<IngredientResponse>, ApiError>, 'queryKey' | 'queryFn'>
|
||||
options?: Omit<UseQueryOptions<IngredientResponse[], ApiError>, 'queryKey' | 'queryFn'>
|
||||
) => {
|
||||
return useQuery<PaginatedResponse<IngredientResponse>, ApiError>({
|
||||
return useQuery<IngredientResponse[], ApiError>({
|
||||
queryKey: inventoryKeys.ingredients.list(tenantId, filter),
|
||||
queryFn: () => inventoryService.getIngredients(tenantId, filter),
|
||||
enabled: !!tenantId,
|
||||
|
||||
@@ -36,7 +36,7 @@ export class InventoryService {
|
||||
async getIngredients(
|
||||
tenantId: string,
|
||||
filter?: InventoryFilter
|
||||
): Promise<PaginatedResponse<IngredientResponse>> {
|
||||
): Promise<IngredientResponse[]> {
|
||||
const queryParams = new URLSearchParams();
|
||||
|
||||
if (filter?.category) queryParams.append('category', filter.category);
|
||||
@@ -60,7 +60,7 @@ export class InventoryService {
|
||||
? `${this.baseUrl}/${tenantId}/ingredients?${queryParams.toString()}`
|
||||
: `${this.baseUrl}/${tenantId}/ingredients`;
|
||||
|
||||
return apiClient.get<PaginatedResponse<IngredientResponse>>(url);
|
||||
return apiClient.get<IngredientResponse[]>(url);
|
||||
}
|
||||
|
||||
async updateIngredient(
|
||||
@@ -218,8 +218,8 @@ export class InventoryService {
|
||||
if (endDate) queryParams.append('end_date', endDate);
|
||||
|
||||
const url = queryParams.toString()
|
||||
? `${this.baseUrl}/${tenantId}/dashboard/analytics?${queryParams.toString()}`
|
||||
: `${this.baseUrl}/${tenantId}/dashboard/analytics`;
|
||||
? `/tenants/${tenantId}/dashboard/analytics?${queryParams.toString()}`
|
||||
: `/tenants/${tenantId}/dashboard/analytics`;
|
||||
|
||||
return apiClient.get(url);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import React, { useState, useMemo } from 'react';
|
||||
import { Plus, Download, AlertTriangle, Package, Clock, CheckCircle, Eye, Edit, Calendar, DollarSign } from 'lucide-react';
|
||||
import { Button, Input, Card, Badge, StatsGrid, StatusCard, getStatusColor, StatusModal } from '../../../../components/ui';
|
||||
import { Button, Input, Card, StatsGrid, StatusCard, getStatusColor, StatusModal } from '../../../../components/ui';
|
||||
import { LoadingSpinner } from '../../../../components/shared';
|
||||
import { formatters } from '../../../../components/ui/Stats/StatsPresets';
|
||||
import { PageHeader } from '../../../../components/layout';
|
||||
import { InventoryForm, LowStockAlert } from '../../../../components/domain/inventory';
|
||||
import { useIngredients, useLowStockIngredients, useStockAnalytics } from '../../../../api/hooks/inventory';
|
||||
import { LowStockAlert } from '../../../../components/domain/inventory';
|
||||
import { useIngredients, useStockAnalytics } from '../../../../api/hooks/inventory';
|
||||
import { useCurrentTenant } from '../../../../stores/tenant.store';
|
||||
import { IngredientResponse } from '../../../../api/types/inventory';
|
||||
|
||||
@@ -25,21 +25,16 @@ const InventoryPage: React.FC = () => {
|
||||
error: ingredientsError
|
||||
} = useIngredients(tenantId, { search: searchTerm || undefined });
|
||||
|
||||
const {
|
||||
data: lowStockData,
|
||||
isLoading: lowStockLoading
|
||||
} = useLowStockIngredients(tenantId);
|
||||
|
||||
const {
|
||||
data: analyticsData,
|
||||
isLoading: analyticsLoading
|
||||
} = useStockAnalytics(tenantId);
|
||||
|
||||
const ingredients = ingredientsData?.items || [];
|
||||
const lowStockItems = lowStockData || [];
|
||||
const ingredients = ingredientsData || [];
|
||||
const lowStockItems = ingredients.filter(ingredient => ingredient.stock_status === 'low_stock');
|
||||
|
||||
const getInventoryStatusConfig = (ingredient: IngredientResponse) => {
|
||||
const { current_stock_level, low_stock_threshold, stock_status } = ingredient;
|
||||
const { stock_status } = ingredient;
|
||||
|
||||
switch (stock_status) {
|
||||
case 'out_of_stock':
|
||||
|
||||
Reference in New Issue
Block a user