mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
- Remove nested git repository from bugulma/frontend/.git - Add all frontend files to main repository tracking - Convert from separate frontend/backend repos to unified monorepo - Preserve all frontend code and development history as tracked files - Eliminate nested repository complexity for simpler development workflow This creates a proper monorepo structure with frontend and backend coexisting in the same repository for easier development and deployment.
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
import {
|
|
createConditionalListQueryHook,
|
|
createDetailQueryHook,
|
|
useInvalidatingMutation,
|
|
} from '@/lib/api-hooks';
|
|
import { createQueryKeyFactory } from '@/lib/query-keys';
|
|
import type { CreateResourceFlowRequest } from '@/schemas/backend/resource-flow';
|
|
import {
|
|
createResourceFlow,
|
|
deleteResourceFlow,
|
|
getResourceFlowById,
|
|
getResourceFlowsByOrganization,
|
|
getResourceFlowsBySite,
|
|
} from '@/services/resources-api';
|
|
|
|
/**
|
|
* Query key factory for resource flows
|
|
* Uses reusable factory to reduce duplication
|
|
*/
|
|
const baseKeys = createQueryKeyFactory('resourceFlows');
|
|
export const resourceFlowKeys = {
|
|
...baseKeys,
|
|
bySite: (siteId: string) => [...baseKeys.all, 'site', siteId] as const,
|
|
byOrganization: (organizationId: string) =>
|
|
[...baseKeys.all, 'organization', organizationId] as const,
|
|
// Deprecated: kept for backwards compatibility
|
|
byBusiness: (businessId: string) => [...baseKeys.all, 'organization', businessId] as const,
|
|
};
|
|
|
|
/**
|
|
* Hook to fetch a single resource flow by ID
|
|
* Uses generic factory for consistent behavior
|
|
*/
|
|
export const useResourceFlow = createDetailQueryHook(
|
|
(id) => resourceFlowKeys.detail(id!),
|
|
(id) => getResourceFlowById(id)
|
|
);
|
|
|
|
/**
|
|
* Hook to fetch resource flows by site ID
|
|
* Uses generic factory for consistent behavior
|
|
*/
|
|
export const useResourceFlowsBySite = createConditionalListQueryHook(
|
|
(siteId) => (siteId ? resourceFlowKeys.bySite(siteId) : []),
|
|
(siteId) => getResourceFlowsBySite(siteId)
|
|
);
|
|
|
|
/**
|
|
* Hook to fetch resource flows by organization ID
|
|
* Resource flows belong to Organizations (not just Businesses)
|
|
* Uses generic factory for consistent behavior
|
|
*/
|
|
export const useResourceFlowsByOrganization = createConditionalListQueryHook(
|
|
(organizationId) => (organizationId ? resourceFlowKeys.byOrganization(organizationId) : []),
|
|
(organizationId) => getResourceFlowsByOrganization(organizationId)
|
|
);
|
|
|
|
/**
|
|
* @deprecated Use useResourceFlowsByOrganization instead
|
|
* Kept for backwards compatibility during migration
|
|
*/
|
|
export const useResourceFlowsByBusiness = useResourceFlowsByOrganization;
|
|
|
|
/**
|
|
* Hook to create a new resource flow
|
|
* Uses reusable mutation utility for consistent invalidation
|
|
*/
|
|
export function useCreateResourceFlow() {
|
|
return useInvalidatingMutation({
|
|
mutationFn: (request: CreateResourceFlowRequest) => createResourceFlow(request),
|
|
invalidateKeys: [resourceFlowKeys.lists()],
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Hook to delete a resource flow
|
|
* Uses reusable mutation utility for consistent invalidation
|
|
*/
|
|
export function useDeleteResourceFlow() {
|
|
return useInvalidatingMutation({
|
|
mutationFn: (id: string) => deleteResourceFlow(id),
|
|
invalidateKeys: [resourceFlowKeys.lists()],
|
|
});
|
|
}
|