Commit db52ddd0 authored by Florent Chehab's avatar Florent Chehab

reafacto(front): cleaned renderCore and outside data related to module wrapper

parent fa557fb3
......@@ -20,6 +20,9 @@ import NumberField from "./fields/NumberField";
import { getLatestReadDataFromStore } from "../../redux/api/utils";
import HiddenField from "./fields/HiddenField";
import LanguageService from "../../services/data/LanguageService";
import UniversityService from "../../services/data/UniversityService";
import CurrencyService from "../../services/data/CurrencyService";
import CountryService from "../../services/data/CountryService";
export default {
/**
......@@ -129,37 +132,23 @@ export default {
},
renderUniversitiesField() {
const { outsideData } = this.props;
const universities = outsideData.universities.map(univ => ({
label: univ.name,
value: univ.id,
disabled: false
}));
return (
<MultiSelectField
label="Universités concernées"
{...this.getReferenceAndValue("universities")}
required
options={universities}
options={UniversityService.getUniversitiesOptions()}
/>
);
},
renderCountriesField() {
const { outsideData } = this.props;
const countries = outsideData.countries.map(country => ({
label: country.name,
value: country.id,
disabled: false
}));
return (
<MultiSelectField
label="Pays concernés"
{...this.getReferenceAndValue("countries")}
required
options={countries}
options={CountryService.getCountryOptions()}
/>
);
},
......@@ -169,16 +158,9 @@ export default {
},
renderCurrencyField(props) {
const { outsideData } = this.props;
const currencies = outsideData.currencies.map(c => ({
label: c.name ? c.name : c.code,
value: c.code,
disabled: false
}));
return this.renderSelectField({
...props,
options: currencies
options: CurrencyService.getCurrenciesOptions()
});
},
......
import React from "react";
import PropTypes from "prop-types";
import withStyles from "@material-ui/core/styles/withStyles";
import compose from "recompose/compose";
import { connect } from "react-redux";
......@@ -30,19 +29,11 @@ class CountryDriForm extends Form {
class CountryDriEditor extends Editor {
renderForm() {
return (
<CountryDriForm
modelData={this.props.rawModelData}
outsideData={this.props.outsideData}
ref={this.formRef}
/>
<CountryDriForm modelData={this.props.rawModelData} ref={this.formRef} />
);
}
}
CountryDriEditor.propTypes = {
outsideData: PropTypes.object.isRequired
};
export default compose(
withStyles(styles, { withTheme: true }),
connect(
......
import React from "react";
import PropTypes from "prop-types";
import withStyles from "@material-ui/core/styles/withStyles";
import compose from "recompose/compose";
import { connect } from "react-redux";
......@@ -24,17 +23,12 @@ class CountryScholarshipEditor extends Editor {
return (
<CountryScholarshipForm
modelData={this.props.rawModelData}
outsideData={this.props.outsideData}
ref={this.formRef}
/>
);
}
}
CountryScholarshipEditor.propTypes = {
outsideData: PropTypes.object.isRequired
};
export default compose(
withStyles(styles, { withTheme: true }),
connect(
......
......@@ -35,11 +35,7 @@ class TaggedItemForm extends Form {
class TaggedItemEditor extends Editor {
renderForm() {
return (
<TaggedItemForm
modelData={this.props.rawModelData}
outsideData={this.props.outsideData}
ref={this.formRef}
/>
<TaggedItemForm modelData={this.props.rawModelData} ref={this.formRef} />
);
}
}
......
import React from "react";
import PropTypes from "prop-types";
import withStyles from "@material-ui/core/styles/withStyles";
import compose from "recompose/compose";
import { connect } from "react-redux";
......@@ -32,17 +31,12 @@ class UniversityDriEditor extends Editor {
return (
<UniversityDriForm
modelData={this.props.rawModelData}
outsideData={this.props.outsideData}
ref={this.formRef}
/>
);
}
}
UniversityDriEditor.propTypes = {
outsideData: PropTypes.object.isRequired
};
export default compose(
withStyles(styles, { withTheme: true }),
connect(
......
import React from "react";
import PropTypes from "prop-types";
import withStyles from "@material-ui/core/styles/withStyles";
import compose from "recompose/compose";
import { connect } from "react-redux";
......@@ -26,17 +25,12 @@ class UniversityScholarshipEditor extends Editor {
return (
<UniversityScholarshipForm
modelData={this.props.rawModelData}
outsideData={this.props.outsideData}
ref={this.formRef}
/>
);
}
}
UniversityScholarshipEditor.propTypes = {
outsideData: PropTypes.object.isRequired
};
export default compose(
withStyles(styles, { withTheme: true }),
connect(
......
import React, { useCallback, useEffect } from "react";
import React, { useEffect } from "react";
import PropTypes from "prop-types";
import compose from "recompose/compose";
import { useDispatch } from "react-redux";
import Markdown from "../../common/markdown/Markdown";
......@@ -9,36 +8,38 @@ import ModuleWrapper from "./common/ModuleWrapper";
import ModuleGroupWrapper from "./common/ModuleGroupWrapper";
import CountryDriEditor from "../editors/CountryDriEditor";
import getActions from "../../../redux/api/getActions";
import withUnivInfo from "../common/withUnivInfo";
import RequestParams from "../../../redux/api/RequestParams";
import CountryService from "../../../services/data/CountryService";
import withNetworkWrapper, {
getApiPropTypes,
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
import useInvalidateAll from "../../../hooks/useInvalidateAll";
// eslint-disable-next-line no-unused-vars
function renderCore(rawModelData, classes, outsideData) {
function CoreComponent({ rawModelData }) {
const { comment } = rawModelData;
return <Markdown source={comment} />;
}
CoreComponent.propTypes = {
rawModelData: PropTypes.shape({
comment: PropTypes.string
})
};
CoreComponent.defaultProps = {
rawModelData: { comment: "" }
};
const buildParams = countryId =>
RequestParams.Builder.withQueryParam("countries", countryId).build();
function CountryDri({ countryId, countryDriItems, api }) {
const dispatch = useDispatch();
useEffect(() => {
api.countryDriItems.setParams(buildParams(countryId));
}, [countryId]);
const invalidateData = useCallback(() => {
dispatch(getActions("countryDri").invalidateAll());
}, [dispatch]);
const outsideData = { countries: CountryService.getCountries() };
const invalidateData = useInvalidateAll("countryDri");
return (
<ModuleGroupWrapper
......@@ -50,9 +51,6 @@ function CountryDri({ countryId, countryDriItems, api }) {
countries: [countryId],
importance_level: "-"
}}
propsForEditor={{
outsideData
}}
>
{countryDriItems.map((rawModelData, idx) => (
<ModuleWrapper
......@@ -61,9 +59,7 @@ function CountryDri({ countryId, countryDriItems, api }) {
buildTitle={modelData => modelData.title}
rawModelData={rawModelData}
editor={CountryDriEditor}
renderCore={renderCore}
coreClasses={{}}
outsideData={outsideData}
CoreComponent={CoreComponent}
moduleInGroupInfos={{
isInGroup: true,
invalidateGroup: () => this.props.invalidateData()
......
import React, { useCallback, useEffect } from "react";
import React, { useEffect } from "react";
import PropTypes from "prop-types";
import compose from "recompose/compose";
import { useDispatch } from "react-redux";
import { makeStyles } from "@material-ui/styles";
......@@ -11,16 +10,13 @@ import ModuleGroupWrapper from "./common/ModuleGroupWrapper";
import Scholarship from "./common/Scholarship";
import CountryScholarshipEditor from "../editors/CountryScholarshipEditor";
import getActions from "../../../redux/api/getActions";
import withUnivInfo from "../common/withUnivInfo";
import RequestParams from "../../../redux/api/RequestParams";
import CountryService from "../../../services/data/CountryService";
import CurrencyService from "../../../services/data/CurrencyService";
import withNetworkWrapper, {
getApiPropTypes,
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
import useInvalidateAll from "../../../hooks/useInvalidateAll";
const useStyles = makeStyles(theme => ({
item: {
......@@ -29,26 +25,42 @@ const useStyles = makeStyles(theme => ({
}
}));
// eslint-disable-next-line no-unused-vars
function renderCore(rawModelData, classes, outsideData) {
const { comment, frequency, currency, short_description } = rawModelData;
const amountMin = rawModelData.amount_min;
const amountMax = rawModelData.amount_max;
const otherAdvantages = rawModelData.other_advantages;
function CoreComponent({ rawModelData }) {
const {
comment,
frequency,
currency,
short_description,
amount_min,
amount_max,
other_advantages
} = rawModelData;
return (
<Scholarship
currency={currency}
frequency={frequency}
shortDescription={short_description}
amountMin={amountMin}
amountMax={amountMax}
otherAdvantages={otherAdvantages}
amountMin={amount_min}
amountMax={amount_max}
otherAdvantages={other_advantages}
comment={comment}
/>
);
}
CoreComponent.propTypes = {
rawModelData: PropTypes.shape({
comment: PropTypes.string,
frequency: PropTypes.string,
currency: PropTypes.number,
short_description: PropTypes.string,
amount_min: PropTypes.number,
amount_max: PropTypes.number,
other_advantages: PropTypes.string
}).isRequired
};
const buildParams = countryId =>
RequestParams.Builder.withQueryParam("countries", countryId).build();
......@@ -59,20 +71,12 @@ function CountryScholarships({
api
}) {
const classes = useStyles();
const dispatch = useDispatch();
useEffect(() => {
api.countryScholarshipsItems.setParams(buildParams(countryId));
}, [countryId]);
const invalidateData = useCallback(() => {
dispatch(getActions("countryScholarships").invalidateAll());
}, [dispatch]);
const outsideData = {
countries: CountryService.getCountries(),
currencies: CurrencyService.getCurrencies()
};
const invalidateData = useInvalidateAll("countryScholarships");
return (
<ModuleGroupWrapper
......@@ -86,9 +90,6 @@ function CountryScholarships({
currency: "EUR",
obj_moderation_level: 0
}}
propsForEditor={{
outsideData
}}
>
{countryScholarshipsItems.map(rawModelData => (
<div key={rawModelData.id} className={classes.item}>
......@@ -96,9 +97,7 @@ function CountryScholarships({
buildTitle={modelData => modelData.title}
rawModelData={rawModelData}
editor={CountryScholarshipEditor}
renderCore={renderCore}
coreClasses={classes}
outsideData={outsideData}
CoreComponent={CoreComponent}
moduleInGroupInfos={{
isInGroup: true,
invalidateGroup: invalidateData
......
......@@ -2,8 +2,6 @@ import React, { useEffect } from "react";
import PropTypes from "prop-types";
import compose from "recompose/compose";
import { useDispatch } from "react-redux";
import { makeStyles } from "@material-ui/styles";
import ModuleWrapper from "./common/ModuleWrapper";
import SharedUnivFeedbackEditor from "../editors/SharedUnivFeedbackEditor";
......@@ -17,34 +15,21 @@ import withNetworkWrapper, {
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
const useStyles = makeStyles(theme => ({
root: {
width: "100%",
overflowX: "auto"
},
tableCell: {
padding: "2px"
},
content: {
display: "flex",
alignItems: "center"
},
icon: {
paddingRight: theme.spacing(1)
}
}));
// eslint-disable-next-line no-unused-vars
function renderCore(rawModelData, classes) {
function CoreComponent({ rawModelData }) {
const { comment } = rawModelData;
return <TruncatedMarkdown truncateFromLength={1000} source={comment} />;
}
CoreComponent.propTypes = {
rawModelData: PropTypes.shape({
comment: PropTypes.string
}).isRequired
};
const buildParams = univId =>
RequestParams.Builder.withQueryParam("university", univId).build();
function SharedUnivFeedback({ univId, api, feedback }) {
const classes = useStyles();
const dispatch = useDispatch();
useEffect(() => {
......@@ -58,8 +43,7 @@ function SharedUnivFeedback({ univId, api, feedback }) {
}
rawModelData={feedback[0]}
editor={SharedUnivFeedbackEditor}
renderCore={renderCore}
coreClasses={classes}
CoreComponent={CoreComponent}
moduleInGroupInfos={{
isInGroup: true,
invalidateGroup: () =>
......
......@@ -10,8 +10,7 @@ import {
} from "../editors/TaggedItemEditor";
import TruncatedMarkdown from "../../common/markdown/TruncatedMarkdown";
// eslint-disable-next-line no-unused-vars
function renderCore(rawModelData, classes, outsideData) {
function CoreComponent({ rawModelData }) {
const { comment } = rawModelData;
return (
<>
......@@ -26,6 +25,12 @@ function renderCore(rawModelData, classes, outsideData) {
);
}
CoreComponent.propTypes = {
rawModelData: PropTypes.shape({
comment: PropTypes.string
}).isRequired
};
function TaggedItem(props) {
return (
<ModuleWrapper
......@@ -36,7 +41,7 @@ function TaggedItem(props) {
? CountryTaggedItemEditor
: UniversityTaggedItemEditor
}
renderCore={renderCore}
CoreComponent={CoreComponent}
moduleInGroupInfos={{
isInGroup: true,
invalidateGroup: () => props.invalidateGroup()
......
import React, { useCallback, useEffect } from "react";
import React, { useEffect } from "react";
import PropTypes from "prop-types";
import compose from "recompose/compose";
import { useDispatch } from "react-redux";
import Markdown from "../../common/markdown/Markdown";
......@@ -9,38 +8,35 @@ import ModuleWrapper from "./common/ModuleWrapper";
import ModuleGroupWrapper from "./common/ModuleGroupWrapper";
import UniversityDriEditor from "../editors/UniversityDriEditor";
import getActions from "../../../redux/api/getActions";
import RequestParams from "../../../redux/api/RequestParams";
import UniversityService from "../../../services/data/UniversityService";
import withNetworkWrapper, {
getApiPropTypes,
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
import withUnivInfo from "../common/withUnivInfo";
import useInvalidateAll from "../../../hooks/useInvalidateAll";
// eslint-disable-next-line no-unused-vars
function renderCore(rawModelData, classes, outsideData) {
function CoreComponent({ rawModelData }) {
const { comment } = rawModelData;
return <Markdown source={comment} />;
}
CoreComponent.propTypes = {
rawModelData: PropTypes.shape({
comment: PropTypes.string
}).isRequired
};
const buildParams = univId =>
RequestParams.Builder.withQueryParam("universities", univId).build();
function UniversityDri({ univId, univDriItems, api }) {
const dispatch = useDispatch();
useEffect(() => {
api.univDriItems.setParams(buildParams(univId));
}, [univId]);
const invalidateData = useCallback(() => {
dispatch(getActions("universityDri").invalidateAll());
});
const outsideData = { universities: UniversityService.getUniversities() };
const invalidateData = useInvalidateAll("universityDri");
return (
<ModuleGroupWrapper
......@@ -52,9 +48,6 @@ function UniversityDri({ univId, univDriItems, api }) {
universities: [univId],
importance_level: "-"
}}
propsForEditor={{
outsideData
}}
>
{univDriItems.map(rawModelData => (
<ModuleWrapper
......@@ -62,9 +55,7 @@ function UniversityDri({ univId, univDriItems, api }) {
buildTitle={modelData => modelData.title}
rawModelData={rawModelData}
editor={UniversityDriEditor}
renderCore={renderCore}
coreClasses={{}}
outsideData={outsideData}
CoreComponent={CoreComponent}
moduleInGroupInfos={{
isInGroup: true,
invalidateGroup: invalidateData
......
......@@ -18,9 +18,9 @@ import withNetworkWrapper, {
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
function renderCore(rawModelData, classes, outsideData) {
function CoreComponent({ rawModelData, cityName, countryName }) {
const { name, acronym, logo, website } = rawModelData;
const { city, country } = outsideData;
return (
<Grid container spacing={2} direction="row">
<Grid
......@@ -53,7 +53,7 @@ function renderCore(rawModelData, classes, outsideData) {
<Typography variant="h6">{acronym}</Typography>
<Divider />
<Typography variant="subtitle1">
{city},&nbsp;{country}
{cityName},&nbsp;{countryName}
</Typography>
<Typography variant="body2">
&nbsp; Site internet&nbsp;: &nbsp;
......@@ -68,6 +68,18 @@ function renderCore(rawModelData, classes, outsideData) {
);
}
CoreComponent.propTypes = {
cityName: PropTypes.string.isRequired,
countryName: PropTypes.string.isRequired,
rawModelData: PropTypes.shape({
comment: PropTypes.string,
name: PropTypes.string.isRequired,
acronym: PropTypes.string,
logo: PropTypes.string,
website: PropTypes.string
}).isRequired
};
const buildParams = univId => RequestParams.Builder.withId(univId).build();
function UniversityGeneral({ univId, university, city, country, api }) {
......@@ -75,18 +87,18 @@ function UniversityGeneral({ univId, university, city, country, api }) {
api.university.setParams(buildParams(univId));
}, [univId]);
const outsideData = {
city: city.name,
country: country.name
};
return (
<ModuleWrapper
buildTitle={() => "Présentation"}
rawModelData={university}
editor={UniversityGeneralEditor}
renderCore={renderCore}
outsideData={outsideData}
CoreComponent={props => (
<CoreComponent
{...props}
cityName={city.name}
countryName={country.name}
/>
)}
/>
);
}
......
import React, { useEffect } from "react";
import PropTypes from "prop-types";
import compose from "recompose/compose";
import { useDispatch } from "react-redux";
import { makeStyles } from "@material-ui/styles";
import ModuleWrapper from "./common/ModuleWrapper";
......@@ -9,15 +8,13 @@ import ModuleGroupWrapper from "./common/ModuleGroupWrapper";
import Scholarship from "./common/Scholarship";
import UniversityScholarshipEditor from "../editors/UniversityScholarshipEditor";
import getActions from "../../../redux/api/getActions";
import RequestParams from "../../../redux/api/RequestParams";
import UniversityService from "../../../services/data/UniversityService";
import CurrencyService from "../../../services/data/CurrencyService";
import withUnivInfo from "../common/withUnivInfo";
import withNetworkWrapper, {
getApiPropTypes,
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
import useInvalidateAll from "../../../hooks/useInvalidateAll";
const useStyles = makeStyles(theme => ({
item: {
......@@ -27,7 +24,7 @@ const useStyles = makeStyles(theme => ({
}));
// eslint-disable-next-line no-unused-vars
function renderCore(rawModelData, classes, outsideData) {
function CoreComponent({ rawModelData }) {
const { comment, frequency, currency, short_description } = rawModelData;
const amountMin = rawModelData.amount_min;
const amountMax = rawModelData.amount_max;
......@@ -46,26 +43,30 @@ function renderCore(rawModelData, classes, outsideData) {
);
}
CoreComponent.propTypes = {
rawModelData: PropTypes.shape({
comment: PropTypes.string,
frequency: PropTypes.string,
currency: PropTypes.number,
short_description: PropTypes.string,
amount_min: PropTypes.number,
amount_max: PropTypes.number,
other_advantages: PropTypes.string
}).isRequired
};
const buildParams = univId =>
RequestParams.Builder.withQueryParam("universities", univId).build();
// TODO bug on save ?
function UniversityScholarships({ univId, api, univScholarshipsItems }) {
const classes = useStyles();
const dispatch = useDispatch();
useEffect(() => {
api.univScholarshipsItems.setParams(buildParams(univId));
}, [univId]);
const invalidateData = useDispatch(() => {
dispatch(getActions("universityScholarships").invalidateAll());
});
const outsideData = {
universities: UniversityService.getUniversities(),
currencies: CurrencyService.getCurrencies()
};
const invalidateData = useInvalidateAll("universityDri");
return (
<ModuleGroupWrapper
......@@ -79,9 +80,6 @@ function UniversityScholarships({ univId, api, univScholarshipsItems }) {
currency: "EUR",
obj_moderation_level: 0
}}
propsForEditor={{
outsideData
}}
>
{univScholarshipsItems.map(rawModelData => (
<div key={rawModelData.id} className={classes.item}>
......@@ -89,9 +87,7 @@ function UniversityScholarships({ univId, api, univScholarshipsItems }) {
buildTitle={modelData => modelData.title}
rawModelData={rawModelData}
editor={UniversityScholarshipEditor}