PromucFlow_constructor/app/client/src/components/utils/ReduxFormTextField.tsx
Ankita Kinger e0edd068f6
chore: Optimising the code for admin settings page (#25404)
## Description


#### PR fixes following issue(s)
Fixes [#25264](https://github.com/appsmithorg/appsmith/issues/25264)

#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## Testing

#### How Has This Been Tested?
- [x] Manual
- [x] Jest
- [x] Cypress

## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-07-18 15:18:48 +05:30

63 lines
1.7 KiB
TypeScript

import React from "react";
import type { WrappedFieldMetaProps, WrappedFieldInputProps } from "redux-form";
import { Field } from "redux-form";
import type { InputType } from "design-system-old";
import { Input, NumberInput } from "design-system";
import type { Intent } from "constants/DefaultTheme";
import { SettingSubtype } from "@appsmith/pages/AdminSettings/config/types";
import { omit } from "lodash";
const renderComponent = (
componentProps: FormTextFieldProps & {
meta: Partial<WrappedFieldMetaProps>;
input: Partial<WrappedFieldInputProps>;
},
) => {
const showError = componentProps.meta.touched && !componentProps.meta.active;
return componentProps.type === SettingSubtype.NUMBER ? (
<NumberInput
{...omit(componentProps, "type")}
{...componentProps.input}
errorMessage={
!componentProps.hideErrorMessage &&
showError &&
componentProps.meta.error &&
componentProps.meta.error
}
label={componentProps.label as string}
/>
) : (
<Input
{...componentProps.input}
{...componentProps}
errorMessage={
!componentProps.hideErrorMessage &&
showError &&
componentProps.meta.error
}
renderAs={"input"}
size="md"
/>
);
};
export type FormTextFieldProps = {
name: string;
placeholder: string;
description?: string;
type?: InputType;
label?: React.ReactNode;
intent?: Intent;
disabled?: boolean;
autoFocus?: boolean;
hideErrorMessage?: boolean;
isRequired?: boolean;
};
function ReduxFormTextField(props: FormTextFieldProps) {
return <Field component={renderComponent} {...props} asyncControl />;
}
export default ReduxFormTextField;