{"size": 1791, "ext": "js", "max_stars_repo_path": "resources/js/components/Departaments/index.js", "max_stars_repo_name": "gonpineiro/inventario2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "resources/js/components/Departaments/index.js", "max_issues_repo_name": "gonpineiro/inventario2", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "resources/js/components/Departaments/index.js", "max_forks_repo_name": "gonpineiro/inventario2", "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": 26.3382352941, "max_line_length": 79, "alphanum_fraction": 0.5455053043}
import React, { Component } from "react";
import { connect } from "react-redux";

import { departamentColums } from "./columns";

import { Container } from "../Global/styles";
import SubLayout from "../Layout/SubLayout";

import Table from "../Global/Table";
import Form from "./Form";

import * as departamentsActions from "../../Redux/actions/departamentsActions";

class Departaments extends Component {
    async componentDidMount() {
        const {
            bringAll,
            bringAllClients,
            data: { departaments }
        } = this.props;

        if (!departaments.lenght) bringAll();
        bringAllClients();
    }

    content() {
        const {
            bringAll,
            bringOne,
            bringOneDelete,
            data: { departaments },
            loadings: { tableLoading },
            rechargeTable,
            stateForm
        } = this.props;

        if (rechargeTable) bringAll();

        if (tableLoading && !departaments.lenght) return "Loading";

        return (
            <Table
                rows={departaments}
                columns={departamentColums}
                bringOne={bringOne}
                bringOneDelete={bringOneDelete}
                stateForm={stateForm}
            />
        );
    }

    render() {
        const { stateForm, cancel } = this.props;
        return (
            <Container>
                <SubLayout title="Departamentos" changeForm={cancel}>
                    {stateForm === "table" && this.content()}
                    {stateForm !== "table" && <Form />}
                </SubLayout>
            </Container>
        );
    }
}

const mapStateToProps = reducers => reducers.departamentsReducer;

export default connect(mapStateToProps, departamentsActions)(Departaments);
