{"size": 2608, "ext": "js", "max_stars_repo_path": "src/components/Sidebar/SidebarDefault.js", "max_stars_repo_name": "matheusmhq/conectando-socios-react-js", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/Sidebar/SidebarDefault.js", "max_issues_repo_name": "matheusmhq/conectando-socios-react-js", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/Sidebar/SidebarDefault.js", "max_forks_repo_name": "matheusmhq/conectando-socios-react-js", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.8771929825, "max_line_length": 78, "alphanum_fraction": 0.5467791411}
import React, { useEffect, useState } from "react";
import { Col } from "react-bootstrap";

import BtnDefault from "components/Form/Buttons/BtnDefault";
import DropdownDefault from "components/Form/Dropdowns/DropdownDefault";
import { getCity, getState, getTypes } from "functions/requests/requestGet";

function SidebarDefault({ history, ...props }) {
  const {
    idType,
    setIdType,
    idState,
    setIdState,
    idCity,
    setIdCity,
    setPage,
    reload,
    setReload,
  } = props;

  const [loading, setLoading] = useState(false);
  const [optionsState, setOptionsState] = useState([]);
  const [optionsCity, setOptionsCity] = useState([]);
  const [optionsTypes, setOptionsTypes] = useState([]);

  useEffect(() => {
    getState(setOptionsState);
    getTypes(setOptionsTypes);
  }, []);

  useEffect(() => {
    if (idState > 0) getCity(setOptionsCity, setLoading, idState);
    else {
      setOptionsCity([]);
      setIdCity(0);
    }
  }, [idState]);

  const ClearFields = () => {
    setIdType(0);
    setIdState(0);
    setIdCity(0);
    setPage(1);
    setReload(!reload);
  };

  const ApplyFilter = () => {
    setPage(1);
    setReload(!reload);
  };

  console.log("idType " + idType);

  return (
    <div className="sidebar-filters w-100">
      <h4 className="title-default">Filtros</h4>

      <Col md={12}>
        <DropdownDefault
          label={"Categoria"}
          name={"type"}
          onChange={setIdType}
          value={idType}
          options={optionsTypes}
        />
      </Col>

      <Col md={12}>
        <DropdownDefault
          label={"Estado"}
          name={"state"}
          onChange={setIdState}
          value={idState}
          options={optionsState}
        />
      </Col>

      <Col md={12}>
        <DropdownDefault
          label={"Cidade"}
          name={"city"}
          onChange={setIdCity}
          value={idCity}
          options={optionsCity}
          customClass={"mb-0"}
        />
      </Col>

      <Col md={12} className="mt-3">
        <BtnDefault
          disabled={idType > 0 || idCity > 0 || idState > 0 ? false : true}
          size={"md"}
          title={"Filtrar"}
          block={true}
          onClick={ApplyFilter}
        />
      </Col>

      <Col md={12} className="mt-3">
        <BtnDefault
          disabled={idType == 0 && idCity == 0 && idState == 0 ? true : false}
          size={"md"}
          title={"Limpar"}
          block={true}
          variant={"outline-secondary"}
          onClick={ClearFields}
        />
      </Col>
    </div>
  );
}

export default SidebarDefault;
