Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Render the new token dialog via turbo stream

Klaus Zanders6c395b620ab2
diff --git a/app/components/my/access_token/api_tokens_section_component.html.erb b/app/components/my/access_token/api_tokens_section_component.html.erb
index 181b5e8d908..3527199661c 100644
--- a/app/components/my/access_token/api_tokens_section_component.html.erb
+++ b/app/components/my/access_token/api_tokens_section_component.html.erb
@@ -42,7 +42,21 @@ See COPYRIGHT and LICENSE files for more details.
<% if @api_tokens.any? %>
<%= render My::AccessToken::API::TableComponent.new(rows: @api_tokens) %>
<% end %>
- <%= render My::AccessToken::NewAccessTokenComponent.new %>
+ <%= render(
+ Primer::Beta::Button.new(
+ tag: :a,
+ scheme: :primary,
+ test_selector: "api-token-add",
+ href: dialog_my_access_tokens_path(token_type: "api"),
+ data: { turbo_stream: true },
+ aria: { label: I18n.t("my.access_token.new_access_token_dialog_show_button_text") },
+ role: "button",
+ title: I18n.t("my.access_token.new_access_token_dialog_show_button_text")
+ )
+ ) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ I18n.t("my.access_token.new_access_token_dialog_show_button_text")
+ end %>
<% else %>
<div tabindex="0" class="-info op-toast">
<div role="alert" aria-atomic="true" class="op-toast--content">
diff --git a/app/components/my/access_token/new_access_token_component.html.erb b/app/components/my/access_token/new_access_token_component.html.erb
index fcda19cf2ea..7d4764a3e7c 100644
--- a/app/components/my/access_token/new_access_token_component.html.erb
+++ b/app/components/my/access_token/new_access_token_component.html.erb
@@ -36,11 +36,6 @@ See COPYRIGHT and LICENSE files for more details.
size: :large
)
) do |dialog|
- dialog.with_show_button(scheme: :primary, mt: 3, test_selector: "api-token-add") do |button|
- button.with_leading_visual_icon(icon: :plus)
- I18n.t("my.access_token.new_access_token_dialog_show_button_text")
- end
-
dialog.with_header(
show_divider: false,
visually_hide_title: false
diff --git a/app/controllers/my/access_tokens_controller.rb b/app/controllers/my/access_tokens_controller.rb
index 28fcb5d85b3..85ba7ec8e17 100644
--- a/app/controllers/my/access_tokens_controller.rb
+++ b/app/controllers/my/access_tokens_controller.rb
@@ -42,6 +42,7 @@ module My
layout "my"
no_authorization_required! :index,
+ :dialog,
:generate_rss_key,
:revoke_rss_key,
:generate_api_key,
diff --git a/app/views/my/access_tokens/dialog.turbo_stream.erb b/app/views/my/access_tokens/dialog.turbo_stream.erb
new file mode 100644
index 00000000000..df147cb9ac6
--- /dev/null
+++ b/app/views/my/access_tokens/dialog.turbo_stream.erb
@@ -0,0 +1,3 @@
+<%= turbo_stream.dialog do
+ render(My::AccessToken::NewAccessTokenComponent.new(token_type: @token_type))
+ end %>
diff --git a/config/routes.rb b/config/routes.rb
index 2db2f76d036..4b16aa1271f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -862,15 +862,16 @@ Rails.application.routes.draw do
namespace :my do
resources :access_tokens, only: %i[index] do
collection do
- post "generate_rss_key", action: "generate_rss_key"
- delete "revoke_rss_key", action: "revoke_rss_key"
+ get :dialog
+ post :generate_rss_key
+ delete :revoke_rss_key
- post "generate_api_key", action: "generate_api_key"
+ post :generate_api_key
end
- delete "revoke_api_key", action: "revoke_api_key"
- delete "revoke_ical_token", action: "revoke_ical_token"
- delete "revoke_storage_token", action: "revoke_storage_token"
+ delete :revoke_api_key
+ delete :revoke_ical_token
+ delete :revoke_storage_token
end
end