Verified Commit 81886f4f authored by Florent Chehab's avatar Florent Chehab
Browse files

refactor(frontend): moved buildParams

parent e7ca842c
......@@ -64,11 +64,6 @@ VersionInfo.propTypes = {
editFromVersion: PropTypes.func.isRequired
};
const buildParams = modelInfo => {
const { contentTypeId, id } = modelInfo;
return RequestParams.Builder.withEndPointAttrs([contentTypeId, id]).build();
};
function History({
versions,
renderTitle,
......@@ -149,6 +144,11 @@ History.propTypes = {
rawModelDataEx: PropTypes.object.isRequired
};
const buildParams = modelInfo => {
const { contentTypeId, id } = modelInfo;
return RequestParams.Builder.withEndPointAttrs([contentTypeId, id]).build();
};
export default compose(
withNetworkWrapper([
new NetWrapParam("versions", "all", {
......
......@@ -60,11 +60,6 @@ PendingModerationInfo.propTypes = {
editFromPending: PropTypes.func.isRequired
};
const buildParams = modelInfo => {
const { contentTypeId, id } = modelInfo;
return RequestParams.Builder.withEndPointAttrs([contentTypeId, id]).build();
};
function PendingModeration({
pendingModeration,
editFromPendingModeration,
......@@ -124,6 +119,11 @@ PendingModeration.propTypes = {
renderCore: PropTypes.func.isRequired
};
const buildParams = modelInfo => {
const { contentTypeId, id } = modelInfo;
return RequestParams.Builder.withEndPointAttrs([contentTypeId, id]).build();
};
export default compose(
withNetworkWrapper([
new NetWrapParam("pendingModerationObj", "all", {
......
......@@ -27,9 +27,6 @@ const useStyles = makeStyles(theme => ({
}
}));
const buildParams = match =>
RequestParams.Builder.withId(getExchangeId(match)).build();
/**
* Page that handle the modification of exchange feedbacks.
*/
......@@ -85,6 +82,9 @@ PageEditExchangeFeedbacks.propTypes = {
exchange: PropTypes.object.isRequired
};
const buildParams = match =>
RequestParams.Builder.withId(getExchangeId(match)).build();
export default compose(
withNetworkWrapper([
new NetWrapParam("exchanges", "one", {
......
......@@ -16,18 +16,6 @@ function getUserIdFromUrl(match) {
return match.params.userId;
}
const buildPictureParams = match =>
RequestParams.Builder.withQueryParam(
"owner",
getUserIdFromUrl(match)
).build();
const buildFilesParams = match =>
RequestParams.Builder.withQueryParam(
"owner",
getUserIdFromUrl(match)
).build();
/**
* WARNING BETA files & padding
* Page that lists the files available
......@@ -59,6 +47,18 @@ PageFiles.propTypes = {
files: PropTypes.array.isRequired
};
const buildPictureParams = match =>
RequestParams.Builder.withQueryParam(
"owner",
getUserIdFromUrl(match)
).build();
const buildFilesParams = match =>
RequestParams.Builder.withQueryParam(
"owner",
getUserIdFromUrl(match)
).build();
export default compose(
withNetworkWrapper([
new NetWrapParam("pictures", "all", {
......
......@@ -8,8 +8,6 @@ import List from "./view/View";
import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper";
import NavigationService from "../../services/NavigationService";
const buildParams = listId => RequestParams.Builder.withId(listId).build();
/**
* Component to display one recommendation list
*/
......@@ -28,6 +26,8 @@ ViewListSubPage.propTypes = {
list: PropTypes.object.isRequired
};
const buildParams = listId => RequestParams.Builder.withId(listId).build();
export default compose(
withNetworkWrapper([
new NetWrapParam("recommendationLists", "one", {
......
......@@ -29,9 +29,6 @@ CoreComponent.defaultProps = {
rawModelData: { comment: "" }
};
const buildParams = countryId =>
RequestParams.Builder.withQueryParam("countries", countryId).build();
function CountryDri({ countryId, countryDriItems }) {
const defaultModelData = useMemo(
() => ({
......@@ -65,6 +62,9 @@ CountryDri.propTypes = {
countryDriItems: PropTypes.array.isRequired
};
const buildParams = countryId =>
RequestParams.Builder.withQueryParam("countries", countryId).build();
export default compose(
withUnivInfo(["countryId"]),
withNetworkWrapper([
......
......@@ -24,9 +24,6 @@ const useStyles = makeStyles(theme => ({
}
}));
const buildParams = countryId =>
RequestParams.Builder.withQueryParam("countries", countryId).build();
function CountryScholarships({ countryScholarshipsItems, countryId, country }) {
const classes = useStyles();
......@@ -64,6 +61,9 @@ CountryScholarships.propTypes = {
countryScholarshipsItems: PropTypes.array.isRequired
};
const buildParams = countryId =>
RequestParams.Builder.withQueryParam("countries", countryId).build();
export default compose(
withUnivInfo(["countryId", "country"]),
withNetworkWrapper([
......
......@@ -21,9 +21,6 @@ CoreComponent.propTypes = {
}).isRequired
};
const buildParams = univId =>
RequestParams.Builder.withQueryParam("university", univId).build();
function SharedUnivFeedback({ feedback }) {
return (
<ModuleWrapper
......@@ -41,6 +38,9 @@ SharedUnivFeedback.propTypes = {
feedback: PropTypes.array.isRequired
};
const buildParams = univId =>
RequestParams.Builder.withQueryParam("university", univId).build();
export default compose(
withUnivInfo(),
withNetworkWrapper([
......
......@@ -26,9 +26,6 @@ CoreComponent.propTypes = {
}).isRequired
};
const buildParams = univId =>
RequestParams.Builder.withQueryParam("universities", univId).build();
function UniversityDri({ univId, univDriItems }) {
const defaultModelData = useMemo(
() => ({
......@@ -62,6 +59,9 @@ UniversityDri.propTypes = {
univDriItems: PropTypes.array.isRequired
};
const buildParams = univId =>
RequestParams.Builder.withQueryParam("universities", univId).build();
export default compose(
withUnivInfo(["countryId"]),
withNetworkWrapper([
......
......@@ -79,8 +79,6 @@ CoreComponent.propTypes = {
}).isRequired
};
const buildParams = univId => RequestParams.Builder.withId(univId).build();
function UniversityGeneral({ university, city, country }) {
return (
<ModuleWrapper
......@@ -104,6 +102,8 @@ UniversityGeneral.propTypes = {
university: PropTypes.object.isRequired
};
const buildParams = univId => RequestParams.Builder.withId(univId).build();
export default compose(
withUnivInfo(["city", "country"]),
withNetworkWrapper([
......
......@@ -142,12 +142,6 @@ function renderEl(dataEl) {
return <Item key={p.id} {...p} />;
}
const buildParams = (univId, page) =>
RequestParams.Builder.withQueryParam("university", univId)
.withQueryParam("page", page)
.withQueryParam("page_size", 3)
.build();
function UniversityOffers({ offers, goToPage }) {
const classes = useStyles();
......@@ -183,6 +177,12 @@ UniversityOffers.propTypes = {
goToPage: PropTypes.func.isRequired
};
const buildParams = (univId, page) =>
RequestParams.Builder.withQueryParam("university", univId)
.withQueryParam("page", page)
.withQueryParam("page_size", 3)
.build();
const ConnectedComponent = compose(
withUnivInfo(),
withNetworkWrapper([
......
......@@ -23,9 +23,6 @@ const useStyles = makeStyles(theme => ({
}
}));
const buildParams = univId =>
RequestParams.Builder.withQueryParam("universities", univId).build();
function UniversityScholarships({ univId, univScholarshipsItems }) {
const classes = useStyles();
......@@ -62,6 +59,9 @@ UniversityScholarships.propTypes = {
univScholarshipsItems: PropTypes.array.isRequired
};
const buildParams = univId =>
RequestParams.Builder.withQueryParam("universities", univId).build();
export default compose(
withUnivInfo(),
withNetworkWrapper([
......
......@@ -123,8 +123,6 @@ CoreComponent.propTypes = {
}).isRequired
};
const buildParams = univId => RequestParams.Builder.withId(univId).build();
function UniversitySemestersDates({ semestersDates }) {
return (
<ModuleWrapper
......@@ -140,6 +138,8 @@ UniversitySemestersDates.propTypes = {
semestersDates: PropTypes.object.isRequired
};
const buildParams = univId => RequestParams.Builder.withId(univId).build();
export default compose(
withUnivInfo(),
withNetworkWrapper([
......
......@@ -53,9 +53,6 @@ const useStyles = makeStyles(theme => ({
}
}));
const buildParams = exchangeId =>
RequestParams.Builder.withQueryParam("course__exchange", exchangeId).build();
function EditModuleCoursesFeedback({ courseFeedbacks }) {
const classes = useStyles();
......@@ -124,6 +121,9 @@ EditModuleCoursesFeedback.propTypes = {
courseFeedbacks: PropTypes.array.isRequired
};
const buildParams = exchangeId =>
RequestParams.Builder.withQueryParam("course__exchange", exchangeId).build();
export default compose(
withNetworkWrapper([
new NetWrapParam("courseFeedbacks", "all", {
......
......@@ -39,9 +39,6 @@ CoreComponent.propTypes = {
}).isRequired
};
const buildParams = exchangeId =>
RequestParams.Builder.withId(exchangeId).build();
function EditModuleGeneralFeedback({ generalFeedback }) {
return (
<ModuleWrapper
......@@ -57,6 +54,9 @@ EditModuleGeneralFeedback.propTypes = {
generalFeedback: PropTypes.object.isRequired
};
const buildParams = exchangeId =>
RequestParams.Builder.withId(exchangeId).build();
export default compose(
withNetworkWrapper([
new NetWrapParam("exchangeFeedbacks", "one", {
......
......@@ -30,26 +30,6 @@ const useStyles = makeStyles(theme => ({
}
}));
const buildExchangesParams = (
univId,
page = 1,
major = undefinedVal,
minor = undefinedVal
) => {
const params = RequestParams.Builder.withQueryParam("university", univId)
.withQueryParam("page_size", 8)
.withQueryParam("page", page);
if (typeof major !== "undefined" && major !== undefinedVal)
params.withQueryParam("exchange__student_major", major);
if (typeof minor !== "undefined" && minor !== undefinedVal)
params.withQueryParam("exchange__student_minor", minor);
return params.build();
};
const buildUnivMajorMinorsParams = univId =>
RequestParams.Builder.withQueryParam("university", univId).build();
/**
* Tab on the university page containing information related to previous exchange
*/
......@@ -159,6 +139,26 @@ PreviousExchangesTab.propTypes = {
setMajor: PropTypes.func.isRequired
};
const buildExchangesParams = (
univId,
page = 1,
major = undefinedVal,
minor = undefinedVal
) => {
const params = RequestParams.Builder.withQueryParam("university", univId)
.withQueryParam("page_size", 8)
.withQueryParam("page", page);
if (typeof major !== "undefined" && major !== undefinedVal)
params.withQueryParam("exchange__student_major", major);
if (typeof minor !== "undefined" && minor !== undefinedVal)
params.withQueryParam("exchange__student_minor", minor);
return params.build();
};
const buildUnivMajorMinorsParams = univId =>
RequestParams.Builder.withQueryParam("university", univId).build();
const ConnectedComp = compose(
withUnivInfo(),
withNetworkWrapper([
......
......@@ -46,11 +46,6 @@ const useStyles = makeStyles(theme => ({
}
}));
const buildParamsCountryTI = countryId =>
RequestParams.Builder.withQueryParam("country", countryId).build();
const buildParamsUniversityTI = univId =>
RequestParams.Builder.withQueryParam("university", univId).build();
/**
* Tab containing tips and tricks about the university and the country
*
......@@ -128,6 +123,12 @@ TipsAndTricksTab.propTypes = {
universityTI: PropTypes.array.isRequired
};
const buildParamsCountryTI = countryId =>
RequestParams.Builder.withQueryParam("country", countryId).build();
const buildParamsUniversityTI = univId =>
RequestParams.Builder.withQueryParam("university", univId).build();
export default compose(
withUnivInfo(["countryId", "univId", "country", "univ"]),
withNetworkWrapper([
......
......@@ -71,8 +71,6 @@ const useStyles = makeStyles(theme => ({
}
}));
const buildParams = userId => RequestParams.Builder.withId(userId).build();
/**
* Component used to display the user information
*/
......@@ -220,6 +218,8 @@ UserInfo.propTypes = {
user: PropTypes.object.isRequired
};
const buildParams = userId => RequestParams.Builder.withId(userId).build();
export default withNetworkWrapper([
new NetWrapParam("users", "one", {
propKey: "user",
......
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