Skip to content

Commit

Permalink
FIX: Invalid Date on "last" shortcut for timer + bookmarks (#12783)
Browse files Browse the repository at this point in the history
The "last custom date and time" shortcut for the topic timer and
bookmarks could get into a state where it had an Invalid Date if
the user opened the topic timer modal, clicked Custom Date and then
closed the modal without making changes. This has been fixed, the
last custom date + time will no longer be set in this case and if
somehow the last custom date + time is invalid that option will not
show.

Also improve the wording from just "Last" to "Last custom datetime"
  • Loading branch information
martin-brennan committed Apr 21, 2021
1 parent 2dfa1a2 commit 206d8db
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export default Component.extend({
}

this._bindKeyboardShortcuts();
this._loadLastUsedCustomDatetime();
},

@observes("prefilledDatetime")
Expand Down Expand Up @@ -134,7 +133,7 @@ export default Component.extend({
if (lastTime && lastDate) {
let parsed = parseCustomDatetime(lastDate, lastTime, this.userTimezone);

if (parsed < now(this.userTimezone)) {
if (!parsed.isValid() || parsed < now(this.userTimezone)) {
return;
}

Expand Down Expand Up @@ -175,6 +174,8 @@ export default Component.extend({
"userTimezone"
)
options(additionalOptionsToShow, hiddenOptions, customOptions, userTimezone) {
this._loadLastUsedCustomDatetime();

let options = defaultShortcutOptions(userTimezone);

if (additionalOptionsToShow.length > 0) {
Expand Down Expand Up @@ -255,7 +256,7 @@ export default Component.extend({
this.userTimezone
);

if (customDatetime.isValid()) {
if (customDatetime.isValid() && this.customDate) {
dateTime = customDatetime;

localStorage.lastCustomTime = this.customTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,41 @@ acceptance("Topic - Edit timer", function (needs) {
assert.ok(regex.test(text));
});

test("schedule - last custom date and time", async function (assert) {
updateCurrentUser({ moderator: true });

await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".admin-topic-timer-update button");

await click("#tap_tile_custom");
await click(".modal-close");

await click(".toggle-admin-menu");
await click(".admin-topic-timer-update button");

assert.notOk(
exists("#tap_tile_last_custom"),
"it does not show last custom if the custom date and time was not filled and valid"
);

await click("#tap_tile_custom");
await fillIn(".tap-tile-date-input .date-picker", "2099-11-24");
await fillIn("#custom-time", "10:30");
await click(".edit-topic-timer-buttons button.btn-primary");

await click(".toggle-admin-menu");
await click(".admin-topic-timer-update button");

assert.ok(
exists("#tap_tile_last_custom"),
"it show last custom because the custom date and time was valid"
);
let text = queryAll("#tap_tile_last_custom").text().trim();
const regex = /Nov 24, 10:30 am/g;
assert.ok(regex.test(text));
});

test("TL4 can't auto-delete", async function (assert) {
updateCurrentUser({ moderator: false, admin: false, trust_level: 4 });

Expand Down
14 changes: 1 addition & 13 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,6 @@ en:
search_placeholder: "Search bookmarks by name, topic title, or post content"
search: "Search"
reminders:
later_today: "Later today"
next_business_day: "Next business day"
tomorrow: "Tomorrow"
next_week: "Next week"
post_local_date: "Date in post"
later_this_week: "Later this week"
start_of_next_business_week: "Monday"
start_of_next_business_week_alt: "Next Monday"
next_month: "Next month"
custom: "Custom date and time"
last_custom: "Last"
none: "No reminder needed"
today_with_time: "today at %{time}"
tomorrow_with_time: "tomorrow at %{time}"
at_time: "at %{date_time}"
Expand Down Expand Up @@ -614,7 +602,7 @@ en:
custom: "Custom date and time"
relative: "Relative time"
none: "None needed"
last_custom: "Last"
last_custom: "Last custom datetime"

user_action:
user_posted_topic: "<a href='%{userUrl}'>%{user}</a> posted <a href='%{topicUrl}'>the topic</a>"
Expand Down

0 comments on commit 206d8db

Please sign in to comment.