import type { TRPCClientErrorBase } from '@trpc/react-query'; import { createTRPCReact } from '@trpc/react-query'; import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server'; import type { ExternalToast } from 'sonner'; import { toast } from 'sonner'; import type { AppRouter } from '@openpanel/trpc'; export const api = createTRPCReact({}); /** * Inference helper for inputs. * * @example type HelloInput = RouterInputs['example']['hello'] */ export type RouterInputs = inferRouterInputs; /** * Inference helper for outputs. * * @example type HelloOutput = RouterOutputs['example']['hello'] */ export type RouterOutputs = inferRouterOutputs; export type IChartData = RouterOutputs['chart']['chart']; export type IChartSerieDataItem = IChartData['series'][number]['data'][number]; export function handleError(error: TRPCClientErrorBase) { toast('Error', { description: error.message, }); } export function handleErrorToastOptions(options: ExternalToast) { return (error: TRPCClientErrorBase) => { toast('Error', { description: error.message, ...options, }); }; }