Use Graphql types in FE and complete mappers removal (#348)

Fix Typescript build issues
This commit is contained in:
Charles Bochet
2023-06-21 10:52:00 -07:00
committed by GitHub
parent b179d1f1f0
commit 8a330b9746
35 changed files with 398 additions and 574 deletions

View File

@ -1,26 +1,7 @@
import { ReactNode } from 'react';
import { DocumentNode } from 'graphql';
import {
AnyEntity,
BoolExpType,
GqlType,
UnknownType,
} from '@/utils/interfaces/generic.interface';
export type SearchConfigType<
SearchType extends AnyEntity | UnknownType = UnknownType,
> = SearchType extends UnknownType
? {
query: DocumentNode;
template: (searchInput: string) => any;
resultMapper: (data: any) => any;
}
: {
query: DocumentNode;
template: (searchInput: string) => BoolExpType<SearchType>;
resultMapper: (data: GqlType<SearchType>) => {
value: SearchType;
render: (value: SearchType) => ReactNode;
};
};
export type SearchConfigType = {
query: DocumentNode;
template: (searchInput: string) => any;
resultMapper: (data: any) => any;
};

View File

@ -2,7 +2,6 @@ import { useMemo, useState } from 'react';
import { gql, useQuery } from '@apollo/client';
import { debounce } from '@/utils/debounce';
import { AnyEntity, UnknownType } from '@/utils/interfaces/generic.interface';
import { SearchConfigType } from '../interfaces/interface';
@ -64,22 +63,21 @@ export const SEARCH_COMPANY_QUERY = gql`
}
`;
export type SearchResultsType<T extends AnyEntity | UnknownType = UnknownType> =
{
results: {
render: (value: T) => string;
value: T;
}[];
loading: boolean;
};
export type SearchResultsType<T> = {
results: {
render: (value: T) => string;
value: T;
}[];
loading: boolean;
};
export const useSearch = <T extends AnyEntity | UnknownType = UnknownType>(): [
export const useSearch = <T>(): [
SearchResultsType<T>,
React.Dispatch<React.SetStateAction<string>>,
React.Dispatch<React.SetStateAction<SearchConfigType<T> | null>>,
React.Dispatch<React.SetStateAction<SearchConfigType | null>>,
string,
] => {
const [searchConfig, setSearchConfig] = useState<SearchConfigType<T> | null>(
const [searchConfig, setSearchConfig] = useState<SearchConfigType | null>(
null,
);
const [searchInput, setSearchInput] = useState<string>('');