Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Dec 7, 2023
1 parent 975906b commit 6a62d4c
Show file tree
Hide file tree
Showing 30 changed files with 634 additions and 297 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= button_to @path, method: :delete, form: { data: { turbo_confirm: t("are_you_sure") } },
class: "c-btn c-btn--ghost c-acount__button c-acount__button--icon", target: '_top' do %>
<%= render 'svg/trash' %>
<span><%= @text %></span>
<% end %>
16 changes: 16 additions & 0 deletions app/components/common/buttons/delete_button_with_text/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Common
module Buttons
module DeleteButtonWithText
class Component < ApplicationViewComponent
attr_reader :path, :text

def initialize(path:, text:)
super

@path = path
@text = text
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<%= @form.check_box @attribute, @options %>
<div class="o-checkbox__slider round"></div>
<label class='o-checkbox' for="checkbox">
<%= @form.check_box @attribute, @options %>
<div class="o-checkbox__slider round"></div>
</label>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<label class="c-account__label-explain" for="<%= "#{@user.class.name.underscore}_password" %>">
<div>
<%= t('users.password') %>
<%= tag.span t('users.form.you_can_leave_blank') if @user.persisted? || (@user.signed_in_with_identity_document? && @user.encrypted_password.blank?) %>
</div>
<%= tag.span t('users.form.password_requirements', minimum: @minimum_password_length) if @minimum_password_length %>
</label>
20 changes: 20 additions & 0 deletions app/components/common/form/password_field/description/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Common
module Form
module PasswordField
module Description
class Component < ApplicationViewComponent
attr_reader :form, :attribute, :minimum_password_length, :user

def initialize(form:, attribute:, minimum_password_length:, user:)
super

@form = form
@attribute = attribute
@minimum_password_length = minimum_password_length
@user = user
end
end
end
end
end
end
4 changes: 4 additions & 0 deletions app/components/common/webpush/setting/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<label class="o-checkbox" for="webpush">
<%= check_box_tag 'webpush', 'yes', false, data: data_data %>
<div class="o-checkbox__slider round"></div>
</label>
16 changes: 16 additions & 0 deletions app/components/common/webpush/setting/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Common
module Webpush
module Setting
class Component < ApplicationViewComponent
def data_data
{
controller: 'profile-webpush',
profile_webpush_target: 'checkbox',
profile_webpush_vapid_public_value: Rails.configuration.customization[:vapid_public],
action: 'change->push-notification#setupPushNotifications'
}
end
end
end
end
end
37 changes: 17 additions & 20 deletions app/components/modals/change_offer/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,47 +35,47 @@
</div>
</div>

<%= form_with model: @autobider, url: autobider_url, remote: true,
data: { turbo_frame: "_top", controller: 'form--autobider-submit form--autobider-validation', form__autobider_submit_target: 'form', form__autobider_validation_bid_min_value: @auction.min_bids_step.to_f },
html: {id: ' autobid_form '} do |f| %>
<%= form_with **autobider_form_properties do |f| %>
<div class="c-modal__grid u-align-center u-flex-wrap u-mt-24 u-mt-48-l">
<%= f.hidden_field :domain_name, value: offer.auction.domain_name %>
<%= f.hidden_field :user_id, value: offer.user_id %>
<label><%= t('english_offers.form.autobidder_value') %></label>

<div class="c-modal__col">
<%= f.number_field :price, min: 0.0, step: 0.01, value: number_with_precision(@autobider.price.to_f,precision: 2),
disabled: @auction.finished? ? true : false, "data-action": "keydown->form--autobider-submit#validatePrice input->form--autobider-submit#validatingInputPrice", "data-form--autobider-submit-target": "price", "data-form--autobider-validation-target": "bidInput" %>
<%= component 'common/form/number_field', form: f, **number_field_properties %>
</div>

<div class="c-modal__col">
<div class="u-flex u-flex-wrap u-flex-gap-12">
<label class="o-checkbox" for="checkbox">
<%= f.check_box :enable, id: 'checkbox', data: { form__autobider_submit_target: 'checkbox', action: 'change->form--autobider-submit#submitAutobider' } %>
<div class="o-checkbox__slider round"></div>
</label>
<span class="u-word-nowrap"><%= t('english_offers.form.autobidder') %>: <strong><%= t('english_offers.form.yep') %></strong></span>
<%= component 'common/form/checkboxes/rounded_checkbox', form: f, **autobider_checkbox_properties %>

<span class="u-word-nowrap">
<%= t('english_offers.form.autobidder') %>: <strong><%= t('english_offers.form.yep') %></strong>
</span>
</div>
</div>
</div>
<% end %>

<%= form_with model: @offer, url: url, id: 'english_offer_form', data: { turbo: false },
data: { controller: 'autotax-counter', autotax_counter_template_value: t('english_offers.price_with_wat_template'),
autotax_counter_tax_value: "#{offer.billing_profile.present? ? offer.billing_profile.vat_rate : 0.0 }",
autotax_counter_defaulttemplate_value: t('offers.price_is_without_vat')} do |f| %>
<%= form_with **offer_form_properties do |f| %>
<%= f.hidden_field :user_id, value: offer.user_id %>
<%= f.hidden_field :auction_id, value: offer.auction_id %>

<div class="c-modal__grid u-flex-wrap u-mt-24 u-mt-48-l">
<div class="c-modal__col">
<label for='min_bids_step'><%= t('english_offers.price') %></label>
<span id="offer_<%=offer.auction.id%>_form">
<%= component 'modals/change_offer/number_form_field', offer_value: @auction.min_bids_step.to_f, offer_disabled: @auction.finished? %>
</span>
</div>

<div class="c-modal__col">
<label><%= t('english_offers.total') %></label>
<span class="c-modal__calculation" data-autotax-counter-target='result'>
<% if offer.billing_profile.present? %>
<%= t('offers.price_with_wat', price: (@auction.min_bids_step.to_f * offer.billing_profile.vat_rate.to_f).to_f + @auction.min_bids_step.to_f, tax: offer.billing_profile.vat_rate * 100) %>
<%= t('offers.price_with_wat',
price: (@auction.min_bids_step.to_f * offer.billing_profile.vat_rate.to_f).to_f + @auction.min_bids_step.to_f,
tax: offer.billing_profile.vat_rate * 100) %>
<% else %>
<%= t('offers.price_is_without_vat') %>
<% end %>
Expand All @@ -84,12 +84,9 @@
</div>
<div class="c-modal__select u-mt-24 ">
<%= f.label :billing_profile, t('.bidder') %>
<%= f.select :billing_profile_id,
billing_profiles = BillingProfile.where(user_id: offer.user_id).collect { |b| [b.name, b.id, {'data-vat-rate' => b.vat_rate}] },
{},
class: billing_profiles.size == 1 ? "disabled" : "",
data: { action: 'change->autotax-counter#updateTax' } %>
<%= component 'common/form/dropdown_input', form: f, **billing_profile_dropdown_properties %>
</div>

<%= link_to t('new_billing_profile'), billing_profiles_path, class: 'c-modal__link c-modal__link--first-col', target: '_top' %>
<% end %>
</div>
Expand Down
77 changes: 77 additions & 0 deletions app/components/modals/change_offer/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,83 @@ def current_price(offer, current_user)
content.html_safe
end
end

def number_field_properties
{
attribute: :price,
options: {
min: 0.0,
step: 0.01,
value: number_with_precision(@autobider.price.to_f, precision: 2),
disabled: is_number_field_disabled?,
data: {
action: 'keydown->form--autobider-submit#validatePrice input->form--autobider-submit#validatingInputPrice',
form__autobider_submit_target: 'price',
form__autobider_validation_target: 'bidInput'
}
}
}
end

def autobider_form_properties
{
model: @autobider,
url: autobider_url,
data: {
turbo_frame: '_top',
controller: 'form--autobider-submit form--autobider-validation',
form__autobider_submit_target: 'form',
form__autobider_validation_bid_min_value: @auction.min_bids_step.to_f
},
html: { id: ' autobid_form ' }
}
end

def autobider_checkbox_properties
{
attribute: :enable,
options: {
id: 'checkbox',
data: {
form__autobider_submit_target: 'checkbox',
action: 'change->form--autobider-submit#submitAutobider'
}
}
}
end

def is_number_field_disabled?
@auction.finished? ? true : false
end

def offer_form_properties
{
model: @offer,
url:,
id: 'english_offer_form',
data: {
turbo: false,
controller: 'autotax-counter',
autotax_counter_template_value: t('english_offers.price_with_wat_template'),
autotax_counter_tax_value: "#{offer.billing_profile.present? ? offer.billing_profile.vat_rate : 0.0}",
autotax_counter_defaulttemplate_value: t('offers.price_is_without_vat')
}
}
end

def billing_profile_dropdown_properties
{
attribute: :billing_profile_id,
enum: billing_profiles = BillingProfile.where(user_id: offer.user_id).collect do |b|
[b.name, b.id, {'data-vat-rate' => b.vat_rate}]
end,
first_options: { },
second_options: {
class: billing_profiles.size == 1 ? "disabled" : "",
data: { action: 'change->autotax-counter#updateTax' }
}
}
end
end
end
end
22 changes: 6 additions & 16 deletions app/components/modals/change_offer_po/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
</div>
</div>

<%= form_with model: @offer, url: url, id: 'english_offer_form', data: { turbo: false },
data: { controller: 'autotax-counter', autotax_counter_template_value: t('english_offers.price_with_wat_template'),
autotax_counter_tax_value: "#{offer.billing_profile.present? ? offer.billing_profile.vat_rate : 0.0 }",
autotax_counter_defaulttemplate_value: t('offers.price_is_without_vat')} do |f| %>
<%= form_with **offer_form_properties do |f| %>
<%= f.hidden_field :user_id, value: offer.user_id %>
<%= f.hidden_field :auction_id, value: offer.auction_id %>
<div class="c-modal__grid u-flex-wrap u-mt-24 u-mt-48-l">
Expand All @@ -44,10 +41,9 @@
<span id="offer_<%=offer.auction.id%>_form">
<%= component 'modals/change_offer/number_form_field', offer_value: current_price, offer_disabled: @auction.finished? %>
</span>
<span class="c-modal__input-desc">
<%= t('.minimum_offer', minimum: Money.new(Setting.find_by(code: 'auction_minimum_offer').retrieve,
Setting.find_by(code: 'auction_currency').retrieve)) %></span>
<span class="c-modal__input-desc"><%= minimum_offer %></span>
</div>

<div class="c-modal__col">
<label>Kokku</label>
<span class="c-modal__calculation" data-autotax-counter-target='result'>
Expand All @@ -61,11 +57,7 @@
</div>
<div class="c-modal__select u-mt-24 ">
<%= f.label :billing_profile, t('.bidder') %>
<%= f.select :billing_profile_id,
billing_profiles = BillingProfile.where(user_id: offer.user_id).collect { |b| [b.name, b.id, {'data-vat-rate' => b.vat_rate}] },
{},
class: billing_profiles.size == 1 ? "disabled" : "",
data: { action: 'change->autotax-counter#updateTax' } %>
<%= component 'common/form/dropdown_input', form: f, **billing_profile_dropdown_properties %>
</div>
<%= link_to t('new_billing_profile'), billing_profiles_path, class: 'c-modal__link c-modal__link--first-col', target: '_top' %>
<% end %>
Expand All @@ -79,11 +71,9 @@
<% if @auction.in_progress? %>
<div class="c-modal__footer__col">

<%= button_to offer_path(@auction.offer_from_user(current_user).uuid), method: :delete, form: { data: { turbo_confirm: t(".confirm_delete") } }, class: "c-btn c-btn--ghost c-btn--icon" do %>
<span class="o-delete-icon"></span>
<% end if @auction.offer_from_user(@current_user).present? %>
<%= component 'common/action_button', **delete_action_button_properties if @auction.offer_from_user(@current_user).present? %>

<%= submit_tag t(:submit), class: "c-btn c-btn--green", id: 'bid_action', form: 'english_offer_form', style: 'cursor: pointer;', data: { turbo: false } %>
<%= submit_tag t(:submit), **submit_form_button_properties %>
</div>
<% end %>

Expand Down
70 changes: 68 additions & 2 deletions app/components/modals/change_offer_po/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,74 @@ def offer_disabled?
end

def current_price
auction.offer_from_user(current_user).present? ? auction.current_price_from_user(current_user) : Money.new(Setting.find_by(code: 'auction_minimum_offer').retrieve)
if auction.offer_from_user(current_user).present?
auction.current_price_from_user(current_user)
else
Money.new(Setting.find_by(code: 'auction_minimum_offer').retrieve)
end
end

def minimum_offer
I18n.t('.minimum_offer', minimum: Money.new(Setting.find_by(code: 'auction_minimum_offer').retrieve,
Setting.find_by(code: 'auction_currency').retrieve))
end

def offer_form_properties
{
model: @offer,
url:,
id: 'english_offer_form',
data: {
turbo: false,
controller: 'autotax-counter',
autotax_counter_template_value: t('english_offers.price_with_wat_template'),
autotax_counter_tax_value: "#{offer.billing_profile.present? ? offer.billing_profile.vat_rate : 0.0}",
autotax_counter_defaulttemplate_value: t('offers.price_is_without_vat')
}
}
end

def billing_profile_dropdown_properties
{
attribute: :billing_profile_id,
enum: billing_profiles = BillingProfile.where(user_id: offer.user_id).collect do |b|
[b.name, b.id, { 'data-vat-rate' => b.vat_rate }]
end,
first_options: {},
second_options: {
class: billing_profiles.size == 1 ? 'disabled' : '',
data: { action: 'change->autotax-counter#updateTax' }
}
}
end

def delete_action_button_properties
{
type: 'delete',
href: offer_path(@auction.offer_from_user(current_user).uuid),
options: {
method: :delete,
form: {
data: {
turbo_confirm: t('.confirm_delete')
}
},
target: '_top'
}
}
end

def submit_form_button_properties
{
class: "c-btn c-btn--green",
id: 'bid_action',
form: 'english_offer_form',
style: 'cursor: pointer;',
data: {
turbo: false
}
}
end
end
end
end
end
1 change: 0 additions & 1 deletion app/models/auction.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Auction < ApplicationRecord # rubocop:disable Metrics
include Presentable
include SqlQueriable
include Searchable
include PgSearch::Model

Expand Down
Loading

0 comments on commit 6a62d4c

Please sign in to comment.