From 5fa1d40dbf097daa560c24aa3a50689e51db0f94 Mon Sep 17 00:00:00 2001 From: Zainab Amir Date: Mon, 4 Jan 2021 18:42:52 +0500 Subject: [PATCH] Populate registration page fields (#66) When registering via SSO, populate registration fields with user data acquired from the social auth pipeline. VAN-238 --- src/logistration/RegistrationPage.jsx | 7 +++++++ src/logistration/data/service.js | 4 ++-- .../tests/RegistrationPage.test.jsx | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/logistration/RegistrationPage.jsx b/src/logistration/RegistrationPage.jsx index 3cc472e7..1b818227 100644 --- a/src/logistration/RegistrationPage.jsx +++ b/src/logistration/RegistrationPage.jsx @@ -125,6 +125,12 @@ class RegistrationPage extends React.Component { }); return false; } + if (this.props.thirdPartyAuthContext.pipelineUserDetails !== nextProps.thirdPartyAuthContext.pipelineUserDetails) { + this.setState({ + ...nextProps.thirdPartyAuthContext.pipelineUserDetails, + }); + return false; + } return true; } @@ -595,6 +601,7 @@ RegistrationPage.defaultProps = { finishAuthUrl: null, providers: [], secondaryProviders: [], + pipelineUserDetails: null, }, formData: null, validations: null, diff --git a/src/logistration/data/service.js b/src/logistration/data/service.js index ab0fb99c..5ab0279f 100644 --- a/src/logistration/data/service.js +++ b/src/logistration/data/service.js @@ -1,4 +1,4 @@ -import { camelCaseObject, getConfig } from '@edx/frontend-platform'; +import { camelCaseObject, convertKeyNames, getConfig } from '@edx/frontend-platform'; import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; import querystring from 'querystring'; @@ -62,7 +62,7 @@ export async function getThirdPartyAuthContext(urlParams) { throw (e); }); return { - thirdPartyAuthContext: camelCaseObject(data), + thirdPartyAuthContext: camelCaseObject(convertKeyNames(data, { fullname: 'name' })), }; } diff --git a/src/logistration/tests/RegistrationPage.test.jsx b/src/logistration/tests/RegistrationPage.test.jsx index d13b8af0..95714f6c 100644 --- a/src/logistration/tests/RegistrationPage.test.jsx +++ b/src/logistration/tests/RegistrationPage.test.jsx @@ -272,6 +272,24 @@ describe('./RegistrationPage.js', () => { expect(tree).toMatchSnapshot(); }); + it('tests shouldComponentUpdate with pipeline user data', () => { + const nextProps = { + validations: null, + thirdPartyAuthContext: { + pipelineUserDetails: { + name: 'test', + email: 'test@example.com', + username: 'test-username', + }, + }, + }; + + const root = mount(reduxWrapper()); + + const shouldUpdate = root.find('RegistrationPage').instance().shouldComponentUpdate(nextProps); + expect(shouldUpdate).toBe(false); + }); + it('should match url after redirection', () => { const dasboardUrl = 'http://test.com/testing-dashboard/'; store = mockStore({