From 1b6612ce5e4ba877d7e7dbd16bfd5ea1acba9793 Mon Sep 17 00:00:00 2001 From: eemaanamir Date: Wed, 13 Nov 2024 15:09:23 +0500 Subject: [PATCH] refactor: refactored code according to requested changes --- src/index.jsx | 17 +++++++++-------- src/routes/AppRoutes.jsx | 29 +++++++++++++++++++---------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/index.jsx b/src/index.jsx index af9ce1581..c754a1e77 100755 --- a/src/index.jsx +++ b/src/index.jsx @@ -7,6 +7,7 @@ import { initialize, mergeConfig, subscribe, + getConfig, } from '@edx/frontend-platform'; import { AppProvider, @@ -26,19 +27,19 @@ import Head from './head/Head'; import AppRoutes from './routes/AppRoutes'; -if (process.env.ENABLE_NEW_PROFILE_VIEW === 'true') { - import('./index-v2.scss'); -} else { - import('./index.scss'); -} - -subscribe(APP_READY, () => { +subscribe(APP_READY, async () => { + const isNewProfileEnabled = getConfig().ENABLE_NEW_PROFILE_VIEW === 'true'; + if (isNewProfileEnabled) { + await import('./index-v2.scss'); + } else { + await import('./index.scss'); + } ReactDOM.render(
- +
, diff --git a/src/routes/AppRoutes.jsx b/src/routes/AppRoutes.jsx index f0a862040..84c84402e 100644 --- a/src/routes/AppRoutes.jsx +++ b/src/routes/AppRoutes.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import PropTypes from 'prop-types'; import { AuthenticatedPageRoute, PageWrap, @@ -7,17 +8,25 @@ import { Routes, Route } from 'react-router-dom'; import { ProfilePage, NotFoundPage } from '../profile'; import { ProfilePage as NewProfilePage, NotFoundPage as NewNotFoundPage } from '../profile-v2'; -const isNewProfileEnabled = process.env.ENABLE_NEW_PROFILE_VIEW === 'true'; +const AppRoutes = ({ isNewProfileEnabled }) => { + const SelectedProfilePage = isNewProfileEnabled ? NewProfilePage : ProfilePage; + const SelectedNotFoundPage = isNewProfileEnabled ? NewNotFoundPage : NotFoundPage; -const SelectedProfilePage = isNewProfileEnabled ? NewProfilePage : ProfilePage; -const SelectedNotFoundPage = isNewProfileEnabled ? NewNotFoundPage : NotFoundPage; + return ( + + } /> + } /> + } /> + + ); +}; -const AppRoutes = () => ( - - } /> - } /> - } /> - -); +AppRoutes.propTypes = { + isNewProfileEnabled: PropTypes.bool, +}; + +AppRoutes.defaultProps = { + isNewProfileEnabled: null, +}; export default AppRoutes;