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:
@ -0,0 +1,34 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { isDefined } from '../../utils/type-guards/isDefined';
|
||||
|
||||
export function useListenClickOutsideArrayOfRef<T extends HTMLElement>(
|
||||
arrayOfRef: Array<React.RefObject<T>>,
|
||||
outsideClickCallback: (event?: MouseEvent) => void,
|
||||
) {
|
||||
useEffect(() => {
|
||||
function handleClickOutside(event: any) {
|
||||
const clickedOnAtLeastOneRef = arrayOfRef
|
||||
.filter((ref) => !!ref.current)
|
||||
.some((ref) => ref.current?.contains(event.target as Node));
|
||||
|
||||
if (!clickedOnAtLeastOneRef) {
|
||||
outsideClickCallback(event);
|
||||
}
|
||||
}
|
||||
|
||||
const hasAtLeastOneRefDefined = arrayOfRef.some((ref) =>
|
||||
isDefined(ref.current),
|
||||
);
|
||||
|
||||
if (hasAtLeastOneRefDefined) {
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
document.addEventListener('touchstart', handleClickOutside);
|
||||
}
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handleClickOutside);
|
||||
document.removeEventListener('touchstart', handleClickOutside);
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [arrayOfRef, outsideClickCallback]);
|
||||
}
|
||||
12
front/src/modules/utils/debounce.ts
Normal file
12
front/src/modules/utils/debounce.ts
Normal file
@ -0,0 +1,12 @@
|
||||
export 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);
|
||||
};
|
||||
};
|
||||
5
front/src/modules/utils/type-guards/isDefined.ts
Normal file
5
front/src/modules/utils/type-guards/isDefined.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export function isDefined<T>(
|
||||
value: T | undefined | null,
|
||||
): value is NonNullable<T> {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
13
front/src/modules/utils/type-guards/isNonEmptyArray.ts
Normal file
13
front/src/modules/utils/type-guards/isNonEmptyArray.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export function isNonEmptyArray<T>(
|
||||
probableArray: T[] | undefined | null,
|
||||
): probableArray is NonNullable<T[]> {
|
||||
if (
|
||||
Array.isArray(probableArray) &&
|
||||
probableArray.length &&
|
||||
probableArray.length > 0
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
15
front/src/modules/utils/type-guards/isNonEmptyString.ts
Normal file
15
front/src/modules/utils/type-guards/isNonEmptyString.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { isDefined } from './isDefined';
|
||||
|
||||
export function isNonEmptyString(
|
||||
probableNonEmptyString: string | undefined | null,
|
||||
): probableNonEmptyString is string {
|
||||
if (
|
||||
isDefined(probableNonEmptyString) &&
|
||||
typeof probableNonEmptyString === 'string' &&
|
||||
probableNonEmptyString !== ''
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user