Skip to content

Commit d73d840

Browse files
authored
feat: added env parse to boolean functionality (#1389)
1 parent d23b5f5 commit d73d840

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/notification-preferences/data/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { getConfig } from '@edx/frontend-platform';
22

3+
import { parseEnvBoolean } from '../../utils';
4+
35
export const notificationChannels = () => ({
46
WEB: 'web',
5-
...(getConfig().SHOW_PUSH_CHANNEL && { PUSH: 'push' }),
6-
...(getConfig().SHOW_EMAIL_CHANNEL && { EMAIL: 'email' }),
7+
...(parseEnvBoolean(getConfig().SHOW_PUSH_CHANNEL) && { PUSH: 'push' }),
8+
...(parseEnvBoolean(getConfig().SHOW_EMAIL_CHANNEL) && { EMAIL: 'email' }),
79
});
810

911
export const shouldHideAppPreferences = (preferences, appId) => {

src/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ export function getMostRecentApprovedOrPendingVerifiedName(verifiedNames) {
3838

3939
return applicableName;
4040
}
41+
42+
/**
43+
* Parse an environment variable string value to a boolean.
44+
* @param {string} value the environment variable string value
45+
* @returns {boolean} the parsed boolean value
46+
*/
47+
export const parseEnvBoolean = (value) => {
48+
if (!value) { return false; }
49+
return String(value).toLowerCase() === 'true';
50+
};

0 commit comments

Comments
 (0)