2020-04-28 06:52:53 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
|
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
2021-12-27 12:04:45 +00:00
|
|
|
import TextInput from "components/ads/TextInput";
|
2020-10-27 05:02:32 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
|
|
|
|
import styled from "styled-components";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { InputType } from "components/constants";
|
2021-12-27 12:04:45 +00:00
|
|
|
import {
|
|
|
|
|
Field,
|
|
|
|
|
WrappedFieldMetaProps,
|
|
|
|
|
WrappedFieldInputProps,
|
|
|
|
|
} from "redux-form";
|
2020-10-27 05:02:32 +00:00
|
|
|
|
2021-02-26 06:58:47 +00:00
|
|
|
export const StyledInfo = styled.span`
|
2020-10-27 05:02:32 +00:00
|
|
|
font-weight: normal;
|
|
|
|
|
line-height: normal;
|
2021-02-26 06:58:47 +00:00
|
|
|
color: ${Colors.DOVE_GRAY};
|
2020-10-27 05:02:32 +00:00
|
|
|
font-size: 12px;
|
|
|
|
|
margin-left: 1px;
|
|
|
|
|
`;
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
export function InputText(props: {
|
|
|
|
|
label: string;
|
|
|
|
|
value: string;
|
|
|
|
|
isValid: boolean;
|
2021-02-26 06:58:47 +00:00
|
|
|
subtitle?: string;
|
2020-04-28 06:52:53 +00:00
|
|
|
validationMessage?: string;
|
|
|
|
|
placeholder?: string;
|
|
|
|
|
dataType?: string;
|
|
|
|
|
isRequired?: boolean;
|
|
|
|
|
name: string;
|
2020-10-27 05:02:32 +00:00
|
|
|
encrypted?: boolean;
|
2021-02-26 06:58:47 +00:00
|
|
|
disabled?: boolean;
|
2020-04-28 06:52:53 +00:00
|
|
|
}) {
|
2021-12-27 12:04:45 +00:00
|
|
|
const { dataType, disabled, name, placeholder } = props;
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
return (
|
2021-04-28 10:28:39 +00:00
|
|
|
<div data-cy={name} style={{ width: "50vh" }}>
|
2021-12-27 12:04:45 +00:00
|
|
|
<Field
|
|
|
|
|
component={renderComponent}
|
|
|
|
|
datatype={dataType}
|
2021-04-28 10:28:39 +00:00
|
|
|
disabled={disabled || false}
|
2020-04-28 06:52:53 +00:00
|
|
|
placeholder={placeholder}
|
2021-12-27 12:04:45 +00:00
|
|
|
{...props}
|
|
|
|
|
asyncControl
|
2020-04-28 06:52:53 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 12:04:45 +00:00
|
|
|
function renderComponent(
|
|
|
|
|
props: {
|
|
|
|
|
placeholder: string;
|
|
|
|
|
dataType?: InputType;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
} & {
|
|
|
|
|
meta: Partial<WrappedFieldMetaProps>;
|
|
|
|
|
input: Partial<WrappedFieldInputProps>;
|
|
|
|
|
},
|
|
|
|
|
) {
|
|
|
|
|
return (
|
|
|
|
|
<TextInput
|
|
|
|
|
dataType={props.dataType}
|
|
|
|
|
disabled={props.disabled || false}
|
|
|
|
|
name={props.input?.name}
|
|
|
|
|
onChange={props.input.onChange}
|
|
|
|
|
placeholder={props.placeholder}
|
|
|
|
|
value={props.input.value}
|
|
|
|
|
{...props.input}
|
|
|
|
|
width="100%"
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-04-28 06:52:53 +00:00
|
|
|
class InputTextControl extends BaseControl<InputControlProps> {
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
2021-05-13 08:35:39 +00:00
|
|
|
configProperty,
|
|
|
|
|
dataType,
|
|
|
|
|
disabled,
|
2021-12-27 12:04:45 +00:00
|
|
|
encrypted,
|
2020-04-28 06:52:53 +00:00
|
|
|
isValid,
|
|
|
|
|
label,
|
|
|
|
|
placeholderText,
|
2021-05-13 08:35:39 +00:00
|
|
|
propertyValue,
|
2021-02-26 06:58:47 +00:00
|
|
|
subtitle,
|
2021-05-13 08:35:39 +00:00
|
|
|
validationMessage,
|
2020-04-28 06:52:53 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<InputText
|
|
|
|
|
dataType={this.getType(dataType)}
|
2021-02-26 06:58:47 +00:00
|
|
|
disabled={disabled}
|
2021-12-27 12:04:45 +00:00
|
|
|
encrypted={encrypted}
|
2021-04-28 10:28:39 +00:00
|
|
|
isValid={isValid}
|
|
|
|
|
label={label}
|
|
|
|
|
name={configProperty}
|
|
|
|
|
placeholder={placeholderText}
|
2021-02-26 06:58:47 +00:00
|
|
|
subtitle={subtitle}
|
2021-04-28 10:28:39 +00:00
|
|
|
validationMessage={validationMessage}
|
|
|
|
|
value={propertyValue}
|
2020-04-28 06:52:53 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isNumberType(): boolean {
|
|
|
|
|
const { inputType } = this.props;
|
|
|
|
|
switch (inputType) {
|
|
|
|
|
case "CURRENCY":
|
|
|
|
|
case "INTEGER":
|
|
|
|
|
case "NUMBER":
|
|
|
|
|
case "PHONE_NUMBER":
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getType(dataType: InputType | undefined) {
|
|
|
|
|
switch (dataType) {
|
|
|
|
|
case "PASSWORD":
|
|
|
|
|
return "password";
|
|
|
|
|
case "NUMBER":
|
|
|
|
|
return "number";
|
|
|
|
|
default:
|
|
|
|
|
return "text";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getControlType(): ControlType {
|
|
|
|
|
return "INPUT_TEXT";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InputControlProps extends ControlProps {
|
|
|
|
|
placeholderText: string;
|
|
|
|
|
inputType?: InputType;
|
|
|
|
|
dataType?: InputType;
|
2021-02-26 06:58:47 +00:00
|
|
|
subtitle?: string;
|
2020-10-27 05:02:32 +00:00
|
|
|
encrypted?: boolean;
|
2021-02-26 06:58:47 +00:00
|
|
|
disabled?: boolean;
|
2020-04-28 06:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default InputTextControl;
|