Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds end timestamp to maintenance banner #1165

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ FEATURE_LANGUAGE_FACET='true'
IS_MAINTENANCE_ALERT_ENABLED=''
MAINTENANCE_ALERT_MESSAGE=''
MAINTENANCE_ALERT_START_TIMESTAMP=''
MAINTENANCE_ALERT_END_TIMESTAMP=''
HOTJAR_APP_ID=''
HOTJAR_VERSION=6
HOTJAR_DEBUG=''
Expand Down
1 change: 1 addition & 0 deletions .env.development-stage
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ FEATURE_LANGUAGE_FACET='true'
IS_MAINTENANCE_ALERT_ENABLED=''
MAINTENANCE_ALERT_MESSAGE=''
MAINTENANCE_ALERT_START_TIMESTAMP=''
MAINTENANCE_ALERT_END_TIMESTAMP=''
HOTJAR_APP_ID=''
HOTJAR_VERSION=6
HOTJAR_DEBUG=''
Expand Down
25 changes: 24 additions & 1 deletion src/components/app/Layout.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,43 @@ describe('Layout', () => {
isSystemMaintenanceAlertOpen: false,
maintenanceMessage: undefined,
maintenanceStartTimestamp: undefined,
maintenanceEndTimestamp: undefined,
},
{
isSystemMaintenanceAlertOpen: true,
maintenanceMessage: 'Hello World!',
maintenanceStartTimestamp: undefined,
maintenanceEndTimestamp: undefined,
},
{
isSystemMaintenanceAlertOpen: true,
maintenanceMessage: 'Hello World!',
maintenanceStartTimestamp: dayjs().subtract(1, 'm').toISOString(),
maintenanceEndTimestamp: dayjs().add(2, 'm').toISOString(),
},
{
isSystemMaintenanceAlertOpen: false,
maintenanceMessage: 'Hello World!',
maintenanceStartTimestamp: dayjs().add(1, 'm').toISOString(),
maintenanceStartTimestamp: dayjs().subtract(1, 'm').toISOString(),
maintenanceEndTimestamp: dayjs().add(2, 'm').toISOString(),
},
{
isSystemMaintenanceAlertOpen: true,
maintenanceMessage: 'Hello World!',
maintenanceStartTimestamp: undefined,
maintenanceEndTimestamp: dayjs().add(2, 'm').toISOString(),
},
{
isSystemMaintenanceAlertOpen: true,
maintenanceMessage: 'Hello World!',
maintenanceStartTimestamp: dayjs().subtract(1, 'm').toISOString(),
maintenanceEndTimestamp: undefined,
},
])('renders with enterprise customer (%s)', ({
isSystemMaintenanceAlertOpen,
maintenanceMessage,
maintenanceStartTimestamp,
maintenanceEndTimestamp,
}) => {
if (maintenanceMessage) {
mergeConfig({
Expand All @@ -113,6 +130,12 @@ describe('Layout', () => {
});
}

if (maintenanceEndTimestamp) {
mergeConfig({
MAINTENANCE_ALERT_END_TIMESTAMP: maintenanceEndTimestamp ?? '',
});
}

renderWithRouterProvider({
path: '/:enterpriseSlug',
element: <LayoutWrapper />,
Expand Down
26 changes: 18 additions & 8 deletions src/components/app/data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

import { POLICY_TYPES } from '../../enterprise-user-subsidy/enterprise-offers/data/constants';
import { LICENSE_STATUS } from '../../enterprise-user-subsidy/data/constants';
import { getBrandColorsFromCSSVariables, isDefinedAndNotNull, isTodayWithinDateThreshold } from '../../../utils/common';
import {
getBrandColorsFromCSSVariables,
isDefinedAndNotNull,
isTodayBetweenDates,
isTodayWithinDateThreshold,
} from '../../../utils/common';
import { COURSE_STATUSES, SUBSIDY_TYPE } from '../../../constants';
import { LATE_ENROLLMENTS_BUFFER_DAYS } from '../../../config/constants';
import {
Expand Down Expand Up @@ -34,15 +39,20 @@
return false;
}
const startTimestamp = config.MAINTENANCE_ALERT_START_TIMESTAMP;

// Given no start timestamp, the system maintenance alert should be open, as
// it's enabled and has a message.
if (!startTimestamp) {
return true;
const endTimestamp = config.MAINTENANCE_ALERT_END_TIMESTAMP;
if (startTimestamp && endTimestamp) {
return isTodayBetweenDates({ startDate: startTimestamp, endDate: endTimestamp });
}
if (startTimestamp) {
return dayjs().isAfter(dayjs(startTimestamp));

Check warning on line 47 in src/components/app/data/utils.js

View check run for this annotation

Codecov / codecov/patch

src/components/app/data/utils.js#L47

Added line #L47 was not covered by tests
}
if (endTimestamp) {
return dayjs().isBefore(dayjs(endTimestamp));

Check warning on line 50 in src/components/app/data/utils.js

View check run for this annotation

Codecov / codecov/patch

src/components/app/data/utils.js#L50

Added line #L50 was not covered by tests
}

// Otherwise, check whether today's date is after the defined start date.
return dayjs().isAfter(dayjs(startTimestamp));
// Given no start timestamp and no end timestamp, the system maintenance alert should be open, as
// it's enabled and has a message.
return true;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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,
ENABLE_SKILLS_QUIZ: process.env.ENABLE_SKILLS_QUIZ || false,
ENABLE_NOTICES: process.env.ENABLE_NOTICES || null,
LEARNER_SUPPORT_URL: process.env.LEARNER_SUPPORT_URL || null,
Expand Down
7 changes: 7 additions & 0 deletions src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ export function isTodayWithinDateThreshold({ date, days }) {
return today.isBetween(offsetDays, dateToCheck);
}

export function isTodayBetweenDates({ startDate, endDate }) {
const today = dayjs();
const formattedStartDate = dayjs(startDate);
const formattedEndDate = dayjs(endDate);
return today.isBetween(formattedStartDate, formattedEndDate);
}

/**
* Returns a formatted date in the following format:
*
Expand Down
Loading