Skip to content

Commit 132d863

Browse files
committed
Fix warning message to show remaining time in minutes
1 parent 3a37239 commit 132d863

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

app/javascript/controllers/session_timeout_controller.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ export default class extends Controller {
8888
showWarning() {
8989
if (!this.flashElement || this.warningVisible) return;
9090

91-
const messageTemplate = this.valueOrDefault("warningMessage", "Your session will expire in %{seconds} seconds.");
92-
const messageText = messageTemplate.replace("%{seconds}", this.warningOffsetValue);
91+
const remainingMinutes = this.minutesFromSeconds(this.warningOffsetValue);
92+
const messageTemplate = this.valueOrDefault("warningMessage", "Your session will expire in %{minutes} minutes.");
93+
const messageText = messageTemplate.replace("%{minutes}", remainingMinutes);
9394
const staySignedInLabel = this.valueOrDefault("staySignedInLabel", "Stay signed in");
9495

9596
const alert = document.createElement("div");
@@ -184,6 +185,11 @@ export default class extends Controller {
184185
alert.remove();
185186
}
186187

188+
minutesFromSeconds(seconds) {
189+
const minutes = Math.ceil(seconds / 60);
190+
return Math.max(minutes, 1);
191+
}
192+
187193
valueOrDefault(name, fallback = "") {
188194
const hasKey = this[`has${this.capitalize(name)}Value`];
189195
if (hasKey) {

config/locales/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ en:
3232
messages:
3333
user_not_registered: "User Not registered. Please contact a server administrator for a user account"
3434
session_timeout:
35-
warning_message: "Your session will expire in %{seconds} seconds."
35+
warning_message: "Your session will expire in %{minutes} minutes."
3636
stay_signed_in: "Stay signed in"
3737
error_message: "We couldn't extend your session. Please save your work and sign in again."
3838
expired_message: "Your session has expired. Please sign in again to continue."

spec/system/session_timeout_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
expect(page).to have_css(
3838
".alert-warning",
39-
text: I18n.t("session_timeout.warning_message", seconds: warning_offset_seconds)
39+
text: expected_warning_message(warning_offset_seconds)
4040
)
4141
end
4242

@@ -148,6 +148,14 @@
148148
end
149149
end
150150

151+
def expected_warning_message(seconds)
152+
I18n.t("session_timeout.warning_message", minutes: minutes_from_seconds(seconds))
153+
end
154+
155+
def minutes_from_seconds(seconds)
156+
[(seconds / 60.0).ceil, 1].max
157+
end
158+
151159
def wait_for_session_timeout_controller
152160
page.find("#flash-messages", visible: :all)
153161

0 commit comments

Comments
 (0)