Skip to content

Instantly share code, notes, and snippets.

@sp0033212000
Created July 19, 2020 10:02
Show Gist options
  • Save sp0033212000/f20e520a62c368daba6a8a14b49728e8 to your computer and use it in GitHub Desktop.
Save sp0033212000/f20e520a62c368daba6a8a14b49728e8 to your computer and use it in GitHub Desktop.
import React, { useState, useRef, useEffect } from "react";
import { inputTypes, InputData } from "../types/input.types";
import { Field, reduxForm, InjectedFormProps } from "redux-form";
import { Icon } from "semantic-ui-react";
import InputField from "./General/InputFields.js/InputField";
import { connect } from "react-redux";
interface RowProps {
index: number;
}
const Component: React.FC<
RowProps & InjectedFormProps<InputData & RowProps>
> = ({ index }) => {
const [edit, setEdit] = useState<boolean>(false);
const ref = useRef<HTMLInputElement>(null);
useEffect(() => {
if (edit) {
ref.current?.focus();
}
}, [edit, ref]);
const onCheckClick = () => {
setEdit(false);
};
const onCancelClick = () => {
setEdit(false);
};
const uiIconGroup = () => {
if (edit) {
return (
<>
<Icon
onClick={onCheckClick}
className="table__check_icon table__icon"
name="check circle outline"
/>
<Icon
onClick={onCancelClick}
className="table__cancel_icon table__icon"
name="times circle outline"
/>
</>
);
} else {
return (
<>
<Icon
onClick={() => setEdit(true)}
className="table__edit_icon table__icon"
name="edit"
/>
<Icon
className="table__delete_icon table__icon"
name="trash alternate"
/>
</>
);
}
};
return (
<div className="table__row">
{Object.keys(inputTypes).map((key, index) => {
return (
<Field
refEl={index === 0 ? ref : null}
className="table__cell"
key={key}
component={InputField}
name={key}
readOnly={!edit}
/>
);
})}
<div className="table__cell table__cell--icon">{uiIconGroup()}</div>
</div>
);
};
Component.displayName = "Row";
const Row = reduxForm<InputData>({ form: "stock" })(Component);
export default connect(null, {})(Row);
@sp0033212000
Copy link
Author

Argument of type 'FC<RowProps & InjectedFormProps<InputData & RowProps, {}, string>>' is not assignable to parameter of type 'ComponentType<InjectedFormProps<InputData, {}, string>>'. Type 'FunctionComponent<RowProps & InjectedFormProps<InputData & RowProps, {}, string>>' is not assignable to type 'FunctionComponent<InjectedFormProps<InputData, {}, string>>'. Types of property 'propTypes' are incompatible. Type 'WeakValidationMap<RowProps & InjectedFormProps<InputData & RowProps, {}, string>> | undefined' is not assignable to type 'WeakValidationMap<InjectedFormProps<InputData, {}, string>> | undefined'. Type 'WeakValidationMap<RowProps & InjectedFormProps<InputData & RowProps, {}, string>>' is not assignable to type 'WeakValidationMap<InjectedFormProps<InputData, {}, string>>'. Types of property 'handleSubmit' are incompatible. Type 'Validator<SubmitHandler<InputData & RowProps, {}, string>> | undefined' is not assignable to type 'Validator<SubmitHandler<InputData, {}, string>> | undefined'. Type 'Validator<SubmitHandler<InputData & RowProps, {}, string>>' is not assignable to type 'Validator<SubmitHandler<InputData, {}, string>>'. Type 'SubmitHandler<InputData & RowProps, {}, string>' is not assignable to type 'SubmitHandler<InputData, {}, string>'.ts(2345)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment