Commit 588198cc authored by Florent Chehab's avatar Florent Chehab

useInvalidateAll created and used

parent fa829e0b
Pipeline #45270 passed with stages
in 3 minutes and 45 seconds
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,13 +8,13 @@ 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 withNetworkWrapper, {
getApiPropTypes,
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
import useInvalidateAll from "../../../hooks/useInvalidateAll";
function CoreComponent({ rawModelData }) {
const { comment } = rawModelData;
......@@ -36,15 +35,11 @@ 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 invalidateData = useInvalidateAll("countryDri");
return (
<ModuleGroupWrapper
......
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,14 +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 withNetworkWrapper, {
getApiPropTypes,
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
import useInvalidateAll from "../../../hooks/useInvalidateAll";
const useStyles = makeStyles(theme => ({
item: {
......@@ -73,15 +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 invalidateData = useInvalidateAll("countryScholarships");
return (
<ModuleGroupWrapper
......
......@@ -30,7 +30,7 @@ const buildParams = univId =>
RequestParams.Builder.withQueryParam("university", univId).build();
function SharedUnivFeedback({ univId, api, feedback }) {
const dispatch = useDispatch(); // TODO use invalidate all
const dispatch = useDispatch();
useEffect(() => {
api.feedback.setParams(buildParams(univId));
......
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,14 +8,13 @@ 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 withNetworkWrapper, {
getApiPropTypes,
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
import withUnivInfo from "../common/withUnivInfo";
import useInvalidateAll from "../../../hooks/useInvalidateAll";
function CoreComponent({ rawModelData }) {
const { comment } = rawModelData;
......@@ -34,15 +32,11 @@ 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 invalidateData = useInvalidateAll("universityDri");
return (
<ModuleGroupWrapper
......
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,13 +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 withUnivInfo from "../common/withUnivInfo";
import withNetworkWrapper, {
getApiPropTypes,
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
import useInvalidateAll from "../../../hooks/useInvalidateAll";
const useStyles = makeStyles(theme => ({
item: {
......@@ -62,15 +61,12 @@ const buildParams = univId =>
// 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 invalidateData = useInvalidateAll("universityDri");
return (
<ModuleGroupWrapper
......
......@@ -173,7 +173,7 @@ Scholarship.propTypes = {
currency: PropTypes.string,
frequency: PropTypes.string,
shortDescription: PropTypes.string.isRequired,
comment: PropTypes.string,
comment: PropTypes.string.isRequired,
otherAdvantages: PropTypes.string,
amountMin: PropTypes.string,
amountMax: PropTypes.string
......
import { useDispatch } from "react-redux";
import { useCallback, useMemo } from "react";
import getActions from "../redux/api/getActions";
/**
* Hook that can be used to invalidate api data from "all"
*
* @param {string} routes
* @returns {Function}
*/
function useInvalidateAll(...routes) {
const dispatch = useDispatch();
const invalidateData = useCallback(() => {
routes.forEach(route => {
dispatch(getActions(route).invalidateAll());
});
}, [dispatch]);
return useMemo(() => invalidateData, [invalidateData]);
}
export default useInvalidateAll;
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