Skip to content

Commit

Permalink
EditableDetailsV2 added ability to override input type (#2892)
Browse files Browse the repository at this point in the history
* refactor(*): changed handling of date inputs

* ci(*): testing path change

* temporarily disabled test

* updated hook name

* fix(backoffice-v2): no longer looking at form value for input type

* feat(backoffice-v2): added a way to override input type

---------

Co-authored-by: Tomer Shvadron <[email protected]>
  • Loading branch information
Omri-Levy and tomer-shvadron authored Dec 12, 2024
1 parent 5e94853 commit a885d7e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export const EditableDetailsV2: FunctionComponent<IEditableDetailsV2Props> = ({
<EditableDetailV2
name={field.name}
type={props.type}
inputType={
config.inputTypes?.[
path.split('.').at(-1) as keyof typeof config.inputTypes
]
}
format={props.format}
minimum={props.minimum}
maximum={props.maximum}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const EditableDetailV2 = ({
minimum,
maximum,
pattern,
inputType,
parse,
}: {
isEditable: boolean;
Expand All @@ -52,6 +53,7 @@ export const EditableDetailV2 = ({
minimum?: number;
maximum?: number;
pattern?: string;
inputType?: string;
parse?: {
date?: boolean;
isoDate?: boolean;
Expand Down Expand Up @@ -131,7 +133,10 @@ export const EditableDetailV2 = ({
);
}

if (parse?.boolean && (typeof value === 'boolean' || type === 'boolean')) {
if (
parse?.boolean &&
(typeof value === 'boolean' || type === 'boolean' || inputType === 'checkbox')
) {
return (
<FormControl>
<Checkbox_
Expand All @@ -145,16 +150,16 @@ export const EditableDetailV2 = ({
}

if (isEditable) {
const inputType = getInputType({ format, type, value });
const computedInputType = inputType ?? getInputType({ format, type, value });

return (
<FormControl>
<Input
{...(typeof minimum === 'number' && { min: minimum })}
{...(typeof maximum === 'number' && { max: maximum })}
{...(pattern && { pattern })}
{...(inputType === 'datetime-local' && { step: '1' })}
type={inputType}
{...(computedInputType === 'datetime-local' && { step: '1' })}
type={computedInputType}
value={displayValue}
onChange={handleInputChange}
autoComplete={'off'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface IBaseEditableDetailsV2Config {
disabled: boolean;
};
};
inputTypes?: Record<string, HTMLInputElement['type']>;
}

export interface IEditableDetailsV2ConfigWithBlacklist extends IBaseEditableDetailsV2Config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ export const useKycBlock = ({
disabled: !caseState.writeEnabled,
},
},
inputTypes: {
dateOfBirth: 'date',
},
},
},
})
Expand Down

0 comments on commit a885d7e

Please sign in to comment.