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.
76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
import {
|
|
createDetailQueryHook,
|
|
createListQueryHook,
|
|
useInvalidatingMutation,
|
|
} from '@/lib/api-hooks';
|
|
import { createQueryKeyFactory } from '@/lib/query-keys';
|
|
import type { CreateOrganizationRequest } from '@/schemas/backend/organization';
|
|
import { getOrganizationById, getOrganizations } from '@/services/organization-service';
|
|
import {
|
|
createOrganization,
|
|
deleteOrganization,
|
|
getUserOrganizations,
|
|
} from '@/services/organizations-api';
|
|
|
|
/**
|
|
* Query key factory for organizations
|
|
* Uses reusable factory to reduce duplication
|
|
* Version 2: Fixed JSON array serialization in backend
|
|
*/
|
|
const baseKeys = createQueryKeyFactory('organizations');
|
|
export const organizationKeys = {
|
|
...baseKeys,
|
|
// Override methods to include version for cache invalidation
|
|
lists: () => [...baseKeys.lists(), 'v2'] as const,
|
|
list: (filters?: Record<string, unknown>) => [...baseKeys.list(filters), 'v2'] as const,
|
|
details: () => [...baseKeys.details(), 'v2'] as const,
|
|
detail: (id: string) => [...baseKeys.detail(id), 'v2'] as const,
|
|
user: () => [...baseKeys.all, 'user', 'v2'] as const,
|
|
};
|
|
|
|
/**
|
|
* Hook to fetch all organizations
|
|
* Uses generic factory for consistent behavior
|
|
*/
|
|
export const useOrganizations = createListQueryHook(organizationKeys.lists(), getOrganizations);
|
|
|
|
/**
|
|
* Hook to fetch a single organization by ID
|
|
* Uses generic factory for consistent behavior
|
|
*/
|
|
export const useOrganization = createDetailQueryHook(
|
|
(id) => organizationKeys.detail(id!),
|
|
(id) => getOrganizationById(id)
|
|
);
|
|
|
|
/**
|
|
* Hook to create a new organization
|
|
* Uses reusable mutation utility for consistent invalidation
|
|
*/
|
|
export function useCreateOrganization() {
|
|
return useInvalidatingMutation({
|
|
mutationFn: (request: CreateOrganizationRequest) => createOrganization(request),
|
|
invalidateKeys: [organizationKeys.lists()],
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Hook to delete an organization
|
|
* Uses reusable mutation utility for consistent invalidation
|
|
*/
|
|
export function useDeleteOrganization() {
|
|
return useInvalidatingMutation({
|
|
mutationFn: (id: string) => deleteOrganization(id),
|
|
invalidateKeys: [organizationKeys.lists(), organizationKeys.user()],
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Hook to fetch organizations for the current user
|
|
* Uses generic factory for consistent behavior
|
|
*/
|
|
export const useUserOrganizations = createListQueryHook(
|
|
organizationKeys.user(),
|
|
getUserOrganizations
|
|
);
|