{"size": 1109, "ext": "js", "max_stars_repo_path": "resources/js/fields/FormFieldComponent.js", "max_stars_repo_name": "itsjeffro/panel", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "resources/js/fields/FormFieldComponent.js", "max_issues_repo_name": "itsjeffro/panel", "max_issues_repo_issues_event_min_datetime": "2021-09-12T09:48:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T08:25:40.000Z", "max_forks_repo_path": "resources/js/fields/FormFieldComponent.js", "max_forks_repo_name": "itsjeffro/panel", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 12, "max_forks_count": null, "avg_line_length": 29.972972973, "max_line_length": 97, "alphanum_fraction": 0.7006311993}
import React from 'react';
import PasswordFormField from './Password/FormField';
import BelongsToField from './BelongsTo/FormField';
import MorphToManyField from './MorphToMany/FormField';
import TextareaField from './Textarea/FormField';
import TextField from "./Text/FormField";
import DateTimeField from "./DateTime/FormField";

const FormFieldComponent = (props) => {
  const components = {
    Password: PasswordFormField,
    BelongsTo: BelongsToField,
    MorphToMany: MorphToManyField,
    Textarea: TextareaField,
    DateTime: DateTimeField,
  };

  const { component, errors, field } = props;

  const ComponentName = components[component] || TextField;
  const column = field.attribute;
  const hasError = errors !== null && errors.hasOwnProperty(column);
  const messageError = errors !== null && errors.hasOwnProperty(column) ? errors[column][0] : '';
  const value = props.value || '';

  return (
    <ComponentName
      { ...props }
      column={ column }
      value={ value }
      hasError={ hasError }
      messageError={ messageError }
    />
  )
}

export default FormFieldComponent;