diff --git a/app/javascript/controllers/magic_link_controller.js b/app/javascript/controllers/magic_link_controller.js index 4d6c45ab5..3e2e4618c 100644 --- a/app/javascript/controllers/magic_link_controller.js +++ b/app/javascript/controllers/magic_link_controller.js @@ -4,12 +4,18 @@ import { onNextEventLoopTick } from "helpers/timing_helpers" export default class extends Controller { static targets = [ "input" ] + submitOnEnter(event) { + event.preventDefault() + this.submit() + } + + submitOnPaste() { + onNextEventLoopTick(() => this.submit()) + } + submit() { - onNextEventLoopTick(() => { - if (!this.inputTarget.disabled) { - this.element.submit() - this.inputTarget.disabled = true - } - }) + if (this.inputTarget.disabled) return + this.element.submit() + this.inputTarget.disabled = true } } diff --git a/app/views/sessions/magic_links/show.html.erb b/app/views/sessions/magic_links/show.html.erb index 931156ff6..434bb93c3 100644 --- a/app/views/sessions/magic_links/show.html.erb +++ b/app/views/sessions/magic_links/show.html.erb @@ -10,7 +10,7 @@ <%= form.text_field :code, required: true, class: "input center txt-align-enter txt-large", autofocus: true, autocorrect: "off", autocapitalize: "off", spellcheck: "false", "data-1p-ignore": true, autocomplete: "one-time-code", maxlength: "6", placeholder: "••••••", value: params[:code], - data: { magic_link_target: "input", action: "keydown.enter->magic-link#submit paste->magic-link#submit" } %> + data: { magic_link_target: "input", action: "keydown.enter->magic-link#submitOnEnter paste->magic-link#submitOnPaste" } %> <% end %>

The code you receive will work for <%= distance_of_time_in_words(MagicLink::EXPIRATION_TIME) %>.

diff --git a/test/system/smoke_test.rb b/test/system/smoke_test.rb index e4bc9cae9..c70d42e95 100644 --- a/test/system/smoke_test.rb +++ b/test/system/smoke_test.rb @@ -1,6 +1,26 @@ require "application_system_test_case" class SmokeTest < ApplicationSystemTestCase + test "joining an account" do + account = accounts("37s") + + visit join_url(code: account.join_code.code, script_name: account.slug) + fill_in "Email address", with: "newbie@example.com" + click_on "Continue" + + assert_selector "h1", text: "Check your email" + identity = Identity.find_by!(email_address: "newbie@example.com") + code = identity.magic_links.active.first.code + fill_in "code", with: code + send_keys :enter + + assert_selector "input[id=user_name]" + fill_in "Full name", with: "New Bee" + click_on "Continue" + + assert_selector "h1", text: "Writebook" + end + test "create a card" do sign_in_as(users(:david))