-
-
{intl.formatMessage(messages['progressive.profiling.page.heading'])}
-
-
- {showError ? (
-
- {intl.formatMessage(messages['welcome.page.error.heading'])}
- {intl.formatMessage(messages['welcome.page.error.message'])}
-
- ) : null}
-
+ return (
+ <>
+
+
+ {intl.formatMessage(messages['progressive.profiling.page.title'],
+ { siteName: getConfig().SITE_NAME })}
+
+
+
+ {props.shouldRedirect ? (
+
+ ) : null}
+
+
+
{intl.formatMessage(messages['progressive.profiling.page.heading'])}
-
- >
- );
- }
- return
;
+
+ {showError ? (
+
+ {intl.formatMessage(messages['welcome.page.error.heading'])}
+ {intl.formatMessage(messages['welcome.page.error.message'])}
+
+ ) : null}
+
+
+
+ >
+ );
};
ProgressiveProfiling.propTypes = {
+ // eslint-disable-next-line react/no-unused-prop-types
extendedProfile: PropTypes.arrayOf(PropTypes.string),
- fieldDescriptions: PropTypes.shape({}),
+ optionalFields: PropTypes.shape({}),
formRenderState: PropTypes.string.isRequired,
intl: intlShape.isRequired,
location: PropTypes.shape({
state: PropTypes.object,
}),
- getFieldData: PropTypes.func.isRequired,
saveUserProfile: PropTypes.func.isRequired,
showError: PropTypes.bool,
shouldRedirect: PropTypes.bool,
@@ -212,7 +208,7 @@ ProgressiveProfiling.propTypes = {
ProgressiveProfiling.defaultProps = {
extendedProfile: [],
- fieldDescriptions: {},
+ optionalFields: {},
location: { state: {} },
shouldRedirect: false,
showError: false,
@@ -220,8 +216,6 @@ ProgressiveProfiling.defaultProps = {
};
const mapStateToProps = state => ({
- extendedProfile: welcomePageSelector(state).extendedProfile,
- fieldDescriptions: welcomePageSelector(state).fieldDescriptions,
formRenderState: welcomePageSelector(state).formRenderState,
shouldRedirect: welcomePageSelector(state).success,
submitState: welcomePageSelector(state).submitState,
@@ -232,6 +226,5 @@ export default connect(
mapStateToProps,
{
saveUserProfile,
- getFieldData,
},
)(injectIntl(ProgressiveProfiling));
diff --git a/src/welcome/data/actions.js b/src/welcome/data/actions.js
index 917cdf3a..6527c9d0 100644
--- a/src/welcome/data/actions.js
+++ b/src/welcome/data/actions.js
@@ -20,21 +20,3 @@ export const saveUserProfileSuccess = () => ({
export const saveUserProfileFailure = () => ({
type: SAVE_USER_PROFILE.FAILURE,
});
-
-// get field data from platform
-export const getFieldData = () => ({
- type: GET_FIELDS_DATA.BASE,
-});
-
-export const getFieldDataBegin = () => ({
- type: GET_FIELDS_DATA.BEGIN,
-});
-
-export const getFieldDataSuccess = (data, extendedProfile) => ({
- type: GET_FIELDS_DATA.SUCCESS,
- payload: { data, extendedProfile },
-});
-
-export const getFieldDataFailure = () => ({
- type: GET_FIELDS_DATA.FAILURE,
-});
diff --git a/src/welcome/data/reducers.js b/src/welcome/data/reducers.js
index b5762cd1..493a9672 100644
--- a/src/welcome/data/reducers.js
+++ b/src/welcome/data/reducers.js
@@ -1,6 +1,6 @@
-import { GET_FIELDS_DATA, SAVE_USER_PROFILE } from './actions';
+import { SAVE_USER_PROFILE } from './actions';
import {
- DEFAULT_STATE, PENDING_STATE, COMPLETE_STATE, FAILURE_STATE,
+ DEFAULT_STATE, PENDING_STATE,
} from '../../data/constants';
export const defaultState = {
@@ -14,23 +14,6 @@ export const defaultState = {
const reducer = (state = defaultState, action) => {
switch (action.type) {
- case GET_FIELDS_DATA.BEGIN:
- return {
- ...state,
- formRenderState: PENDING_STATE,
- };
- case GET_FIELDS_DATA.SUCCESS:
- return {
- ...state,
- extendedProfile: action.payload.extendedProfile,
- fieldDescriptions: action.payload.data,
- formRenderState: COMPLETE_STATE,
- };
- case GET_FIELDS_DATA.FAILURE:
- return {
- ...state,
- formRenderState: FAILURE_STATE,
- };
case SAVE_USER_PROFILE.BEGIN:
return {
...state,
diff --git a/src/welcome/data/sagas.js b/src/welcome/data/sagas.js
index 4e100873..224c50ed 100644
--- a/src/welcome/data/sagas.js
+++ b/src/welcome/data/sagas.js
@@ -1,17 +1,13 @@
import { call, put, takeEvery } from 'redux-saga/effects';
import {
- GET_FIELDS_DATA,
- getFieldDataBegin,
- getFieldDataFailure,
- getFieldDataSuccess,
SAVE_USER_PROFILE,
saveUserProfileBegin,
saveUserProfileFailure,
saveUserProfileSuccess,
} from './actions';
-import { patchAccount, getOptionalFieldData } from './service';
+import { patchAccount } from './service';
export function* saveUserProfileInformation(action) {
try {
@@ -24,17 +20,6 @@ export function* saveUserProfileInformation(action) {
}
}
-export function* getFieldData() {
- try {
- yield put(getFieldDataBegin());
- const data = yield call(getOptionalFieldData);
- yield put(getFieldDataSuccess(data.fields, data.extended_profile));
- } catch (e) {
- yield put(getFieldDataFailure());
- }
-}
-
export default function* saga() {
yield takeEvery(SAVE_USER_PROFILE.BASE, saveUserProfileInformation);
- yield takeEvery(GET_FIELDS_DATA.BASE, getFieldData);
}
diff --git a/src/welcome/data/service.js b/src/welcome/data/service.js
index a7b5246d..6145f779 100644
--- a/src/welcome/data/service.js
+++ b/src/welcome/data/service.js
@@ -1,6 +1,7 @@
import { getConfig } from '@edx/frontend-platform';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
+// eslint-disable-next-line import/prefer-default-export
export async function patchAccount(username, commitValues) {
const requestConfig = {
headers: { 'Content-Type': 'application/merge-patch+json' },
@@ -16,20 +17,3 @@ export async function patchAccount(username, commitValues) {
throw (error);
});
}
-
-export async function getOptionalFieldData() {
- const requestConfig = {
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
- };
-
- const { data } = await getAuthenticatedHttpClient()
- .get(
- `${getConfig().LMS_BASE_URL}/api/optional_fields`,
- requestConfig,
- )
- .catch((e) => {
- throw (e);
- });
-
- return data;
-}
diff --git a/src/welcome/tests/ProgressiveProfiling.test.jsx b/src/welcome/tests/ProgressiveProfiling.test.jsx
index 66a64143..08875b01 100644
--- a/src/welcome/tests/ProgressiveProfiling.test.jsx
+++ b/src/welcome/tests/ProgressiveProfiling.test.jsx
@@ -11,10 +11,10 @@ import * as auth from '@edx/frontend-platform/auth';
import * as logging from '@edx/frontend-platform/logging';
import { injectIntl, IntlProvider, configure } from '@edx/frontend-platform/i18n';
-import { getFieldData, saveUserProfile } from '../data/actions';
+import { saveUserProfile } from '../data/actions';
import ProgressiveProfiling from '../ProgressiveProfiling';
import {
- COMPLETE_STATE, DEFAULT_REDIRECT_URL, FAILURE_STATE, PENDING_STATE,
+ COMPLETE_STATE, DEFAULT_REDIRECT_URL, FAILURE_STATE,
} from '../../data/constants';
const IntlProgressiveProfilingPage = injectIntl(ProgressiveProfiling);
@@ -36,8 +36,18 @@ describe('ProgressiveProfilingTests', () => {
mergeConfig({
WELCOME_PAGE_SUPPORT_LINK: 'http://localhost:1999/welcome',
});
-
- const registrationResult = { redirectUrl: 'http://localhost:18000/dashboard', success: true };
+ const registrationResult = { redirectUrl: getConfig().LMS_BASE_URL + DEFAULT_REDIRECT_URL, success: true };
+ const fields = {
+ company: { name: 'company', type: 'text', label: 'Company' },
+ gender: {
+ name: 'gender',
+ type: 'select',
+ label: 'Gender',
+ options: [['m', 'Male'], ['f', 'Female'], ['o', 'Other/Prefer Not to Say']],
+ },
+ };
+ const extendedProfile = ['company'];
+ const optionalFields = { fields, extended_profile: extendedProfile };
let props = {};
let store = {};
const DASHBOARD_URL = getConfig().LMS_BASE_URL.concat(DEFAULT_REDIRECT_URL);
@@ -79,43 +89,13 @@ describe('ProgressiveProfilingTests', () => {
location: {
state: {
registrationResult,
+ optionalFields,
},
},
};
});
- it('should fire action to get form fields', async () => {
- store.dispatch = jest.fn(store.dispatch);
- const progressiveProfilingPage = await getProgressiveProfilingPage();
-
- progressiveProfilingPage.find('button.btn-link').simulate('click');
- expect(store.dispatch).toHaveBeenCalledWith(getFieldData());
- });
-
- it('should show spinner until fields are fetched', async () => {
- store = mockStore({
- welcomePage: {
- formRenderState: PENDING_STATE,
- },
- });
- const progressiveProfilingPage = await getProgressiveProfilingPage();
- expect(progressiveProfilingPage.find('#loader').exists()).toBeTruthy();
- });
-
it('should render fields returned by backend api', async () => {
- store = mockStore({
- welcomePage: {
- ...initialState.welcomePage,
- fieldDescriptions: {
- gender: {
- name: 'gender',
- type: 'select',
- label: 'Gender',
- options: [['m', 'Male'], ['f', 'Female'], ['o', 'Other/Prefer Not to Say']],
- },
- },
- },
- });
const progressiveProfilingPage = await getProgressiveProfilingPage();
expect(progressiveProfilingPage.find('#gender').exists()).toBeTruthy();
});
@@ -126,27 +106,7 @@ describe('ProgressiveProfilingTests', () => {
gender: 'm',
extended_profile: [{ field_name: 'company', field_value: 'edx' }],
};
- store = mockStore({
- welcomePage: {
- ...initialState.welcomePage,
- extendedProfile: ['company'],
- fieldDescriptions: {
- gender: {
- name: 'gender',
- type: 'select',
- label: 'Gender',
- options: [['m', 'Male'], ['f', 'Female'], ['o', 'Other/Prefer Not to Say']],
- },
- company: {
- name: 'company',
- type: 'text',
- label: 'Company',
- },
- },
- },
- });
store.dispatch = jest.fn(store.dispatch);
-
const progressiveProfilingPage = await getProgressiveProfilingPage();
progressiveProfilingPage.find('select#gender').simulate('change', { target: { value: 'm', name: 'gender' } });
progressiveProfilingPage.find('input#company').simulate('change', { target: { value: 'edx', name: 'company' } });