Pre papulate country in registration form (#251)

- get country code based on IP address from server
- set country code in country field

VAN-366
This commit is contained in:
Mubbshar Anwar
2021-04-23 20:08:50 +05:00
committed by Waheed Ahmed
parent 296f4e07ce
commit bd470f892c
3 changed files with 43 additions and 1 deletions

View File

@@ -11,7 +11,7 @@ export async function getThirdPartyAuthContext(urlParams) {
const { data } = await getAuthenticatedHttpClient()
.get(
`${getConfig().LMS_BASE_URL}/api/third_party_auth_context`,
`${getConfig().LMS_BASE_URL}/api/mfe_context`,
requestConfig,
)
.catch((e) => {

View File

@@ -128,6 +128,14 @@ class RegistrationPage extends React.Component {
return false;
}
if (this.props.thirdPartyAuthContext.countryCode
&& this.state.country !== nextProps.thirdPartyAuthContext.countryCode) {
this.setState({
country: nextProps.thirdPartyAuthContext.countryCode || '',
});
return false;
}
return true;
}
@@ -657,6 +665,7 @@ RegistrationPage.defaultProps = {
thirdPartyAuthContext: {
currentProvider: null,
finishAuthUrl: null,
countryCode: null,
providers: [],
secondaryProviders: [],
pipelineUserDetails: null,
@@ -688,6 +697,7 @@ RegistrationPage.propTypes = {
providers: PropTypes.array,
secondaryProviders: PropTypes.array,
finishAuthUrl: PropTypes.string,
countryCode: PropTypes.string,
pipelineUserDetails: PropTypes.shape({
email: PropTypes.string,
fullname: PropTypes.string,

View File

@@ -55,6 +55,7 @@ describe('RegistrationPage', () => {
providers: [],
secondaryProviders: [],
pipelineUserDetails: null,
countryCode: null,
},
},
};
@@ -671,6 +672,37 @@ describe('RegistrationPage', () => {
registerPage.find('button.username-suggestion').at(0).simulate('click');
expect(registerPage.find('RegistrationPage').state('username')).toEqual('test_1');
});
it('Should update state if countryCode is present in context', () => {
store = mockStore({
...initialState,
commonComponents: {
...initialState.commonComponents,
thirdPartyAuthContext: {
...initialState.commonComponents.thirdPartyAuthContext,
countryCode: 'US',
},
thirdPartyAuthApiStatus: COMPLETE_STATE,
},
});
const nextProps = {
validations: null,
thirdPartyAuthContext: {
pipelineUserDetails: {
name: 'test',
email: 'test@example.com',
username: 'test-username',
},
countryCode: 'US',
},
};
const registrationPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
const shouldUpdate = registrationPage.find('RegistrationPage').instance().shouldComponentUpdate(nextProps);
expect(registrationPage.find('RegistrationPage').state('country')).toEqual('US');
expect(shouldUpdate).toBe(false);
});
});
describe('TestOptionalFields', () => {