FIX: Invalid Date on "last" shortcut for timer + bookmarks (#12783)

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"
This commit is contained in:
Martin Brennan 2021-04-22 09:26:31 +10:00 committed by GitHub
parent 2dfa1a267e
commit 206d8db433
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 16 deletions

View File

@ -88,7 +88,6 @@ export default Component.extend({
}
this._bindKeyboardShortcuts();
this._loadLastUsedCustomDatetime();
},
@observes("prefilledDatetime")
@ -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;
}
@ -175,6 +174,8 @@ export default Component.extend({
"userTimezone"
)
options(additionalOptionsToShow, hiddenOptions, customOptions, userTimezone) {
this._loadLastUsedCustomDatetime();
let options = defaultShortcutOptions(userTimezone);
if (additionalOptionsToShow.length > 0) {
@ -255,7 +256,7 @@ export default Component.extend({
this.userTimezone
);
if (customDatetime.isValid()) {
if (customDatetime.isValid() && this.customDate) {
dateTime = customDatetime;
localStorage.lastCustomTime = this.customTime;

View File

@ -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 });

View File

@ -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}"
@ -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>"