diff --git a/decidim-admin/app/controllers/decidim/admin/share_tokens_controller.rb b/decidim-admin/app/controllers/decidim/admin/share_tokens_controller.rb index 7ad77e091fe74..42dd09d91103f 100644 --- a/decidim-admin/app/controllers/decidim/admin/share_tokens_controller.rb +++ b/decidim-admin/app/controllers/decidim/admin/share_tokens_controller.rb @@ -15,10 +15,10 @@ def new def create @form = form(ShareTokenForm).from_params(params) - CreateShareToken.call(@form, share) do + CreateShareToken.call(@form, share_token) do on(:ok) do flash[:notice] = I18n.t("share_tokens.create.success", scope: "decidim.admin") - redirect_to code_group_codes_path + redirect_to share_tokens_path(component) end on(:invalid) do diff --git a/decidim-admin/app/forms/decidim/admin/share_token_form.rb b/decidim-admin/app/forms/decidim/admin/share_token_form.rb index be425955f72d9..b46dd072f1185 100644 --- a/decidim-admin/app/forms/decidim/admin/share_token_form.rb +++ b/decidim-admin/app/forms/decidim/admin/share_token_form.rb @@ -7,12 +7,20 @@ class ShareTokenForm < Decidim::Form attribute :token, String attribute :expires_at, Decidim::Attributes::TimeWithZone + attribute :no_expiration, Boolean, default: true validates :token, presence: true + validates :expires_at, presence: true, if: ->(form) { form.no_expiration.blank? } def token attributes[:token].to_s.upcase end + + def expires_at + return nil if no_expiration + + super + end end end end diff --git a/decidim-admin/app/views/decidim/admin/share_tokens/_form.html.erb b/decidim-admin/app/views/decidim/admin/share_tokens/_form.html.erb index 1d0cfbddd0040..afa6b7e0eff0f 100644 --- a/decidim-admin/app/views/decidim/admin/share_tokens/_form.html.erb +++ b/decidim-admin/app/views/decidim/admin/share_tokens/_form.html.erb @@ -1,10 +1,46 @@
- <%= form.text_field :token, aria: { label: :token }, style: "text-transform: uppercase" %> + <%= form.text_field :token, aria: { label: :token }, class: "form-input" %>
- <%= form.datetime_field :expires_at, aria: { label: :expires_at } %> +
+
+ <%= form.radio_button :no_expiration, true, id: "expires_never", checked: form.object.no_expiration %> + <%= form.label :no_expiration, "Never expire", for: "expires_never" %> +
+ +
+ <%= form.radio_button :no_expiration, false, id: "expires_custom", checked: !form.object.no_expiration %> + <%= form.label :no_expiration, "Custom", for: "expires_custom" %> +
+
+ +
mt-4"> + <%= form.datetime_field :expires_at, aria: { label: :expires_at } %> +
+ +