28 lines
880 B
TypeScript
28 lines
880 B
TypeScript
import { useCallback } from 'react';
|
|
import { useLocationStore } from '../stores/useLocationStore.ts';
|
|
|
|
export const useLocationHelpers = (locationStore: ReturnType<typeof useLocationStore>) => {
|
|
const { locations, coops, floors } = locationStore;
|
|
|
|
const getFullLocationName = useCallback(
|
|
(floorId: string | null): string => {
|
|
if (!floorId) return 'Belum Ditempatkan';
|
|
const floor = floors.find((f) => f.id === floorId);
|
|
if (!floor) return 'Lantai Tidak Dikenal';
|
|
|
|
const coop = coops.find((c) => c.id === floor.coopId);
|
|
if (!coop) return 'Kandang Tidak Dikenal';
|
|
|
|
const location = locations.find((l) => l.id === coop.locationId);
|
|
if (!location) return 'Lokasi Tidak Dikenal';
|
|
|
|
return `${location.name} / ${coop.name} / ${floor.name}`;
|
|
},
|
|
[locations, coops, floors]
|
|
);
|
|
|
|
return {
|
|
getFullLocationName,
|
|
};
|
|
};
|