Skip to content

Commit

Permalink
fix: salary server props
Browse files Browse the repository at this point in the history
  • Loading branch information
2nthony committed Apr 2, 2024
1 parent 46fb70a commit fed8795
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 106 deletions.
39 changes: 39 additions & 0 deletions packages/next-common/services/serverSide/fellowship/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { withCommonProps } from "next-common/lib";
import { fetchOpenGovTracksProps } from "next-common/services/serverSide";
import nextApi from "next-common/services/nextApi";
import {
fellowshipMembersApiUri,
fellowshipParamsApi,
fellowshipSalaryClaimantsApi,
} from "next-common/services/url";
import { merge, noop } from "lodash-es";

export function withFellowshipSalaryCommonProps(fn = noop) {
return withCommonProps(async (context) => {
const [
tracksProps,
{ result: fellowshipMembers },
{ result: fellowshipParams = {} },
{ result: fellowshipSalaryClaimants },
] = await Promise.all([
fetchOpenGovTracksProps(),
nextApi.fetch(fellowshipMembersApiUri),
nextApi.fetch(fellowshipParamsApi),
nextApi.fetch(fellowshipSalaryClaimantsApi),
]);

const res = await fn?.(context);

return merge(
{
props: {
...tracksProps,
fellowshipMembers,
fellowshipParams,
fellowshipSalaryClaimants,
},
},
res,
);
});
}
32 changes: 2 additions & 30 deletions packages/next/pages/fellowship/salary/claimants/index.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import FellowshipSalaryCommon from "next-common/components/fellowship/salary/common";
import FellowshipSalaryClaimantsContainer from "next-common/components/fellowship/salary/claimants/container";
import { withCommonProps } from "next-common/lib";
import { fetchOpenGovTracksProps } from "next-common/services/serverSide";
import nextApi from "next-common/services/nextApi";
import {
fellowshipMembersApiUri,
fellowshipParamsApi,
fellowshipSalaryClaimantsApi,
} from "next-common/services/url";
import { withFellowshipSalaryCommonProps } from "next-common/services/serverSide/fellowship/common";

export default function FellowshipSalaryClaimantsPage() {
return (
Expand All @@ -17,25 +10,4 @@ export default function FellowshipSalaryClaimantsPage() {
);
}

export const getServerSideProps = withCommonProps(async () => {
const [
tracksProps,
{ result: fellowshipMembers },
{ result: fellowshipParams = {} },
{ result: fellowshipSalaryClaimants },
] = await Promise.all([
fetchOpenGovTracksProps(),
nextApi.fetch(fellowshipMembersApiUri),
nextApi.fetch(fellowshipParamsApi),
nextApi.fetch(fellowshipSalaryClaimantsApi),
]);

return {
props: {
...tracksProps,
fellowshipMembers,
fellowshipParams,
fellowshipSalaryClaimants,
},
};
});
export const getServerSideProps = withFellowshipSalaryCommonProps();
97 changes: 47 additions & 50 deletions packages/next/pages/fellowship/salary/cycles/[...params].jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { withCommonProps } from "next-common/lib";
import { fetchOpenGovTracksProps } from "next-common/services/serverSide";
import FellowshipSalaryCycleLayout from "next-common/components/fellowship/salary/cycles/layout";
import FellowshipSalaryCycleDetailTabsList from "next-common/components/fellowship/salary/cycles/tabsList";
import FellowshipSalaryCycleDetailInfo from "next-common/components/fellowship/salary/cycles/info";
Expand All @@ -12,6 +10,7 @@ import {
fellowshipSalaryCycleRegisteredPaymentsApi,
fellowshipSalaryCycleUnregisteredPaymentsApi,
} from "next-common/services/url";
import { withFellowshipSalaryCommonProps } from "next-common/services/serverSide/fellowship/common";

export default function FellowshipSalaryCyclePage({ cycle }) {
return (
Expand All @@ -28,56 +27,54 @@ export default function FellowshipSalaryCyclePage({ cycle }) {
);
}

export const getServerSideProps = withCommonProps(async (context) => {
const {
params: [id],
page,
} = context.query;
export const getServerSideProps = withFellowshipSalaryCommonProps(
async (context) => {
const {
params: [id],
page,
} = context.query;

const [tracksProps, { result: cycle }] = await Promise.all([
fetchOpenGovTracksProps(),
nextApi.fetch(fellowshipSalaryCycleApi(id)),
]);
const { result: cycle } = await nextApi.fetch(fellowshipSalaryCycleApi(id));

let registrations;
let registeredPayments;
let unRegisteredPayments;
let feeds;
let registrations;
let registeredPayments;
let unRegisteredPayments;
let feeds;

if (cycle) {
const [
{ result: registrationsResult },
{ result: registeredPaymentsResult },
{ result: unRegisteredPaymentsResult },
{ result: feedsResult },
] = await Promise.all([
nextApi.fetch(fellowshipSalaryCycleRegistrationsApi(id), { page }),
nextApi.fetch(fellowshipSalaryCycleRegisteredPaymentsApi(id), {
page,
}),
nextApi.fetch(fellowshipSalaryCycleUnregisteredPaymentsApi(id), {
page,
}),
nextApi.fetch(fellowshipSalaryCycleFeedsApi(id), {
page,
}),
]);
if (cycle) {
const [
{ result: registrationsResult },
{ result: registeredPaymentsResult },
{ result: unRegisteredPaymentsResult },
{ result: feedsResult },
] = await Promise.all([
nextApi.fetch(fellowshipSalaryCycleRegistrationsApi(id), { page }),
nextApi.fetch(fellowshipSalaryCycleRegisteredPaymentsApi(id), {
page,
}),
nextApi.fetch(fellowshipSalaryCycleUnregisteredPaymentsApi(id), {
page,
}),
nextApi.fetch(fellowshipSalaryCycleFeedsApi(id), {
page,
}),
]);

registrations = registrationsResult;
registeredPayments = registeredPaymentsResult;
unRegisteredPayments = unRegisteredPaymentsResult;
feeds = feedsResult;
}
registrations = registrationsResult;
registeredPayments = registeredPaymentsResult;
unRegisteredPayments = unRegisteredPaymentsResult;
feeds = feedsResult;
}

return {
props: {
...tracksProps,
id,
cycle: cycle || null,
registrations: registrations || {},
registeredPayments: registeredPayments || {},
unRegisteredPayments: unRegisteredPayments || {},
feeds: feeds || {},
},
};
});
return {
props: {
id,
cycle: cycle || null,
registrations: registrations || {},
registeredPayments: registeredPayments || {},
unRegisteredPayments: unRegisteredPayments || {},
feeds: feeds || {},
},
};
},
);
36 changes: 18 additions & 18 deletions packages/next/pages/fellowship/salary/feeds.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { withCommonProps } from "next-common/lib";
import { fetchOpenGovTracksProps } from "next-common/services/serverSide";
import nextApi from "next-common/services/nextApi";
import { defaultPageSize } from "next-common/utils/constants";
import FellowshipSalaryCommon from "next-common/components/fellowship/salary/common";
import FellowshipSalaryFeedsContainer from "next-common/components/fellowship/salary/feeds/container";
import { withFellowshipSalaryCommonProps } from "next-common/services/serverSide/fellowship/common";

export default function FellowshipSalaryFeedsPage({ fellowshipSalaryFeeds }) {
return (
Expand All @@ -13,21 +12,22 @@ export default function FellowshipSalaryFeedsPage({ fellowshipSalaryFeeds }) {
);
}

export const getServerSideProps = withCommonProps(async (context) => {
const { page = 0 } = context.query;
export const getServerSideProps = withFellowshipSalaryCommonProps(
async (context) => {
const { page = 0 } = context.query;

const [tracksProps, { result: fellowshipSalaryFeeds }] = await Promise.all([
fetchOpenGovTracksProps(),
nextApi.fetch("fellowship/salary/feeds", {
page,
page_size: defaultPageSize,
}),
]);
const { result: fellowshipSalaryFeeds } = await nextApi.fetch(
"fellowship/salary/feeds",
{
page,
page_size: defaultPageSize,
},
);

return {
props: {
...tracksProps,
fellowshipSalaryFeeds,
},
};
});
return {
props: {
fellowshipSalaryFeeds: fellowshipSalaryFeeds || {},
},
};
},
);
13 changes: 5 additions & 8 deletions packages/next/pages/fellowship/salary/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { withCommonProps } from "next-common/lib";
import { fetchOpenGovTracksProps } from "next-common/services/serverSide";
import nextApi from "next-common/services/nextApi";
import FellowshipSalaryCommon from "next-common/components/fellowship/salary/common";
import FellowshipHistoryCyclesSection from "next-common/components/fellowship/salary/cycles/section";
import FellowshipSalaryActiveCycle from "next-common/components/fellowship/salary/cycles/current";
import { withFellowshipSalaryCommonProps } from "next-common/services/serverSide/fellowship/common";

export default function FellowshipSalaryPage() {
return (
Expand All @@ -14,15 +13,13 @@ export default function FellowshipSalaryPage() {
);
}

export const getServerSideProps = withCommonProps(async () => {
const [tracksProps, { result: historyCycles = {} }] = await Promise.all([
fetchOpenGovTracksProps(),
nextApi.fetch("fellowship/salary/history_cycles"),
]);
export const getServerSideProps = withFellowshipSalaryCommonProps(async () => {
const { result: historyCycles = {} } = nextApi.fetch(
"fellowship/salary/history_cycles",
);

return {
props: {
...tracksProps,
historyCycles,
},
};
Expand Down

0 comments on commit fed8795

Please sign in to comment.