Skip to content

Commit

Permalink
feat: adds useCache prop to AuthenticatedPage, removes the use of cac… (
Browse files Browse the repository at this point in the history
#232)

* feat: adds useCache prop to AuthenticatedPage, removes the use of cache on LicenseActivationPage
  • Loading branch information
chavesj authored Mar 3, 2021
1 parent c614a4d commit c05ea1c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/components/app/AuthenticatedPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { EnterpriseBanner } from '../enterprise-banner';
import { Layout } from '../layout';
import { LoginRedirect } from '../login-redirect';

export default function AuthenticatedPage({ children }) {
export default function AuthenticatedPage({ children, useEnterpriseConfigCache }) {
return (
<LoginRedirect>
<EnterprisePage>
<EnterprisePage useEnterpriseConfigCache={useEnterpriseConfigCache}>
<Layout>
<EnterpriseBanner />
{children}
Expand All @@ -21,4 +21,9 @@ export default function AuthenticatedPage({ children }) {

AuthenticatedPage.propTypes = {
children: PropTypes.node.isRequired,
useEnterpriseConfigCache: PropTypes.bool,
};

AuthenticatedPage.defaultProps = {
useEnterpriseConfigCache: true,
};
9 changes: 7 additions & 2 deletions src/components/enterprise-page/EnterprisePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
useEnterpriseCustomerConfig,
} from './data/hooks';

export default function EnterprisePage({ children }) {
export default function EnterprisePage({ children, useEnterpriseConfigCache }) {
const { enterpriseSlug } = useParams();
const [enterpriseConfig, fetchError] = useEnterpriseCustomerConfig(enterpriseSlug);
const [enterpriseConfig, fetchError] = useEnterpriseCustomerConfig(enterpriseSlug, useEnterpriseConfigCache);

const user = getAuthenticatedUser();
const { profileImage } = user;
Expand Down Expand Up @@ -60,4 +60,9 @@ export default function EnterprisePage({ children }) {

EnterprisePage.propTypes = {
children: PropTypes.node.isRequired,
useEnterpriseConfigCache: PropTypes.bool,
};

EnterprisePage.defaultProps = {
useEnterpriseConfigCache: true,
};
5 changes: 3 additions & 2 deletions src/components/enterprise-page/data/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ const defaultBrandingConfig = {

/**
* @param {string} [enterpriseSlug] enterprise slug.
* @param {boolean} [useCache] indicates whether cache should be used
* @returns {object} EnterpriseConfig
*/
export function useEnterpriseCustomerConfig(enterpriseSlug) {
export function useEnterpriseCustomerConfig(enterpriseSlug, useCache = true) {
const [enterpriseConfig, setEnterpriseConfig] = useState();
const [fetchError, setFetchError] = useState();

useEffect(() => {
fetchEnterpriseCustomerConfigForSlug(enterpriseSlug)
fetchEnterpriseCustomerConfigForSlug(enterpriseSlug, useCache)
.then((response) => {
const { results } = camelCaseObject(response.data);
const config = results.pop();
Expand Down
4 changes: 2 additions & 2 deletions src/components/enterprise-page/data/service.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { getConfig } from '@edx/frontend-platform/config';

export function fetchEnterpriseCustomerConfigForSlug(slug) {
export function fetchEnterpriseCustomerConfigForSlug(slug, useCache = true) {
const config = getConfig();
const url = `${config.LMS_BASE_URL}/enterprise/api/v1/enterprise-customer/?slug=${slug}`;
const httpClient = getAuthenticatedHttpClient({
useCache: config.USE_API_CACHE,
useCache: useCache && config.USE_API_CACHE,
});
return httpClient.get(url);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import LicenseActivation from './LicenseActivation';
import AuthenticatedPage from '../app/AuthenticatedPage';

const LicenseActivationPage = () => (
<AuthenticatedPage>
<AuthenticatedPage useEnterpriseConfigCache={false}>
<LicenseActivation />
</AuthenticatedPage>

Expand Down

0 comments on commit c05ea1c

Please sign in to comment.