Files
bigcapital/packages/webapp/src/trpc.ts
Ahmed Bouhuolia 3bf2803360 feat(trpc): implement tRPC integration for accounts module
- Add tRPC server setup with NestJS (nestjs-trpc)
- Create AccountsTrpcRouter with CRUD operations
- Add tRPC client configuration in webapp
- Create tRPC React hooks for accounts module
- Replace existing REST hooks with tRPC hooks across 35+ files
- Maintain backward compatibility with existing REST API
- Add proper cache invalidation for mutations

New files:
- packages/server/src/modules/Trpc/*
- packages/webapp/src/trpc.ts
- packages/webapp/src/hooks/trpc/*
- shared/bigcapital-utils/src/trpc.ts

Dependencies added:
- @trpc/server, @trpc/client, @trpc/react-query
- nestjs-trpc, superjson
- @tanstack/react-query

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 04:34:04 +02:00

43 lines
1.1 KiB
TypeScript

import { createTRPCReact } from '@trpc/react-query';
import { httpBatchLink } from '@trpc/client';
import superjson from 'superjson';
import { store } from '@/store/createStore';
import { tanstackQueryClient } from '@/hooks/query/base';
// Define the AppRouter type - this will be imported from the server package
// For now, we use any until the server exports the proper types
export type AppRouter = any;
export const trpc = createTRPCReact<AppRouter>();
export function getAuthHeaders() {
const state = store.getState();
const { token, organizationId } = state.authentication;
const headers: Record<string, string> = {};
if (token) {
headers['x-access-token'] = token;
}
if (organizationId) {
headers['organization-id'] = organizationId.toString();
}
headers['Accept-Language'] = 'en';
return headers;
}
export const trpcClient = trpc.createClient({
transformer: superjson,
links: [
httpBatchLink({
url: '/api/trpc',
headers() {
return getAuthHeaders();
},
}),
],
});
// Export the QueryClient for use in the TRPCProvider
export const queryClient = tanstackQueryClient;