From 975906b606b6e597185528540c4d1668c06923cf Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 22 Nov 2023 14:22:25 +0200 Subject: [PATCH] refactoring: devide into components, added tests --- .../common/action_button/component.html.erb | 13 ++ .../common/action_button/component.rb | 31 ++++ .../buttons/button_to/component.html.erb | 4 +- .../common/buttons/button_to/component.rb | 9 +- .../checkbox_with_label}/component.html.erb | 2 +- .../checkbox_with_label/component.rb | 20 +++ .../rounded_checkbox/component.html.erb | 2 + .../checkboxes/rounded_checkbox/component.rb | 19 +++ .../form/dropdown_input/component.html.erb | 3 +- .../common/form/dropdown_input/component.rb | 8 +- .../form/email_field/component.html.erb | 3 +- .../common/form/email_field/component.rb | 6 +- .../form/form_button/component.html.erb | 2 +- .../common/form/form_button/component.rb | 6 +- .../common/form/label/component.html.erb | 4 +- app/components/common/form/label/component.rb | 13 +- .../form/number_field/component.html.erb | 1 + .../common/form/number_field/component.rb | 19 +++ .../form/password_field/component.html.erb | 3 +- .../common/form/password_field/component.rb | 6 +- .../form/telephone_field/component.html.erb | 1 + .../component.rb | 8 +- .../common/form/text_field/component.html.erb | 1 + .../common/form/text_field/component.rb | 18 ++ .../links/link_button/component.html.erb | 4 +- .../common/links/link_button/component.rb | 9 +- .../modals/pay_invoice/component.html.erb | 5 +- .../auction_action_button/component.html.erb | 4 +- .../component.html.erb | 6 +- .../edit_english_offer/component.html.erb | 2 +- .../outstanding_invoices/component.html.erb} | 24 +-- .../outstanding_invoices/component.rb | 47 ++++++ .../invoices/paid_invoices/component.html.erb | 48 ++++++ .../pages/invoices/paid_invoices/component.rb | 31 ++++ .../component.html.erb | 10 ++ .../blind_auction_offer_table/component.rb | 22 +++ .../component.html.erb | 58 +++++++ .../english_auction_offer_table/component.rb | 33 ++++ .../offers/offers_table/component.html.erb | 31 ++++ .../pages/offers/offers_table/component.rb | 26 +++ app/controllers/payment_orders_controller.rb | 38 ----- app/views/auctions/_auction.html.erb | 2 +- .../billing_profiles/_billing_info.html.erb | 4 +- app/views/billing_profiles/_form.html.erb | 36 ++-- app/views/billing_profiles/index.html.erb | 6 +- app/views/devise/passwords/edit.html.erb | 13 +- app/views/devise/sessions/new.html.erb | 14 +- app/views/english_offers/edit.html.erb | 13 -- app/views/english_offers/new.html.erb | 15 -- app/views/english_offers/show.html.erb | 67 +------- app/views/histories/index.html.erb | 2 + app/views/invoices/_paid_invoices.html.erb | 59 ------- app/views/invoices/index.html.erb | 6 +- app/views/notifications/index.html.erb | 2 +- app/views/offers/_offer.html.erb | 11 +- app/views/offers/delete.html.erb | 13 -- app/views/offers/edit.html.erb | 13 -- app/views/offers/index.html.erb | 42 +---- app/views/offers/new.html.erb | 13 -- app/views/offers/show.html.erb | 19 +-- app/views/phone_confirmations/_form.html.erb | 4 +- app/views/svg/_trash.html.erb | 1 + app/views/users/_form.html.erb | 75 +++++---- app/views/users/_sign_up_form.html.erb | 157 +++++++++--------- app/views/users/_user_info.html.erb | 9 +- app/views/wishlist_items/_editable.html.erb | 23 ++- .../wishlist_items/_wishlist_items.html.erb | 10 +- app/views/wishlist_items/index.html.erb | 4 +- 68 files changed, 679 insertions(+), 554 deletions(-) create mode 100644 app/components/common/action_button/component.html.erb create mode 100644 app/components/common/action_button/component.rb rename app/components/common/form/{checkbox => checkboxes/checkbox_with_label}/component.html.erb (69%) create mode 100644 app/components/common/form/checkboxes/checkbox_with_label/component.rb create mode 100644 app/components/common/form/checkboxes/rounded_checkbox/component.html.erb create mode 100644 app/components/common/form/checkboxes/rounded_checkbox/component.rb create mode 100644 app/components/common/form/number_field/component.html.erb create mode 100644 app/components/common/form/number_field/component.rb create mode 100644 app/components/common/form/telephone_field/component.html.erb rename app/components/common/form/{checkbox => telephone_field}/component.rb (53%) create mode 100644 app/components/common/form/text_field/component.html.erb create mode 100644 app/components/common/form/text_field/component.rb rename app/{views/invoices/_outstanding_invoices.html.erb => components/pages/invoices/outstanding_invoices/component.html.erb} (69%) create mode 100644 app/components/pages/invoices/outstanding_invoices/component.rb create mode 100644 app/components/pages/invoices/paid_invoices/component.html.erb create mode 100644 app/components/pages/invoices/paid_invoices/component.rb create mode 100644 app/components/pages/offers/blind_auction_offer_table/component.html.erb create mode 100644 app/components/pages/offers/blind_auction_offer_table/component.rb create mode 100644 app/components/pages/offers/english_auction_offer_table/component.html.erb create mode 100644 app/components/pages/offers/english_auction_offer_table/component.rb create mode 100644 app/components/pages/offers/offers_table/component.html.erb create mode 100644 app/components/pages/offers/offers_table/component.rb delete mode 100644 app/views/invoices/_paid_invoices.html.erb create mode 100644 app/views/svg/_trash.html.erb diff --git a/app/components/common/action_button/component.html.erb b/app/components/common/action_button/component.html.erb new file mode 100644 index 000000000..e66940943 --- /dev/null +++ b/app/components/common/action_button/component.html.erb @@ -0,0 +1,13 @@ +<% if @type == 'close' %> + <%= link_to @href, class: "c-btn #{colorize} c-btn--icon", **@options do %> + + <% end %> +<% elsif @type == 'edit' %> + <%= link_to @href, class: "c-btn #{colorize} c-btn--icon", **@options do %> + + <% end %> +<% elsif @type == 'delete' %> + <%= button_to @href, class: "c-btn #{colorize} c-btn--icon", **@options do %> + + <% end %> +<% end %> diff --git a/app/components/common/action_button/component.rb b/app/components/common/action_button/component.rb new file mode 100644 index 000000000..685102e3f --- /dev/null +++ b/app/components/common/action_button/component.rb @@ -0,0 +1,31 @@ +module Common + module ActionButton + class Component < ApplicationViewComponent + attr_reader :type, :href, :color, :options + + def initialize(type:, href:, color: 'ghost', options: {}) + super + + @type = type + @href = href + @color = color + @options = options + end + + def colorize + colors_hash[color] + end + + def colors_hash + { + 'blue-secondary' => 'c-btn--blue-secondary', + 'green' => 'c-btn--green', + 'blue' => 'c-btn--blue', + 'orange' => 'c-btn--orange', + 'black' => 'c-btn--black', + 'ghost' => 'c-btn--ghost' + } + end + end + end +end diff --git a/app/components/common/buttons/button_to/component.html.erb b/app/components/common/buttons/button_to/component.html.erb index 3819abdf0..227c778ab 100644 --- a/app/components/common/buttons/button_to/component.html.erb +++ b/app/components/common/buttons/button_to/component.html.erb @@ -1,7 +1,7 @@ <% if content.present? %> - <%= button_to @href, class: "c-btn--icon c-btn #{colorize}", data: { **@data_attributes }, target: @target, method: @method, form: { **form_attributes } do %> + <%= button_to @href, class: "c-btn--icon c-btn #{colorize}", **@options do %> <%= content %> <% end %> <% else %> - <%= button_to @link_title, @href, class: "c-login__button c-btn #{colorize}", data: { **@data_attributes }, target: @target, method: @method, form: { **form_attributes } %> + <%= button_to @title_caption, @href, class: "c-login__button c-btn #{colorize}", **@options%> <% end %> diff --git a/app/components/common/buttons/button_to/component.rb b/app/components/common/buttons/button_to/component.rb index 6db442541..9a5544207 100644 --- a/app/components/common/buttons/button_to/component.rb +++ b/app/components/common/buttons/button_to/component.rb @@ -2,18 +2,15 @@ module Common module Buttons module ButtonTo class Component < ApplicationViewComponent - attr_reader :title_caption, :href, :data_attributes, :color, :target, :method, :form_attributes + attr_reader :title_caption, :href, :color, :options - def initialize(title_caption:, href:, data_attributes: {}, color: 'blue-secondary', target: '_top', method: :post, form_attributes: {}) + def initialize(href:, title_caption: nil, color: 'blue-secondary', options: {}) super @title_caption = title_caption @href = href - @data_attributes = data_attributes - @target = target @color = color - @method = method - @form_attributes = form_attributes + @options = options end def colorize diff --git a/app/components/common/form/checkbox/component.html.erb b/app/components/common/form/checkboxes/checkbox_with_label/component.html.erb similarity index 69% rename from app/components/common/form/checkbox/component.html.erb rename to app/components/common/form/checkboxes/checkbox_with_label/component.html.erb index e30a43751..5d33f6813 100644 --- a/app/components/common/form/checkbox/component.html.erb +++ b/app/components/common/form/checkboxes/checkbox_with_label/component.html.erb @@ -1,5 +1,5 @@ diff --git a/app/components/common/form/checkboxes/checkbox_with_label/component.rb b/app/components/common/form/checkboxes/checkbox_with_label/component.rb new file mode 100644 index 000000000..903ba31ff --- /dev/null +++ b/app/components/common/form/checkboxes/checkbox_with_label/component.rb @@ -0,0 +1,20 @@ +module Common + module Form + module Checkboxes + module CheckboxWithLabel + class Component < ApplicationViewComponent + attr_reader :label_title, :form, :attribute, :options + + def initialize(label_title:, form:, attribute:, options: {}) + super + + @label_title = label_title + @form = form + @attribute = attribute + @options = options + end + end + end + end + end +end diff --git a/app/components/common/form/checkboxes/rounded_checkbox/component.html.erb b/app/components/common/form/checkboxes/rounded_checkbox/component.html.erb new file mode 100644 index 000000000..2f9021b4f --- /dev/null +++ b/app/components/common/form/checkboxes/rounded_checkbox/component.html.erb @@ -0,0 +1,2 @@ +<%= @form.check_box @attribute, @options %> +
\ No newline at end of file diff --git a/app/components/common/form/checkboxes/rounded_checkbox/component.rb b/app/components/common/form/checkboxes/rounded_checkbox/component.rb new file mode 100644 index 000000000..7c3788248 --- /dev/null +++ b/app/components/common/form/checkboxes/rounded_checkbox/component.rb @@ -0,0 +1,19 @@ +module Common + module Form + module Checkboxes + module RoundedCheckbox + class Component < ApplicationViewComponent + attr_reader :attribute, :form, :options + + def initialize(form:, attribute:, options: {}) + super + + @form = form + @attribute = attribute + @options = options + end + end + end + end + end +end diff --git a/app/components/common/form/dropdown_input/component.html.erb b/app/components/common/form/dropdown_input/component.html.erb index 56a1e5fd0..bc6d9dc86 100644 --- a/app/components/common/form/dropdown_input/component.html.erb +++ b/app/components/common/form/dropdown_input/component.html.erb @@ -1,2 +1 @@ -<%= form.label @attribute, @label %> -<%= @form.select @attribute, @enum, { include_blank: @include_blank }, { } %> +<%= @form.select @attribute, @enum, { **@first_options }, { **@second_options } %> diff --git a/app/components/common/form/dropdown_input/component.rb b/app/components/common/form/dropdown_input/component.rb index 90658c3e8..1d045a927 100644 --- a/app/components/common/form/dropdown_input/component.rb +++ b/app/components/common/form/dropdown_input/component.rb @@ -2,16 +2,16 @@ module Common module Form module DropdownInput class Component < ApplicationViewComponent - attr_reader :form, :attribute, :enum, :label, :include_blank + attr_reader :form, :attribute, :enum, :first_options, :second_options - def initialize(form:, attribute:, label:, enum:, include_blank: false, **options) + def initialize(form:, attribute:, enum:, first_options: {}, second_options: {}) super @form = form @attribute = attribute @enum = enum - @label = label - @include_blank = include_blank + @first_options = first_options + @second_options = second_options end end end diff --git a/app/components/common/form/email_field/component.html.erb b/app/components/common/form/email_field/component.html.erb index 17e5ee5bc..bdc5957a4 100644 --- a/app/components/common/form/email_field/component.html.erb +++ b/app/components/common/form/email_field/component.html.erb @@ -1,2 +1 @@ -<%= @form.label @attribute, @label_caption %> -<%= @form.email_field @attribute, autofocus: @autofocus, autocomplete: @autocomplete %> +<%= @form.email_field @attribute, **@options %> diff --git a/app/components/common/form/email_field/component.rb b/app/components/common/form/email_field/component.rb index b1f4111b0..50d4925c7 100644 --- a/app/components/common/form/email_field/component.rb +++ b/app/components/common/form/email_field/component.rb @@ -3,7 +3,7 @@ module Form module EmailField class Component < ApplicationViewComponent - attr_reader :form, :attribute, :autocomple, :autofocus, :label_caption + attr_reader :form, :attribute, :options def initialize(form:, attribute:, options:) super @@ -11,9 +11,7 @@ def initialize(form:, attribute:, options:) @form = form @attribute = attribute - @autocomple = options[:autocomple] - @autofocus = options[:autofocus] - @label_caption = options[:label_caption] + @options = options end end end diff --git a/app/components/common/form/form_button/component.html.erb b/app/components/common/form/form_button/component.html.erb index e8b09b674..234a56513 100644 --- a/app/components/common/form/form_button/component.html.erb +++ b/app/components/common/form/form_button/component.html.erb @@ -1 +1 @@ -<%= @form.button @btn_title, class: "c-btn #{colorize} c-login__btn", data: { turbo: @data_turbo } %> \ No newline at end of file +<%= @form.button @btn_title, class: "c-btn #{colorize} c-login__btn", **@options %> diff --git a/app/components/common/form/form_button/component.rb b/app/components/common/form/form_button/component.rb index 3e057bc51..26419987f 100644 --- a/app/components/common/form/form_button/component.rb +++ b/app/components/common/form/form_button/component.rb @@ -2,15 +2,15 @@ module Common module Form module FormButton class Component < ApplicationViewComponent - attr_reader :btn_title, :form, :data_turbo, :color + attr_reader :btn_title, :form, :color, :options - def initialize(btn_title:, form:, data_turbo:, color: 'green') + def initialize(btn_title:, form:, color: 'green', options: {}) super @btn_title = btn_title @form = form - @data_turbo = data_turbo @color = color + @options = options end def colorize diff --git a/app/components/common/form/label/component.html.erb b/app/components/common/form/label/component.html.erb index c54cb44b9..ded72d440 100644 --- a/app/components/common/form/label/component.html.erb +++ b/app/components/common/form/label/component.html.erb @@ -1,7 +1,7 @@ <% if content.present? %> - <%= @form.label @attribute, class: "c-table__filters__btn js-table-filter-btn #{@css_class}", style: @style, for: @for_component, data: { **@data_attributes} do %> + <%= @form.label @attribute, **@options do %> <%= content %> <% end %> <% else %> - <%= @form.label @attribute, @title, class: "c-table__filters__btn js-table-filter-btn #{@css_class}", style: @style, for: @for_component, data: { **@data_attributes} %> + <%= @form.label @attribute, @title, **@options %> <% end %> diff --git a/app/components/common/form/label/component.rb b/app/components/common/form/label/component.rb index 1a73c0967..9fc9e6fac 100644 --- a/app/components/common/form/label/component.rb +++ b/app/components/common/form/label/component.rb @@ -2,22 +2,17 @@ module Common module Form module Label class Component < ApplicationViewComponent - attr_reader :attribute, :form, :title, :for_component, :data_attributes, :style, :css_class + attr_reader :attribute, :form, :title, :options - def initialize(attribute:, form:, title:, for_component:, options:, data_attributes: {}) + def initialize(attribute:, form:, title: nil, options: {}) super @attribute = attribute - @title = title @form = form - @for_component = for_component - @data_attributes = data_attributes - - @style = options[:style] - @css_class = options[:css_class] + @title = title + @options = options end end end end end - diff --git a/app/components/common/form/number_field/component.html.erb b/app/components/common/form/number_field/component.html.erb new file mode 100644 index 000000000..af6031bd1 --- /dev/null +++ b/app/components/common/form/number_field/component.html.erb @@ -0,0 +1 @@ +<%= @form.number_field @attribute, **@options %> diff --git a/app/components/common/form/number_field/component.rb b/app/components/common/form/number_field/component.rb new file mode 100644 index 000000000..02ccd9bb3 --- /dev/null +++ b/app/components/common/form/number_field/component.rb @@ -0,0 +1,19 @@ +module Common + module Form + module NumberField + class Component < ApplicationViewComponent + + attr_reader :form, :attribute, :options + + def initialize(form:, attribute:, options: {}) + super + + @form = form + @attribute = attribute + + @options = options + end + end + end + end +end diff --git a/app/components/common/form/password_field/component.html.erb b/app/components/common/form/password_field/component.html.erb index 7b39f0ab9..22d1a03dc 100644 --- a/app/components/common/form/password_field/component.html.erb +++ b/app/components/common/form/password_field/component.html.erb @@ -1,2 +1 @@ -<%= @form.label @attribute, @label_caption %> -<%= @form.password_field @attribute, autofocus: @autofocus, autocomplete: @autocomplete %> +<%= @form.password_field @attribute, **@options %> diff --git a/app/components/common/form/password_field/component.rb b/app/components/common/form/password_field/component.rb index 300fe8463..91dc78cb2 100644 --- a/app/components/common/form/password_field/component.rb +++ b/app/components/common/form/password_field/component.rb @@ -3,7 +3,7 @@ module Form module PasswordField class Component < ApplicationViewComponent - attr_reader :form, :attribute, :autocomple, :autofocus, :label_caption + attr_reader :form, :attribute, :options def initialize(form:, attribute:, options:) super @@ -11,9 +11,7 @@ def initialize(form:, attribute:, options:) @form = form @attribute = attribute - @autocomple = options[:autocomple] - @autofocus = options[:autofocus] - @label_caption = options[:label_caption] + @options = options end end end diff --git a/app/components/common/form/telephone_field/component.html.erb b/app/components/common/form/telephone_field/component.html.erb new file mode 100644 index 000000000..fff75061b --- /dev/null +++ b/app/components/common/form/telephone_field/component.html.erb @@ -0,0 +1 @@ +<%= @form.telephone_field @attribute, **@options%> \ No newline at end of file diff --git a/app/components/common/form/checkbox/component.rb b/app/components/common/form/telephone_field/component.rb similarity index 53% rename from app/components/common/form/checkbox/component.rb rename to app/components/common/form/telephone_field/component.rb index d46acfa1f..12fc46b27 100644 --- a/app/components/common/form/checkbox/component.rb +++ b/app/components/common/form/telephone_field/component.rb @@ -1,15 +1,15 @@ module Common module Form - module Checkbox + module TelephoneField class Component < ApplicationViewComponent - attr_reader :label_title, :form, :attribute + attr_reader :attribute, :form, :options - def initialize(label_title:, form:, attribute:) + def initialize(form:, attribute:, options: {}) super - @label_title = label_title @form = form @attribute = attribute + @options = options end end end diff --git a/app/components/common/form/text_field/component.html.erb b/app/components/common/form/text_field/component.html.erb new file mode 100644 index 000000000..891b07bd5 --- /dev/null +++ b/app/components/common/form/text_field/component.html.erb @@ -0,0 +1 @@ +<%= @form.text_field @attribute, **@options %> \ No newline at end of file diff --git a/app/components/common/form/text_field/component.rb b/app/components/common/form/text_field/component.rb new file mode 100644 index 000000000..b264cef1f --- /dev/null +++ b/app/components/common/form/text_field/component.rb @@ -0,0 +1,18 @@ +module Common + module Form + module TextField + class Component < ApplicationViewComponent + + attr_reader :form, :attribute, :options + + def initialize(form:, attribute:, options: {}) + super + + @form = form + @attribute = attribute + @options = options + end + end + end + end +end diff --git a/app/components/common/links/link_button/component.html.erb b/app/components/common/links/link_button/component.html.erb index b01cbe409..e36c9f579 100644 --- a/app/components/common/links/link_button/component.html.erb +++ b/app/components/common/links/link_button/component.html.erb @@ -1,7 +1,7 @@ <% if content.present? %> - <%= link_to @href, class: "c-btn #{colorize} c-btn--icon", data: { **@data_attributes }, target: @target do %> + <%= link_to @href, class: "c-btn #{colorize} c-btn--icon", **@options do %> <%= content %> <% end %> <% else %> - <%= link_to @link_title, @href, class: "c-btn #{colorize} #{@css_class_as_login}", data: { **@data_attributes }, target: @target %> + <%= link_to @link_title, @href, class: "c-btn #{colorize} #{@css_class_as_login}", **@options %> <% end %> diff --git a/app/components/common/links/link_button/component.rb b/app/components/common/links/link_button/component.rb index 955ba7041..b6905b86b 100644 --- a/app/components/common/links/link_button/component.rb +++ b/app/components/common/links/link_button/component.rb @@ -2,17 +2,16 @@ module Common module Links module LinkButton class Component < ApplicationViewComponent - attr_reader :link_title, :href, :color, :data_attributes, :target, :css_class_as_login, :options + attr_reader :link_title, :href, :color, :css_class_as_login, :options - def initialize(link_title:, href:, color: 'green', target: nil, data_attributes: {}, options: {}) + def initialize(link_title: nil, href:, css_class_as_login: false, color: 'green', options: {}) super @link_title = link_title @href = href @color = color - @data_attributes = data_attributes - @target = target - @css_class_as_login = options[:css_class_as_login] ? 'c-btn--login' : '' + @options = options + @css_class_as_login = css_class_as_login ? 'c-btn--login' : '' end def colorize diff --git a/app/components/modals/pay_invoice/component.html.erb b/app/components/modals/pay_invoice/component.html.erb index d8f93d402..8263f14ed 100644 --- a/app/components/modals/pay_invoice/component.html.erb +++ b/app/components/modals/pay_invoice/component.html.erb @@ -28,11 +28,10 @@
<%= form_with model: @invoice, url: invoice_path(@invoice.uuid), data: { controller: 'form--debounce', action: 'change->form--debounce#search', form__debounce_target: 'form' } do |f| %> + <%= component 'common/form/label', form: f, attribute: :billing_profile_id, title: t('billing_profiles_name') %> <%= component 'common/form/dropdown_input', form: f, attribute: :billing_profile_id, enum: options_for_select(BillingProfile.where(user_id: invoice.user_id).pluck(:name, :id), current_billing_profile), - label: t('billing_profiles_name') %> - - <%#= f.submit %> + first_options: { include_blank: false } %> <% end %>
diff --git a/app/components/pages/auction/auction_action_button/component.html.erb b/app/components/pages/auction/auction_action_button/component.html.erb index fded4a7c0..bc9a11491 100644 --- a/app/components/pages/auction/auction_action_button/component.html.erb +++ b/app/components/pages/auction/auction_action_button/component.html.erb @@ -7,7 +7,7 @@ <% else %> <%# if need to create new offer for english auction %> <%= component 'common/links/link_button', link_title: deposit_value[:link_title], href: new_auction_english_offer_path(auction_uuid: auction.uuid), - color: deposit_value[:color], data_attributes: { turbo_frame: 'modal' } %> + color: deposit_value[:color], options: { data: { turbo_frame: 'modal' } } %> <% end %> <% else %> @@ -18,7 +18,7 @@ <% else %> <%# if need to create new offer for blind auction %> <%= component 'common/links/link_button', link_title: t('auctions.bid'), href: new_auction_offer_path(auction_uuid: auction.uuid), - color: 'green', data_attributes: { turbo_frame: 'modal' } %> + color: 'green', options: { data: { turbo_frame: 'modal' } } %> <% end %> <% end %> diff --git a/app/components/pages/auction/auction_action_button/edit_and_remove_blind_offer/component.html.erb b/app/components/pages/auction/auction_action_button/edit_and_remove_blind_offer/component.html.erb index 7e35c50d8..97d99a731 100644 --- a/app/components/pages/auction/auction_action_button/edit_and_remove_blind_offer/component.html.erb +++ b/app/components/pages/auction/auction_action_button/edit_and_remove_blind_offer/component.html.erb @@ -1,10 +1,10 @@
<%= component 'common/links/link_button', link_title: nil, href: edit_offer_path(@auction.users_offer_uuid), - color: 'ghost', data_attributes: { turbo_frame: 'modal' } do %> + color: 'ghost', options: { data: { turbo_frame: 'modal' } } do %> <% end %> - <%= component 'common/buttons/button_to', title_caption: nil, href: offer_path(@auction.offer_from_user(@user).uuid), color: 'ghost', method: :delete, - form_attributes: { data: { turbo_confirm: t(".confirm_delete") } } do %> + <%= component 'common/buttons/button_to', title_caption: nil, href: offer_path(@auction.offer_from_user(@user).uuid), color: 'ghost', + options: { method: :delete, form: { data: { turbo_confirm: t(".confirm_delete") } } } do %> <% end %>
diff --git a/app/components/pages/auction/auction_action_button/edit_english_offer/component.html.erb b/app/components/pages/auction/auction_action_button/edit_english_offer/component.html.erb index 3fa76e540..f35ad3610 100644 --- a/app/components/pages/auction/auction_action_button/edit_english_offer/component.html.erb +++ b/app/components/pages/auction/auction_action_button/edit_english_offer/component.html.erb @@ -1,6 +1,6 @@
<%= component 'common/links/link_button', link_title: nil, href: edit_english_offer_path(@auction.users_offer_uuid), - color: 'ghost', data_attributes: { turbo_frame: 'modal' } do %> + color: 'ghost', options: { data: { turbo_frame: 'modal' } } do %> <% end %>
diff --git a/app/views/invoices/_outstanding_invoices.html.erb b/app/components/pages/invoices/outstanding_invoices/component.html.erb similarity index 69% rename from app/views/invoices/_outstanding_invoices.html.erb rename to app/components/pages/invoices/outstanding_invoices/component.html.erb index ad0c9f77c..ec1f235e1 100644 --- a/app/views/invoices/_outstanding_invoices.html.erb +++ b/app/components/pages/invoices/outstanding_invoices/component.html.erb @@ -25,15 +25,8 @@ - - - <% header_collection = [{ column: nil, caption: t('invoices.item'), options: { class: "" } }, - { column: nil, caption: t('invoices.due_date'), options: { class: "" } }, - { column: nil, caption: t('invoices.total'), options: { class: "" } }, - { column: nil, caption: 'Tegevused', options: { class: "u-text-center-l" } }, - ] %> - <%= component 'common/table', header_collection:, options: { class: '' } do %> + <%= component 'common/table', header_collection: issued_invoice_table_headers, options: { class: '' } do %> <% @issued_invoices.each do |invoice| %> @@ -46,14 +39,10 @@ <% end %>
+
- <% header_collection = [{ column: nil, caption: t('invoices.item'), options: { class: "" } }, - { column: nil, caption: t('invoices.due_date'), options: { class: "" } }, - { column: nil, caption: t('invoices.total'), options: { class: "" } }, - { column: nil, caption: 'Tegevused', options: { class: "u-text-center-l" } }, - ] %> - <%= component 'common/table', header_collection:, options: { class: '' } do %> + <%= component 'common/table', header_collection: overdue_invoice_table_headers, options: { class: '' } do %> <% @cancelled_payable_invoices.each do |invoice| %> <%= link_to invoice&.items&.first&.name, invoice_path(invoice.uuid), title: "Invoice", data: { turbo_frame: 'modal' }, style: "color: black;" %> @@ -67,12 +56,7 @@
- <% header_collection = [{ column: nil, caption: t('invoices.item'), options: { class: "" } }, - { column: nil, caption: t('invoices.due_date'), options: { class: "" } }, - { column: nil, caption: t('invoices.total'), options: { class: "" } }, - { column: nil, caption: 'Tegevused', options: { class: "u-text-center-l" } }, - ] %> - <%= component 'common/table', header_collection:, options: { class: '' } do %> + <%= component 'common/table', header_collection: cancel_invoice_table_headers, options: { class: '' } do %> <% @cancelled_expired_invoices.each do |invoice| %> <%= link_to invoice&.items&.first&.name, invoice_path(invoice.uuid), title: "Invoice", data: { turbo_frame: 'modal' }, style: "color: black;" %> diff --git a/app/components/pages/invoices/outstanding_invoices/component.rb b/app/components/pages/invoices/outstanding_invoices/component.rb new file mode 100644 index 000000000..47f189b25 --- /dev/null +++ b/app/components/pages/invoices/outstanding_invoices/component.rb @@ -0,0 +1,47 @@ +module Pages + module Invoices + module OutstandingInvoices + class Component < ApplicationViewComponent + attr_reader :issued_invoices, :cancelled_payable_invoices, :cancelled_expired_invoices, + :unpaid_invoices_count + + def initialize(issued_invoices:, cancelled_payable_invoices:, cancelled_expired_invoices:, + unpaid_invoices_count:) + super + + @issued_invoices = issued_invoices + @cancelled_payable_invoices = cancelled_payable_invoices + @cancelled_expired_invoices = cancelled_expired_invoices + @unpaid_invoices_count = unpaid_invoices_count + end + + def issued_invoice_table_headers + # NB! if you want make columns as sortable, don't forget to wrap the table content within the turbo_frame_tag + # with the name "results". The name "results" is assigned as a value for the orderable Stimulus controller + # in the table component. + [{ column: nil, caption: t('invoices.item'), options: { class: '' } }, + { column: nil, caption: t('invoices.due_date'), options: { class: '' } }, + { column: nil, caption: t('invoices.total'), options: { class: '' } }, + { column: nil, caption: 'Tegevused', + options: { class: 'u-text-center-l' } }] + end + + def overdue_invoice_table_headers + [{ column: nil, caption: t('invoices.item'), options: { class: '' } }, + { column: nil, caption: t('invoices.due_date'), options: { class: '' } }, + { column: nil, caption: t('invoices.total'), options: { class: '' } }, + { column: nil, caption: 'Tegevused', + options: { class: 'u-text-center-l' } }] + end + + def cancel_invoice_table_headers + [{ column: nil, caption: t('invoices.item'), options: { class: '' } }, + { column: nil, caption: t('invoices.due_date'), options: { class: '' } }, + { column: nil, caption: t('invoices.total'), options: { class: '' } }, + { column: nil, caption: 'Tegevused', + options: { class: 'u-text-center-l' } }] + end + end + end + end +end diff --git a/app/components/pages/invoices/paid_invoices/component.html.erb b/app/components/pages/invoices/paid_invoices/component.html.erb new file mode 100644 index 000000000..e2c67398c --- /dev/null +++ b/app/components/pages/invoices/paid_invoices/component.html.erb @@ -0,0 +1,48 @@ +
+

<%= t('invoices.paid') %>

+
+
+ + + +
+ +
+
+
+ <%= component 'common/table', header_collection: paid_invoices_headers, options: { class: '' } do %> + <% @paid_invoices.each do |invoice| %> + + <%= link_to invoice&.items&.first&.name, invoice_path(invoice.uuid), title: "Invoice", data: { turbo_frame: 'modal' }, style: "color: black;" %> + <%= I18n.l(invoice.due_date) %> + <%= invoice.total %> + <%= link_to t('invoices.show_invoice'), invoice_path(invoice.uuid), class: "c-btn c-btn--ghost js-modal-toggle", title: "Invoice", data: { turbo_frame: 'modal' } %> + + <% end %> + <% end %> +
+
+ +
+
+ <%= component 'common/table', header_collection: deposit_paid_headers, options: { class: '' } do %> + <% @deposit_paid.each do |deposit| %> + + <%= deposit.created_at.strftime("%Y-%m-%d") %> + <%= deposit.auction.deposit %> + <%= deposit.auction.domain_name %> + <%= component 'common/badgets', status: deposit.status %> <%#= t("invoices.paid_deposit.#{deposit.status}") %> + <%= deposit.refund_time %> + + <% end %> + <% end %> +
+
+ +
+
+
diff --git a/app/components/pages/invoices/paid_invoices/component.rb b/app/components/pages/invoices/paid_invoices/component.rb new file mode 100644 index 000000000..0b80e30b9 --- /dev/null +++ b/app/components/pages/invoices/paid_invoices/component.rb @@ -0,0 +1,31 @@ +module Pages + module Invoices + module PaidInvoices + class Component < ApplicationViewComponent + attr_reader :paid_invoices, :deposit_paid + + def initialize(paid_invoices:, deposit_paid:) + super + + @paid_invoices = paid_invoices + @deposit_paid = deposit_paid + end + + def paid_invoices_headers + [{ column: nil, caption: t('invoices.item'), options: { class: '' } }, + { column: nil, caption: t('invoices.due_date'), options: { class: '' } }, + { column: nil, caption: t('invoices.total'), options: { class: '' } }, + { column: nil, caption: 'Tegevused', options: { class: 'u-text-center-l' } }] + end + + def deposit_paid_headers + [{ column: nil, caption: t('invoices.paid_deposit.date'), options: { class: '' } }, + { column: nil, caption: t('invoices.paid_deposit.sum'), options: { class: '' } }, + { column: nil, caption: t('invoices.paid_deposit.auction_name'), options: { class: '' } }, + { column: nil, caption: t('invoices.paid_deposit.status'), options: { class: '' } }, + { column: nil, caption: t('invoices.paid_deposit.refund_time'), options: { class: '' } }] + end + end + end + end +end diff --git a/app/components/pages/offers/blind_auction_offer_table/component.html.erb b/app/components/pages/offers/blind_auction_offer_table/component.html.erb new file mode 100644 index 000000000..fcd6f3c54 --- /dev/null +++ b/app/components/pages/offers/blind_auction_offer_table/component.html.erb @@ -0,0 +1,10 @@ + <%= component 'common/table', header_collection: header_collection, options: { class: 'table--black' } do %> + <%= tag.tbody do %> + + <%= @offer.auction.domain_name %> + 2<%= I18n.l(@offer.auction.ends_at) %> + <%= t('offers.price_in_currency', price: @offer.price) %> + <%= t('offers.price_in_currency', price: @offer.total) %> + + <% end %> + <% end %> diff --git a/app/components/pages/offers/blind_auction_offer_table/component.rb b/app/components/pages/offers/blind_auction_offer_table/component.rb new file mode 100644 index 000000000..beb62d87c --- /dev/null +++ b/app/components/pages/offers/blind_auction_offer_table/component.rb @@ -0,0 +1,22 @@ +module Pages + module Offers + module BlindAuctionOfferTable + class Component < ApplicationViewComponent + attr_reader :offer + + def initialize(offer:) + super + + @offer = offer + end + + def header_collection + [{ column: nil, caption: t('auctions.domain_name'), options: { class: '' } }, + { column: nil, caption: t('auctions.ends_at'), options: { class: '' } }, + { column: nil, caption: t('offers.price'), options: { class: '' } }, + { column: nil, caption: t('offers.total'), options: { class: '' } }] + end + end + end + end +end diff --git a/app/components/pages/offers/english_auction_offer_table/component.html.erb b/app/components/pages/offers/english_auction_offer_table/component.html.erb new file mode 100644 index 000000000..f98d1e885 --- /dev/null +++ b/app/components/pages/offers/english_auction_offer_table/component.html.erb @@ -0,0 +1,58 @@ + +
+
+

<%= t('offers.overview') %>

+ <%= component 'common/table', header_collection: overview_table_headers, options: { class: 'table--black' } do %> + <%= tag.tbody do %> + + <%= @offer.auction.domain_name %> + 2<%= I18n.l(@offer.auction.ends_at) %> + <%= t('offers.price_in_currency', price: @offer.price) %> + <%= t('offers.price_in_currency', price: @offer.total) %> + + <% end %> + <% end %> +
+
+ + + +
+
+
+
+

<%= t('offers.show.participants_title') %>

+ <%= component 'common/table', header_collection: bidder_table_headers, options: { class: '' } do %> + <%= tag.tbody do %> + <% @offer.auction.offers.order(updated_at: :desc).each do |offer| %> + + + <%= offer&.billing_profile&.user_id == current_user.id ? "#{offer.username} (You)" : offer.username %> + + <%= t('offers.price_in_currency', price: offer.price) %> + <%= I18n.l(offer.updated_at) %> + + <% end %> + <% end %> + <% end %> +
+
+

<%= t('offers.show.deposit_title') %>

+ <%= component 'common/table', header_collection: deposit_payment_table_headers, options: { class: '' } do %> + <%= tag.tbody do %> + <% @offer.auction.domain_participate_auctions.each do |d| %> + + + <%= d.user.display_name %> + + <%= I18n.l(d.created_at) %> + + <% end %> + <% end %> + <% end %> + +
+
+
+
+ diff --git a/app/components/pages/offers/english_auction_offer_table/component.rb b/app/components/pages/offers/english_auction_offer_table/component.rb new file mode 100644 index 000000000..8ffe57b8d --- /dev/null +++ b/app/components/pages/offers/english_auction_offer_table/component.rb @@ -0,0 +1,33 @@ +module Pages + module Offers + module EnglishAuctionOfferTable + class Component < ApplicationViewComponent + attr_reader :offer + + def initialize(offer:) + super + + @offer = offer + end + + def overview_table_headers + [{ column: nil, caption: t('auctions.domain_name'), options: { class: '' } }, + { column: nil, caption: t('auctions.ends_at'), options: { class: '' } }, + { column: nil, caption: t('offers.price'), options: { class: '' } }, + { column: nil, caption: t('offers.total'), options: { class: '' } }] + end + + def bidder_table_headers + [{ column: nil, caption: t('offers.show.participants'), options: { class: '' } }, + { column: nil, caption: t('offers.show.your_last_offer'), options: { class: '' } }, + { column: nil, caption: t('offers.show.offers_time'), options: { class: '' } }] + end + + def deposit_payment_table_headers + [{ column: nil, caption: t('offers.show.deposit_participants'), options: { class: '' } }, + { column: nil, caption: t('offers.show.offers_time'), options: { class: '' } }] + end + end + end + end +end diff --git a/app/components/pages/offers/offers_table/component.html.erb b/app/components/pages/offers/offers_table/component.html.erb new file mode 100644 index 000000000..69cae5e0f --- /dev/null +++ b/app/components/pages/offers/offers_table/component.html.erb @@ -0,0 +1,31 @@ + + +
+ <%= form_with url: offers_path, + method: :get, data: { controller: 'form--debounce form--filter', + form__debounce_target: 'form', + form__filter_target: 'form', + turbo_action: "advance", + turbo_frame: "results", + action: 'input->form--debounce#search' + } do |f| %> + + <%# TODO: Add filter and search feature %> + + <% end %> + +
+ + + <%= turbo_frame_tag "results" do %> + + + <%= component 'common/table', header_collection: header_collection, options: { class: 'js-table-dt dataTable no-footer' } do %> + + <%= render @offers %> + <% end %> + <% end %> +
+
diff --git a/app/components/pages/offers/offers_table/component.rb b/app/components/pages/offers/offers_table/component.rb new file mode 100644 index 000000000..48f930aa8 --- /dev/null +++ b/app/components/pages/offers/offers_table/component.rb @@ -0,0 +1,26 @@ +module Pages + module Offers + module OffersTable + class Component < ApplicationViewComponent + attr_reader :offers + + def initialize(offers:) + super + + @offers = offers + end + + def header_collection + [{ column: 'auctions.domain_name', caption: t('auctions.domain_name'), options: { class: 'sorting' } }, + { column: 'auctions.platform', caption: 'Tüüp', options: { class: 'sorting' } }, + { column: 'price', caption: t('.your_last_offer'), options: { class: 'sorting' } }, + { column: nil, caption: t('offers.total'), options: { class: '' } }, + { column: 'auctions.ends_at', caption: t('auctions.ends_at'), + options: { class: 'sorting' } }, + { column: nil, caption: t('result_name'), options: {} }, + { column: nil, caption: t('auctions.offer_actions'), options: {} }] + end + end + end + end +end diff --git a/app/controllers/payment_orders_controller.rb b/app/controllers/payment_orders_controller.rb index 9933cc9e6..234d58dea 100644 --- a/app/controllers/payment_orders_controller.rb +++ b/app/controllers/payment_orders_controller.rb @@ -25,38 +25,6 @@ def show @payment_order.callback_url = callback_payment_order_url(@payment_order.uuid) end - # # ANY /payment_orders/aa450f1a-45e2-4f22-b2c3-f5f46b5f906b/return - # def return - # @payment_order = PaymentOrder.find_by!(uuid: params[:uuid]) - - # if @payment_order.paid? - # respond_to do |format| - # format.html do - # redirect_to invoices_path, notice: t('.already_paid') and return - # end - - # format.json { render json: @payment_order.errors, status: :unprocessable_entity and return } - # end - # end - - # @payment_order.update!(response: params.to_unsafe_h) - - # ResultStatusUpdateJob.perform_later - - # respond_to do |format| - # if @payment_order.mark_invoice_as_paid - # format.html { redirect_to invoices_path, notice: successful_update_notice } - # format.json { redirect_to invoices_path, notice: successful_update_notice } - # else - # format.html do - # redirect_to invoices_path, - # notice: t('.not_successful') - # end - # format.json { render json: @payment_order.errors, status: :unprocessable_entity } - # end - # end - # end - # POST /payment_orders/aa450f1a-45e2-4f22-b2c3-f5f46b5f906b/callback def callback render status: :ok, json: { status: 'ok' } @@ -76,12 +44,6 @@ def create_params params.require(:payment_order).permit(:user_id, :invoice_id, :invoice_ids, :type) end - # def successful_update_notice - # invoice_ids = @payment_order.invoices.map(&:number).join(', ') - # return t('.bulk_update', ids: invoice_ids) if @payment_order.invoices.count > 1 - # t(:updated) - # end - def authorize_user authorize! :read, PaymentOrder authorize! :create, PaymentOrder diff --git a/app/views/auctions/_auction.html.erb b/app/views/auctions/_auction.html.erb index 13e1f21e3..44fb0d0ac 100644 --- a/app/views/auctions/_auction.html.erb +++ b/app/views/auctions/_auction.html.erb @@ -28,7 +28,7 @@ <% if user %> <%= component 'pages/auction/auction_action_button', user: user, auction: auction, updated: updated %> <% else %> - <%= component 'common/links/link_button', link_title: t('auctions.bid'), href: new_user_session_path, color: 'green', target: '_top' %> + <%= component 'common/links/link_button', link_title: t('auctions.bid'), href: new_user_session_path, color: 'green', options: { target: '_top' } %> <% end %> diff --git a/app/views/billing_profiles/_billing_info.html.erb b/app/views/billing_profiles/_billing_info.html.erb index bec2b7abb..1d810f705 100644 --- a/app/views/billing_profiles/_billing_info.html.erb +++ b/app/views/billing_profiles/_billing_info.html.erb @@ -9,9 +9,7 @@ <% end %> - <%= link_to edit_billing_profile_path(billing_profile.uuid), data: { turbo_frame: dom_id(billing_profile) }, class: "c-btn c-btn--ghost c-btn--icon js-edit-modal-toggle" do %> - - <% end %> + <%= component 'common/action_button', type: 'edit', href: edit_billing_profile_path(billing_profile.uuid), options: { data: { turbo_frame: dom_id(billing_profile) }} %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/billing_profiles/index.html.erb b/app/views/billing_profiles/index.html.erb index 76d630f1f..f712323dd 100644 --- a/app/views/billing_profiles/index.html.erb +++ b/app/views/billing_profiles/index.html.erb @@ -1,6 +1,5 @@ <%= component 'common/hero', title: t('.title') %> -
- + diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index ae781b7ea..8bfdc5d7a 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -5,20 +5,25 @@ <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put, class: "o-card" }) do |f| %> <%= f.hidden_field :reset_password_token %> + - <%= f.submit t(:submit), class: 'c-btn c-btn--green', data: { turbo: false } %> + + <%= component 'common/form/form_button', form: f, color: 'green', btn_title: t(:submit), options: { data: { turbo: false } } %> +
<%= link_to t(:sign_in), new_user_session_path, class: "o-link u-mb-8" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 96fe31a95..74cfae58a 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -10,7 +10,7 @@