Skip to content

Commit

Permalink
[chores] Added radius_usage_enabled setting in status_page config
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Jan 4, 2024
1 parent 64941a7 commit 78443c1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
33 changes: 25 additions & 8 deletions client/components/status/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default class Status extends React.Component {
orgName,
language,
navigate,
statusPage,
} = this.props;
setTitle(t`STATUS_TITL`, orgName);
const {setLoading} = this.context;
Expand Down Expand Up @@ -187,7 +188,9 @@ export default class Status extends React.Component {
if (macaddr) {
const params = {macaddr};
await this.getUserActiveRadiusSessions(params);
await this.getUserRadiusUsage();
if (statusPage.radius_usage_enabled) {
await this.getUserRadiusUsage();
}
/* request to captive portal is made only if there is
no active session from macaddr stored in the cookie */
const {activeSessions} = this.state;
Expand Down Expand Up @@ -216,13 +219,23 @@ export default class Status extends React.Component {
}

componentWillUnmount = () => {
const {statusPage} = this.props;
clearInterval(this.intervalId);
clearInterval(this.getUserRadiusUsageIntervalId);
if (statusPage.radius_usage_enabled) {
clearInterval(this.getUserRadiusUsageIntervalId);
}
window.removeEventListener("resize", this.updateScreenWidth);
};

async finalOperations() {
const {userData, orgSlug, settings, navigate, setUserData} = this.props;
const {
userData,
orgSlug,
settings,
navigate,
setUserData,
statusPage,
} = this.props;
const {setLoading} = this.context;
// if the user needs bank card verification,
// redirect to payment page and stop here
Expand Down Expand Up @@ -260,10 +273,13 @@ export default class Status extends React.Component {
this.intervalId = setInterval(() => {
this.getUserActiveRadiusSessions();
}, 60000);
await this.getUserRadiusUsage();
this.getUserRadiusUsageIntervalId = setInterval(() => {
this.getUserRadiusUsage();
}, 60000);
if (statusPage.radius_usage_enabled) {
await this.getUserRadiusUsage();
this.getUserRadiusUsageIntervalId = setInterval(() => {
this.getUserRadiusUsage();
}, 60000);
}

window.addEventListener("resize", this.updateScreenWidth);
this.updateSpinner();
this.setState({radiusUsageSpinner: false});
Expand Down Expand Up @@ -964,7 +980,7 @@ export default class Status extends React.Component {
}
/>
)}
{showRadiusUsage && (
{statusPage.radius_usage_enabled && showRadiusUsage && (
<div className="inner flex-row limit-info">
<div className="bg row">
{radiusUsageSpinner ? this.getSpinner() : null}
Expand Down Expand Up @@ -1206,6 +1222,7 @@ Status.propTypes = {
url: PropTypes.string.isRequired,
}),
),
radius_usage_enabled: PropTypes.bool,
saml_logout_url: PropTypes.string,
}).isRequired,
language: PropTypes.string.isRequired,
Expand Down
5 changes: 5 additions & 0 deletions client/components/status/status.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const responseData = {

describe("<Status /> rendering with placeholder translation tags", () => {
const props = createTestProps();
props.statusPage.radius_usage_enabled = true;
it("should render translation placeholder correctly", () => {
const renderer = new ShallowRenderer();
const wrapper = renderer.render(<Status {...props} />);
Expand All @@ -105,6 +106,7 @@ describe("<Status /> rendering", () => {

it("should render correctly", () => {
props = createTestProps();
props.statusPage.radius_usage_enabled = true;
const renderer = new ShallowRenderer();
loadTranslation("en", "default");
const component = renderer.render(<Status {...props} />);
Expand Down Expand Up @@ -279,6 +281,7 @@ describe("<Status /> interactions", () => {
props = createTestProps({
userData: {...responseData, mustLogin: true},
});
props.statusPage.radius_usage_enabled = true;
validateToken.mockReturnValue(true);
const setLoading = jest.fn();
wrapper = shallow(<Status {...props} />, {
Expand Down Expand Up @@ -1787,6 +1790,7 @@ describe("<Status /> interactions", () => {
);
const prop = createTestProps();
prop.statusPage.links = links;
prop.statusPage.radius_usage_enabled = true;
prop.isAuthenticated = true;
wrapper = shallow(<Status {...prop} />, {
context: {setLoading: jest.fn()},
Expand Down Expand Up @@ -1885,6 +1889,7 @@ describe("<Status /> interactions", () => {
);
const prop = createTestProps();
prop.statusPage.links = links;
prop.statusPage.radius_usage_enabled = true;
prop.isAuthenticated = true;
prop.settings.subscriptions = true;
wrapper = shallow(<Status {...prop} />, {
Expand Down
2 changes: 2 additions & 0 deletions internals/config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ client:
secondary_text: false

registration_form:
auto_select_first_plan: false
input_fields:
phone_number: {}
username:
Expand Down Expand Up @@ -100,6 +101,7 @@ client:
social_links: []

status_page:
radius_usage_enabled: false
links: []

login_form:
Expand Down
1 change: 1 addition & 0 deletions organizations/default/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ client:
- text:
en: "Change your password"
url: "/{orgSlug}/change-password/"
radius_usage_enabled: true

login_form:
social_login:
Expand Down

0 comments on commit 78443c1

Please sign in to comment.