29 lines
802 B
TypeScript
29 lines
802 B
TypeScript
import { useNavigate } from 'react-router-dom';
|
|
|
|
export type EntityType = 'PROPERTY' | 'TENANT' | 'CONTRACT' | 'INCOME' | 'EXPENSE' | 'INCIDENT' | 'PROPERTY_GROUP' | 'DOCUMENT' | 'BANK_ACCOUNT';
|
|
|
|
const ROUTES: Record<EntityType, string> = {
|
|
PROPERTY: '/properties',
|
|
PROPERTY_GROUP: '/property-groups',
|
|
TENANT: '/tenants',
|
|
CONTRACT: '/contracts',
|
|
INCOME: '/incomes',
|
|
EXPENSE: '/expenses',
|
|
INCIDENT: '/incidents',
|
|
DOCUMENT: '/documents',
|
|
BANK_ACCOUNT: '/bank-accounts',
|
|
};
|
|
|
|
export function useEntityNavigation() {
|
|
const navigate = useNavigate();
|
|
|
|
const navigateToEntity = (entityType: EntityType, entityId: number) => {
|
|
const route = ROUTES[entityType];
|
|
if (route) {
|
|
navigate(route, { state: { openDetailId: entityId } });
|
|
}
|
|
};
|
|
|
|
return { navigateToEntity };
|
|
}
|