Skip to content

Commit

Permalink
Merge branch 'master' into bilalqamar95/node20-upgrade-1
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz authored Aug 26, 2024
2 parents e1958c6 + dd693bc commit 6690257
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ FEATURE_FILE_ATTACHMENT='true'
IS_MAINTENANCE_ALERT_ENABLED=''
MAINTENANCE_ALERT_MESSAGE=''
MAINTENANCE_ALERT_START_TIMESTAMP=''
MAINTENANCE_ALERT_END_TIMESTAMP=''
USE_API_CACHE='true'
SUBSCRIPTION_LPR='true'
PLOTLY_SERVER_URL='http://localhost:8050'
Expand Down
1 change: 1 addition & 0 deletions .env.development-stage
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ FEATURE_PENDING_ENROLLMENT_ACTIONS='false'
IS_MAINTENANCE_ALERT_ENABLED=''
MAINTENANCE_ALERT_MESSAGE='edX is currently in a brief maintenance window. Functionality involving course enrollments is unavailable at this time, including enrollment and assignment. Please check back shortly to continue the learning journey.'
MAINTENANCE_ALERT_START_TIMESTAMP=''
MAINTENANCE_ALERT_END_TIMESTAMP=''

# Common

Expand Down
12 changes: 10 additions & 2 deletions src/components/App/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { logError } from '@edx/frontend-platform/logging';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { getConfig } from '@edx/frontend-platform/config';

import dayjs from 'dayjs';
import Header from '../../containers/Header';
import Footer from '../../containers/Footer';
import EnterpriseIndexPage from '../../containers/EnterpriseIndexPage';
Expand All @@ -32,7 +33,7 @@ import { SystemWideWarningBanner } from '../system-wide-banner';

import store from '../../data/store';
import { ROUTE_NAMES } from '../EnterpriseApp/data/constants';
import { defaultQueryClientRetryHandler, queryCacheOnErrorHandler } from '../../utils';
import { defaultQueryClientRetryHandler, isTodayBetweenDates, queryCacheOnErrorHandler } from '../../utils';

// eslint-disable-next-line import/no-unresolved
const ReactQueryDevtoolsProduction = lazy(() => import('@tanstack/react-query-devtools/production').then((d) => ({
Expand Down Expand Up @@ -101,8 +102,15 @@ const AppWrapper = () => {
return false;
}
const startTimestamp = config.MAINTENANCE_ALERT_START_TIMESTAMP;
const endTimestamp = config.MAINTENANCE_ALERT_END_TIMESTAMP;
if (startTimestamp && endTimestamp) {
return isTodayBetweenDates({ startDate: startTimestamp, endDate: endTimestamp });
}
if (startTimestamp) {
return new Date() > new Date(startTimestamp);
return dayjs().isAfter(dayjs(startTimestamp));
}
if (endTimestamp) {
return dayjs().isBefore(dayjs(endTimestamp));
}
return true;
}, [config]);
Expand Down
1 change: 1 addition & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ initialize({
IS_MAINTENANCE_ALERT_ENABLED: process.env.IS_MAINTENANCE_ALERT_ENABLED || null,
MAINTENANCE_ALERT_MESSAGE: process.env.MAINTENANCE_ALERT_MESSAGE || null,
MAINTENANCE_ALERT_START_TIMESTAMP: process.env.MAINTENANCE_ALERT_START_TIMESTAMP || null,
MAINTENANCE_ALERT_END_TIMESTAMP: process.env.MAINTENANCE_ALERT_END_TIMESTAMP || null,
ENTERPRISE_LEARNER_PORTAL_URL: process.env.ENTERPRISE_LEARNER_PORTAL_URL || null,
FEATURE_LEARNER_CREDIT_MANAGEMENT: process.env.FEATURE_LEARNER_CREDIT_MANAGEMENT || hasFeatureFlagEnabled('LEARNER_CREDIT_MANAGEMENT') || null,
FEATURE_CONTENT_HIGHLIGHTS: process.env.FEATURE_CONTENT_HIGHLIGHTS || hasFeatureFlagEnabled('CONTENT_HIGHLIGHTS') || null,
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ function isTodayWithinDateThreshold({ date, days }) {
const offsetDays = dateToCheck.subtract(days, 'days');
return today.isBetween(offsetDays, dateToCheck);
}
// TODO: Generalize this function with isTodayWithinDateThreshold
function isTodayBetweenDates({ startDate, endDate }) {
const today = dayjs();
const formattedStartDate = dayjs(startDate);
const formattedEndDate = dayjs(endDate);
return today.isBetween(formattedStartDate, formattedEndDate);
}

export {
camelCaseDict,
Expand Down Expand Up @@ -620,4 +627,5 @@ export {
i18nFormatPassedTimestamp,
i18nFormatProgressStatus,
isTodayWithinDateThreshold,
isTodayBetweenDates,
};

0 comments on commit 6690257

Please sign in to comment.