Commit 637b4888 authored by Rémy Huet's avatar Rémy Huet 💻

Fetch infrastructures and categories

parent cfdb552b
Pipeline #32394 passed with stage
in 56 seconds
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Container, Dimmer, Loader } from 'semantic-ui-react';
import { fetchCategories } from '../actions/categoriesActions';
import { fetchInfrastructures } from '../actions/infrastructuresActions';
function Materials({
dispatch,
userToken,
categoriesFetched,
categoriesFetching,
infrastructuresFetched,
infrastructuresFetching,
}) {
if (!categoriesFetched && !categoriesFetching) {
dispatch(fetchCategories(userToken));
}
if (!infrastructuresFetched && !infrastructuresFetching) {
dispatch(fetchInfrastructures(userToken));
}
function Materials() {
return (
<h1>Hello</h1>
<Container style={{ margin: '1em' }}>
{(categoriesFetching || infrastructuresFetching) && (
<Dimmer active>
<Loader>Chargement en cours</Loader>
</Dimmer>
)}
</Container>
);
}
export default connect()(Materials);
Materials.propTypes = {
dispatch: PropTypes.func.isRequired,
userToken: PropTypes.string.isRequired,
categoriesFetched: PropTypes.bool.isRequired,
categoriesFetching: PropTypes.bool.isRequired,
infrastructuresFetched: PropTypes.bool.isRequired,
infrastructuresFetching: PropTypes.bool.isRequired,
};
export default connect(store => ({
userToken: store.user.token,
categoriesFetched: store.categories.fetched,
categoriesFetching: store.categories.fetching,
infrastructuresFetched: store.infrastructures.fetched,
infrastructuresFetching: store.infrastructures.fetching,
}))(Materials);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment