feature/14-code-cleanup
This commit is contained in:
parent
0e7f75bf21
commit
3c4c9c1ef9
5 changed files with 20 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
|||
import React from 'react';
|
||||
import CustomParamButton from './CustomParamButton';
|
||||
import CustomParamButton, { CustomParamButtonType } from './CustomParamButton';
|
||||
import { isFirstParam } from './CustomParams';
|
||||
|
||||
interface Props {
|
||||
|
@ -17,8 +17,8 @@ const CustomParamAction: React.FC<Props> = ({
|
|||
<label className='label'> </label>
|
||||
{
|
||||
isFirstParam(index)
|
||||
? <CustomParamButton btnColor="is-success" btnIcon='fa-plus' onClick={onAdd} />
|
||||
: <CustomParamButton btnColor="is-danger" btnIcon='fa-minus' onClick={() => onRemove(index)} />
|
||||
? <CustomParamButton className="is-success" type={CustomParamButtonType.plus} onClick={onAdd} />
|
||||
: <CustomParamButton className="is-danger" type={CustomParamButtonType.minus} onClick={() => onRemove(index)} />
|
||||
}
|
||||
</>
|
||||
)
|
||||
|
|
|
@ -1,19 +1,24 @@
|
|||
import React from 'react';
|
||||
|
||||
export enum CustomParamButtonType {
|
||||
plus = 'fa-plus',
|
||||
minus = 'fa-minus',
|
||||
}
|
||||
|
||||
interface Props {
|
||||
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void,
|
||||
btnColor: string;
|
||||
btnIcon: string;
|
||||
className: string;
|
||||
type: CustomParamButtonType;
|
||||
}
|
||||
|
||||
const CustomParamButton: React.FC<Props> = ({
|
||||
onClick,
|
||||
btnColor,
|
||||
btnIcon,
|
||||
className,
|
||||
type,
|
||||
}) => (
|
||||
<button className={`button ${btnColor} is-outlined`} onClick={onClick}>
|
||||
<button className={`button ${className} is-outlined`} onClick={onClick}>
|
||||
<span className="icon">
|
||||
<i className={`fas fa-lg ${btnIcon}`}></i>
|
||||
<i className={`fas fa-lg ${type}`}></i>
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
|
|
|
@ -24,7 +24,7 @@ const CustomParamSelect: React.FC<Props> = ({
|
|||
);
|
||||
|
||||
const selectedMustBeUniq = (selected: string) => {
|
||||
const values: any = getValues({ nest: true });
|
||||
const values = getValues({ nest: true });
|
||||
const customParamsValues: TopicFormCustomParam = values.customParams;
|
||||
|
||||
let valid = true;
|
||||
|
|
|
@ -20,7 +20,7 @@ const CustomParamValue: React.FC<Props> = ({
|
|||
const { register, unregister, errors, watch, setValue } = useFormContext();
|
||||
const selectInputName: string = `${index}[name]`;
|
||||
const valInputName: string = `${index}[value]`;
|
||||
const selectedParamName: any = watch(selectInputName, name);
|
||||
const selectedParamName = watch(selectInputName, name);
|
||||
|
||||
React.useEffect(
|
||||
() => {
|
||||
|
|
|
@ -6,9 +6,9 @@ import CustomParamSelect from './CustomParamSelect';
|
|||
import CustomParamValue from './CustomParamValue';
|
||||
import CustomParamAction from './CustomParamAction';
|
||||
|
||||
const DEF_INDEX = 'default';
|
||||
const DEFAULT_INDEX = 'default';
|
||||
export const INDEX_PREFIX = 'customParams';
|
||||
export const isFirstParam = (index: string) => (index === DEF_INDEX);
|
||||
export const isFirstParam = (index: string) => (index === DEFAULT_INDEX);
|
||||
|
||||
interface Props {
|
||||
isSubmitting: boolean;
|
||||
|
@ -19,8 +19,8 @@ const CustomParams: React.FC<Props> = ({
|
|||
}) => {
|
||||
|
||||
const [formCustomParams, setFormCustomParams] = React.useState<TopicFormCustomParams>({
|
||||
byIndex: { [DEF_INDEX]: { name: '', value: '' } },
|
||||
allIndexes: [DEF_INDEX],
|
||||
byIndex: { [DEFAULT_INDEX]: { name: '', value: '' } },
|
||||
allIndexes: [DEFAULT_INDEX],
|
||||
});
|
||||
|
||||
const onAdd = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue