Skip to content

Commit

Permalink
MPE: Add FAQ and fix crashing module details fetch (#3261)
Browse files Browse the repository at this point in the history
* Add RO's FAQ link

* Delete crashing module details fetch

* Fuse mpeModules mods into submission so that mpe submisisons have module credits
  • Loading branch information
taneliang authored Mar 3, 2021
1 parent b085737 commit b46cc61
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
29 changes: 4 additions & 25 deletions website/src/apis/mpe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import getLocalStorage from 'storage/localStorage';
import { Location, History } from 'history';
import { produce } from 'immer';
import NUSModsApi from './nusmods';
import { MpeSubmission, MpePreference, MpeModule } from '../types/mpe';
import type { Module, ModuleCode } from '../types/modules';
import { MpeSubmission, MpeModule } from '../types/mpe';
import { NUS_AUTH_TOKEN } from '../storage/keys';

export class MpeSessionExpiredError extends Error {}
Expand Down Expand Up @@ -60,36 +59,16 @@ export const fetchMpeModuleList = (): Promise<MpeModule[]> =>
// TODO: Check with NUS if we should use MPE_AY here instead
axios.get<MpeModule[]>(NUSModsApi.mpeModuleListUrl()).then((resp) => resp.data);

export const fetchModuleDetails = (moduleCode: ModuleCode): Promise<Module> =>
axios.get<Module>(NUSModsApi.moduleDetailsUrl(moduleCode)).then((resp) => resp.data);

export const getSSOLink = (): Promise<string> =>
mpe
.get(SSO_PATH, {
params: { callback: window.location.href },
})
.then((resp) => resp.data);

export const getMpeSubmission = (): Promise<MpeSubmission> => {
let submission: MpeSubmission;
return mpe
.get<MpeSubmission>(MPE_PATH)
.then((resp) => {
submission = resp.data;
return Promise.all<Module>(
submission.preferences.map((p) => fetchModuleDetails(p.moduleCode)),
);
})
.then((modules) => ({
...submission,
preferences: modules.map<MpePreference>((m, index) => ({
moduleTitle: m.title,
moduleCode: m.moduleCode,
moduleType: submission.preferences[index].moduleType,
moduleCredits: parseInt(m.moduleCredit, 10),
})),
}));
};
// TODO: Replace data fetched from MPE server with latest data from MPE module list
export const getMpeSubmission = (): Promise<MpeSubmission> =>
mpe.get<MpeSubmission>(MPE_PATH).then((resp) => resp.data);

export const updateMpeSubmission = (submission: MpeSubmission): Promise<void> => {
if (submission.intendedMCs < 0) {
Expand Down
8 changes: 8 additions & 0 deletions website/src/views/mpe/MpeContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classnames from 'classnames';
import { enableMpe } from 'featureFlags';
import Modal from 'views/components/Modal';
import type { MpeSubmission } from 'types/mpe';
import ExternalLink from 'views/components/ExternalLink';
import {
getLoginState,
getSSOLink,
Expand Down Expand Up @@ -85,6 +86,13 @@ const MpeContainer: React.FC = () => {
the ModReg Exercise, in cases where the demand exceeds the available quota and students
have the same Priority Score for a particular module.
</p>
<p>
For further questions, please refer to this{' '}
<ExternalLink href="https://www.nus.edu.sg/registrar/docs/info/mpe/MPE-FAQs.pdf">
FAQ
</ExternalLink>{' '}
provided by NUS Registrar's Office.
</p>
<div>
{isLoggedIn ? (
<MpeFormContainer getSubmission={getSubmission} updateSubmission={updateSubmission} />
Expand Down
22 changes: 19 additions & 3 deletions website/src/views/mpe/form/MpeFormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,25 @@ const MpeFormContainer: React.FC<Props> = ({ getSubmission, updateSubmission })
setIsInitialLoad(true);

Promise.all([fetchMpeModuleList(), getSubmission()])
.then((data) => {
setMpeModuleList(data[0]);
setSubmission(data[1]);
.then(([fetchedMpeModuleList, fetchedSubmission]) => {
setMpeModuleList(fetchedMpeModuleList);
setSubmission({
...fetchedSubmission,
// Replace data fetched from MPE server with latest data from MPE module list
// TODO: Optimize. This does an linear time lookup for each preference
preferences: fetchedSubmission.preferences.map((preference) => {
const mpeModule = fetchedMpeModuleList.find(
(m) => m.moduleCode === preference.moduleCode,
);
if (!mpeModule) return preference;
return {
...preference,
moduleTitle: mpeModule.title,
moduleCode: mpeModule.moduleCode,
moduleCredits: parseInt(mpeModule.moduleCredit, 10),
};
}),
});
})
.catch((err) => {
// this is a temporary fix
Expand Down

2 comments on commit b46cc61

@vercel
Copy link

@vercel vercel bot commented on b46cc61 Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on b46cc61 Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.