diff --git a/striker-ui/components/GeneralInitForm.tsx b/striker-ui/components/GeneralInitForm.tsx index d166007a..d1739239 100644 --- a/striker-ui/components/GeneralInitForm.tsx +++ b/striker-ui/components/GeneralInitForm.tsx @@ -14,7 +14,6 @@ import { REP_DOMAIN } from '../lib/consts/REG_EXP_PATTERNS'; import FlexBox from './FlexBox'; import InputWithRef, { InputForwardedRefContent } from './InputWithRef'; -import isEmpty from '../lib/isEmpty'; import MessageBox, { Message } from './MessageBox'; import MessageGroup, { MessageGroupForwardedRefContent } from './MessageGroup'; import OutlinedInputWithLabel, { @@ -87,7 +86,7 @@ const buildHostName = ({ hostNumber?: number; domainName?: string; }) => - isEmpty([organizationPrefix, hostNumber, domainName], { not: true }) + [organizationPrefix, hostNumber, domainName].every((value) => Boolean(value)) ? `${organizationPrefix}-striker${pad(hostNumber)}.${domainName}` : ''; @@ -422,24 +421,16 @@ const GeneralInitForm = forwardRef< [testInputToToggleSubmitDisabled], ); const isOrganizationPrefixPrereqFilled = useCallback( - () => - isEmpty([organizationNameInputRef.current.getValue?.call(null)], { - not: true, - }), + () => Boolean(organizationNameInputRef.current.getValue?.call(null)), [], ); const isHostNamePrereqFilled = useCallback( () => - isEmpty( - [ - organizationPrefixInputRef.current.getValue?.call(null), - hostNumberInputRef.current.getValue?.call(null), - domainNameInputRef.current.getValue?.call(null), - ], - { - not: true, - }, - ), + [ + organizationPrefixInputRef.current.getValue?.call(null), + hostNumberInputRef.current.getValue?.call(null), + domainNameInputRef.current.getValue?.call(null), + ].every((value) => Boolean(value)), [], ); const populateOrganizationPrefixInputOnBlur: OutlinedInputWithLabelOnBlur = diff --git a/striker-ui/lib/isEmpty.ts b/striker-ui/lib/isEmpty.ts deleted file mode 100644 index 23be50ce..00000000 --- a/striker-ui/lib/isEmpty.ts +++ /dev/null @@ -1,35 +0,0 @@ -type IsEmptyTypeMap = Pick< - MapToType, - 'number' | 'object' | 'string' | 'undefined' ->; - -type MapToValueIsEmptyFunction = { - [TypeName in keyof IsEmptyTypeMap]: ( - value: IsEmptyTypeMap[TypeName], - ) => boolean; -}; - -const MAP_TO_VALUE_IS_EMPTY_FUNCTION: MapToValueIsEmptyFunction = { - number: (value = 0) => value === 0, - object: (value) => Object.keys(value).length === 0, - string: (value = '') => value.trim().length === 0, - undefined: () => true, -}; - -const isEmpty = ( - values: Array, - { not, fn = 'every' }: { not?: boolean; fn?: 'every' | 'some' } = {}, -): boolean => - values[fn]((value) => { - const type = typeof value as TypeName; - - let result = MAP_TO_VALUE_IS_EMPTY_FUNCTION[type](value); - - if (not) { - result = !result; - } - - return result; - }); - -export default isEmpty;