Skip to content

Commit 098c772

Browse files
pedroliveiravbrianchandotcom
authored andcommitted
LRSD-11305 Fix implementation of banner start date
1 parent 3c5cd56 commit 098c772

File tree

1 file changed

+30
-5
lines changed
  • workspaces/liferay-customer-workspace/client-extensions/liferay-customer-site-initializer-code/site-initializer/fragments/group/liferay-customer/customer-portal/fragments/information-banner

1 file changed

+30
-5
lines changed

workspaces/liferay-customer-workspace/client-extensions/liferay-customer-site-initializer-code/site-initializer/fragments/group/liferay-customer/customer-portal/fragments/information-banner/index.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,42 @@ const bannerElement = document.querySelectorAll('.cp-information-banner');
99
const bannerFragment = fragmentElement.querySelector('.cp-information-banner');
1010
const closeButton = fragmentElement.querySelector('.close');
1111

12-
const currentDate = new Date();
13-
const {0: month, 1: day, 2: year} = configuration.displayEndDate.split('/');
14-
const expirationDate = new Date(year, month - 1, day);
15-
const isExpired = expirationDate < currentDate;
12+
const currentDateTrimmed = new Date(new Date().setHours(0, 0, 0, 0));
13+
14+
const isAfterStart = () => {
15+
if (!configuration.displayStartDate) {
16+
return true;
17+
}
18+
19+
const [month, day, year] = configuration.displayStartDate.split('/');
20+
const startDate = new Date(year, month - 1, day);
21+
22+
return currentDateTrimmed >= startDate;
23+
};
24+
25+
const isBeforeExpiration = () => {
26+
if (!configuration.displayEndDate) {
27+
return true;
28+
}
29+
30+
const [month, day, year] = configuration.displayEndDate.split('/');
31+
const expirationDate = new Date(year, month - 1, day);
32+
33+
return currentDateTrimmed < expirationDate;
34+
};
1635

1736
const bannerState = !sessionStorage.getItem('@liferayCP:showBanner')
1837
? true
1938
: false;
39+
2040
const sessionStorageLogState = Liferay.ThemeDisplay.isSignedIn();
2141

22-
if (!isExpired && sessionStorageLogState && bannerState) {
42+
if (
43+
bannerState &&
44+
isAfterStart() &&
45+
isBeforeExpiration() &&
46+
sessionStorageLogState
47+
) {
2348
bannerElement?.forEach((item) => {
2449
item.style.display = 'flex';
2550
});

0 commit comments

Comments
 (0)