Files
dashboard/context/hooks/useLocationHelpers.ts
Alberto-Audrix 32a36cceff
CI / lint-and-test (push) Canceled after 0s
first commit
2026-07-28 08:55:05 +07:00

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,
};
};