Добавлено получение информации о деталях из Parts Index и обновлены компоненты для отображения этой информации. Включены новые типы для работы с данными Parts Index.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { partsIndexService } from '@/lib/partsindex-service';
|
||||
import { PartsIndexCatalog, PartsIndexGroup, PartsIndexTabData } from '@/types/partsindex';
|
||||
import { PartsIndexCatalog, PartsIndexGroup, PartsIndexTabData, PartsIndexEntityInfo } from '@/types/partsindex';
|
||||
|
||||
export const usePartsIndexCatalogs = () => {
|
||||
const [catalogs, setCatalogs] = useState<PartsIndexCatalog[]>([]);
|
||||
@ -59,6 +59,44 @@ export const usePartsIndexCatalogGroups = (catalogId: string | null) => {
|
||||
return { group, loading, error };
|
||||
};
|
||||
|
||||
export const usePartsIndexEntityInfo = (code: string | null, brand?: string | null) => {
|
||||
const [entityInfo, setEntityInfo] = useState<PartsIndexEntityInfo | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!code) {
|
||||
setEntityInfo(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchEntityInfo = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
const response = await partsIndexService.getEntityInfo(code, brand || undefined, 'ru');
|
||||
|
||||
// Берем первый элемент из списка, если он есть
|
||||
if (response.list && response.list.length > 0) {
|
||||
setEntityInfo(response.list[0]);
|
||||
} else {
|
||||
setEntityInfo(null);
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err as Error);
|
||||
console.error(`Ошибка загрузки информации о детали ${code}:`, err);
|
||||
setEntityInfo(null);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchEntityInfo();
|
||||
}, [code, brand]);
|
||||
|
||||
return { entityInfo, loading, error };
|
||||
};
|
||||
|
||||
// Функция для преобразования данных Parts Index в формат меню
|
||||
export const transformPartsIndexToTabData = (
|
||||
catalogs: PartsIndexCatalog[],
|
||||
|
Reference in New Issue
Block a user