Lucas/t 231 timebox i can create a company at the same time im creating (#140)

This PR is a bit messy:

adding graphql schema
adding create company creation on company select on People page
some frontend refactoring to be continued

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Lucas Bordeau
2023-05-25 23:09:23 +02:00
committed by GitHub
parent fecf45f3bc
commit b0044ed1a2
533 changed files with 20601 additions and 333 deletions
+35
View File
@@ -99,6 +99,41 @@ export async function updatePerson(
const result = await apiClient.mutate({
mutation: UPDATE_PERSON,
variables: mapToGqlPerson(person),
// TODO: use a mapper?
optimisticResponse: {
__typename: 'people' as const,
id: person.id,
update_people: {
returning: {
id: person.id,
city: 'TEST',
company: {
domain_name: person.company?.domainName,
name: person.company?.name,
id: person.company?.id,
},
email: person.email,
firstname: person.firstname,
lastname: person.lastname,
phone: person.phone,
created_at: person.creationDate,
// city
// company {
// domain_name
// name
// id
// }
// email
// firstname
// id
// lastname
// phone
// created_at
},
},
},
});
return result;
}
+6 -16
View File
@@ -5,6 +5,7 @@ import {
AnyEntity,
UnknownType,
} from '../../../interfaces/entities/generic.interface';
import { debounce } from '../../../modules/utils/debounce';
export const SEARCH_PEOPLE_QUERY = gql`
query SearchPeopleQuery($where: PersonWhereInput, $limit: Int) {
@@ -48,19 +49,6 @@ export const SEARCH_COMPANY_QUERY = gql`
}
`;
const debounce = <FuncArgs extends any[]>(
func: (...args: FuncArgs) => void,
delay: number,
) => {
let timeoutId: ReturnType<typeof setTimeout>;
return (...args: FuncArgs) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func(...args);
}, delay);
};
};
export type SearchResultsType<T extends AnyEntity | UnknownType = UnknownType> =
{
results: {
@@ -74,6 +62,7 @@ export const useSearch = <T extends AnyEntity | UnknownType = UnknownType>(): [
SearchResultsType<T>,
React.Dispatch<React.SetStateAction<string>>,
React.Dispatch<React.SetStateAction<SearchConfigType<T> | null>>,
string,
] => {
const [searchConfig, setSearchConfig] = useState<SearchConfigType<T> | null>(
null,
@@ -81,7 +70,7 @@ export const useSearch = <T extends AnyEntity | UnknownType = UnknownType>(): [
const [searchInput, setSearchInput] = useState<string>('');
const debouncedsetSearchInput = useMemo(
() => debounce(setSearchInput, 500),
() => debounce(setSearchInput, 50),
[],
);
@@ -119,11 +108,12 @@ export const useSearch = <T extends AnyEntity | UnknownType = UnknownType>(): [
}
return {
loading: false,
results: searchQueryResults.data.searchResults.map(
// TODO: add proper typing
results: searchQueryResults?.data?.searchResults?.map(
searchConfig.resultMapper,
),
};
}, [searchConfig, searchQueryResults]);
return [searchResults, debouncedsetSearchInput, setSearchConfig];
return [searchResults, debouncedsetSearchInput, setSearchConfig, searchInput];
};