Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change redirect option after domain creation #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% @contact_group.each do |setting| %>
<% if setting.format == 'array' and setting.code == 'code_of_technical_contact' %>
<%= component 'settings/tech_contact_field', form: form, setting: setting %>
<% else %>
<fieldset class="space-y-5">
<%= component 'form/checkbox_with_description', form: form, attribute: "[settings][#{setting.id}", label_name: setting.code, description: setting.description, value: setting.value == 'true' %>
</fieldset>
<% end %>
<% end %>
14 changes: 14 additions & 0 deletions app/components/admin/settings/contact_group/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Admin
module Settings
module ContactGroup
class Component < ApplicationViewComponent
attr_reader :contact_group, :form

def initialize(contact_group:, form:)
@contact_group = contact_group
@form = form
end
end
end
end
end
15 changes: 15 additions & 0 deletions app/components/admin/settings/invoice_group/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% @invoice_group.each do |setting| %>
<div class='flex items-center space-y-2'>

<div class='w-52'>
<%= form.label setting.code, class: 'block text-sm font-bold text-gray-700' %>
</div>
<div class="relative mt-1 rounded-md shadow-md border border-gray-300 w-96">
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
<%= heroicon 'cog', variant: :solid, options: { class: 'h-5 w-5 text-gray-400' } %>
</div>
<%= form.text_field "[settings][#{setting.id}", placeholder: t(".#{setting.code}"), value: setting.value, class: 'block w-full rounded-md border-gray-300 pl-10 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm py-2' %>
</div>
<%= form.hidden_field :id, value: "[settings][#{setting.id}" %>
</div>
<% end %>
14 changes: 14 additions & 0 deletions app/components/admin/settings/invoice_group/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Admin
module Settings
module InvoiceGroup
class Component < ApplicationViewComponent
attr_reader :invoice_group, :form

def initialize(invoice_group:, form:)
@invoice_group = invoice_group
@form = form
end
end
end
end
end
32 changes: 32 additions & 0 deletions app/components/admin/settings/registrar_group/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<% @registrar_group.each do |setting| %>

<div class='flex items-center space-y-2'>
<div class='w-52'>
<%= form.label setting.code, class: 'block text-sm font-bold text-gray-700' %>
</div>
<% if setting.format == 'array' and setting.code == 'default_nameserver_records' %>
<%= component 'settings/array_field', form: form, setting: setting %>

<% elsif setting.format == 'hash' %>
<%= component 'settings/hash_field', form: form, setting: setting %>

<% elsif setting.format == 'boolean' %>

<fieldset class="space-y-5">
<%= component 'form/checkbox_with_description', form: form, attribute: "[settings][#{setting.id}", label_name: setting.code, description: setting.description, value: setting.value == 'true' %>
</fieldset>

<% else %>

<div class="relative mt-1 rounded-md shadow-md border border-gray-300 w-96">
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
<%= heroicon 'cog', variant: :solid, options: { class: 'h-5 w-5 text-gray-400' } %>
</div>
<%= form.text_field "[settings][#{setting.id}", placeholder: t(".#{setting.code}"), value: setting.value, class: 'block w-full rounded-md border-gray-300 pl-10 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm py-2' %>
</div>

<% end %>

<%= form.hidden_field :id, value: "[settings][#{setting.id}" %>
</div>
<% end %>
14 changes: 14 additions & 0 deletions app/components/admin/settings/registrar_group/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Admin
module Settings
module RegistrarGroup
class Component < ApplicationViewComponent
attr_reader :registrar_group, :form

def initialize(registrar_group:, form:)
@registrar_group = registrar_group
@form = form
end
end
end
end
end
4 changes: 2 additions & 2 deletions app/components/form_domain_contact/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class='flex flex-col items-start space-y-2 p-3 hidden' data-form--add-element-target="list" data-behaviour--hiddenable-target="elements">
<% tech_form.fields_for :contact, domain_contact.contact do |contact_form| %>

<%= render 'contact_fields', form: contact_form, remove_button: false %>
<%= render 'contact_fields', form: contact_form, remove_button: false, contact_type: contact_type %>

<% end %>
</div>
Expand All @@ -34,7 +34,7 @@
<%= form.fields_for contact_type_objects.to_sym, constanicize_contact_type.new, child_index: "new_contact" do |builder| %>
<% builder.fields_for :contact, Contact.new do |contact_form| %>

<%= render 'contact_fields', form: contact_form, remove_button: true %>
<%= render 'contact_fields', form: contact_form, remove_button: true, contact_type: contact_type %>
<% end %>
<% end %>
</div>
Expand Down
48 changes: 48 additions & 0 deletions app/components/settings/array_field/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div class="flex flex-col w-full" data-controller="form--add-element behaviour--hiddenable" data-form--add-element-child-index-value="new_contact"
data-behaviour--hiddenable-props-class='hidden' data-form--add-element-limit-of-elements=9
data-form--add-element-current-elements-value="<%= @parsed_data.count %>">

<div data-form--add-element-target="list">
<% @parsed_data.each_with_index do |item, index| %>

<div class='flex space-y-2 space-x-2 justify-center items-center' data-controller='behaviour--removeable'>
<% item.each do |k, v| %>
<%= form.label k, "#{k.to_s.humanize} #{index + 1}", class: 'block text-sm font-medium text-gray-700 w-64' %>
<%= form.text_field "settings[#{setting.id}][][#{k}]", value: v, class: 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' %>
<% end %>

<a class='cursor-pointer rounded-full p-1 bg-red-400 hover:bg-red-600 w-8 text-white' data-action="behaviour--removeable#remove">
delete
</a>
</div>
<% end %>
</div>


<div class='text-right'>
<a class='rounded-md bg-green-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-green-500
focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-green-600 cursor-pointer add-contact-button'
data-action="click->form--add-element#addElement"><%= t('.add_contact') %></a>
</div>

<template id="new-contact-template" data-form--add-element-target="template">
<% if setting.code == 'default_nameserver_records' %>
<div class='flex space-y-2 space-x-2 justify-center items-center' data-controller='behaviour--removeable'>
<%= form.label :hostname, "Hostname", class: 'block text-sm font-medium text-gray-700 w-64' %>
<%= form.text_field "settings[#{setting.id}][][hostname]", class: 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' %>

<%= form.label :ipv4, "ipv4", class: 'block text-sm font-medium text-gray-700 w-64' %>
<%= form.text_field "settings[#{setting.id}][][ipv4]", class: 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' %>

<%= form.label :ipv6, "ipv6", class: 'block text-sm font-medium text-gray-700 w-64' %>
<%= form.text_field "settings[#{setting.id}][][ipv6]", class: 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' %>

<div class='p2 w-16'>
<a class='cursor-pointer rounded-full p-1 bg-red-400 hover:bg-red-600 w-8 text-white' data-action="behaviour--removeable#remove">
delete
</a>
</div>
</div>
<% end %>
</template>
</div>
13 changes: 13 additions & 0 deletions app/components/settings/array_field/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Settings
module ArrayField
class Component < ApplicationViewComponent
attr_reader :setting, :form

def initialize(setting:, form:)
@setting = setting
@form = form
@parsed_data = eval(setting.value)
end
end
end
end
8 changes: 8 additions & 0 deletions app/components/settings/hash_field/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class='flex flex-col space-y-2 space-x-2 justify-center items-center'>

<% @parsed_value.each do |k, v| %>
<%= form.label k.to_sym, k.to_s.humanize, class: 'block text-sm font-medium text-gray-700 w-64' %>
<%= form.text_field "settings[#{setting.id}][#{k}]", value: v, class: 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' %>
<% end %>

</div>
13 changes: 13 additions & 0 deletions app/components/settings/hash_field/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Settings
module HashField
class Component < ApplicationViewComponent
attr_reader :setting, :form

def initialize(setting:, form:)
@setting = setting
@form = form
@parsed_value = eval(setting.value)
end
end
end
end
79 changes: 79 additions & 0 deletions app/components/settings/tech_contact_field/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<style>
.dropdown-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 10rem;
padding: 0.5rem 0;
margin: 0.125rem 0 0;
font-size: 1rem;
color: #212529;
text-align: left;
background-color: #fff;
background-clip: padding-box;
border: 1px solid rgba(0,0,0,.15);
border-radius: .25rem;
}

.dropdown-menu li {
padding: .5rem 1rem;
cursor: pointer;
}

.dropdown-menu li:hover {
background-color: #f8f9fa;
}
</style>


<div class="flex flex-col w-full" data-controller="form--add-element behaviour--hiddenable" data-form--add-element-child-index-value="new_contact"
data-behaviour--hiddenable-props-class='hidden' data-form--add-element-limit-of-elements=9
data-form--add-element-current-elements-value="<%= @parsed_data&.count %>">

<div data-form--add-element-target="list">
<% @parsed_data.each_with_index do |item, index| %>

<div class='flex space-y-2 space-x-2 justify-center items-center' data-controller='behaviour--removeable form--autocomplete' data-form--autocomplete-search-url-value="<%= admin_contacts_searches_path %>" data-form--autocomplete-set-code-value="true">
<%= form.label "tech contact code #{index}", class: 'block text-sm font-medium text-gray-700 w-64' %>

<%= component 'form/autocomplete_input', form: form, attribute: :value, heroicon_name: 'user', placeholder: 'ABC:123',
data_attributes: { action: "input->form--autocomplete#search", form__autocomplete_target: "input" },
value: item %>

<%= form.hidden_field "settings[#{setting.id}][]", data: { form__autocomplete_target: "hiddenInput" }, value: item %>

<a class='cursor-pointer rounded-full p-1 bg-red-400 hover:bg-red-600 w-8 text-white' data-action="behaviour--removeable#remove">
delete
</a>
</div>
<% end %>
</div>


<div class='text-right'>
<a class='rounded-md bg-green-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-green-500
focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-green-600 cursor-pointer add-contact-button'
data-action="click->form--add-element#addElement"><%= t('.add_contact') %></a>
</div>

<template id="new-contact-template" data-form--add-element-target="template">
<div class='flex space-y-2 space-x-2 justify-center items-center' data-controller='behaviour--removeable form--autocomplete' data-form--autocomplete-search-url-value="<%= admin_contacts_searches_path %>" data-form--autocomplete-set-code-value="true">
<%= form.label "tech contact code 1", class: 'block text-sm font-medium text-gray-700 w-64' %>

<%= component 'form/autocomplete_input', form: form, attribute: :value, heroicon_name: 'user', placeholder: 'ABC:123',
data_attributes: { action: "input->form--autocomplete#search", form__autocomplete_target: "input" },
value: nil %>

<%= form.hidden_field "settings[#{setting.id}][]", data: { form__autocomplete_target: "hiddenInput" } %>

<div class='p2 w-16'>
<a class='cursor-pointer rounded-full p-1 bg-red-400 hover:bg-red-600 w-8 text-white' data-action="behaviour--removeable#remove">
delete
</a>
</div>
</div>
</template>
</div>
13 changes: 13 additions & 0 deletions app/components/settings/tech_contact_field/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Settings
module TechContactField
class Component < ApplicationViewComponent
attr_reader :setting, :form

def initialize(setting:, form:)
@setting = setting
@form = form
@parsed_data = eval(setting.value)
end
end
end
end
21 changes: 21 additions & 0 deletions app/controllers/admin/contacts/searches_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Admin
module Contacts
class SearchesController < ApplicationController
include Roles::AdminAbilitable

def show
puts '----'
puts params[:query]
puts '-----'

@contacts = Contact.search(params[:query])

puts '==== contacts'
puts @contacts.inspect
puts '====='

render json: @contacts.limit(5).map(&:as_json)
end
end
end
end
19 changes: 5 additions & 14 deletions app/controllers/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,18 @@ class SettingsController < ApplicationController
def show
@invoice_group = Setting.with_group('invoice')
@contact_group = Setting.with_group('contacts')
@registrar_group = Setting.with_group('registrar')
end

def update
if Setting.update(casted_settings.keys, casted_settings.values)
updated, errors = Admin::SettingUpdaterService.new(params).update

if updated
redirect_to root_path, status: :see_other, notice: t('.success')
else
flash[:alert] = update.errors.values.uniq.join(', ')
flash[:alert] = errors.uniq.join(', ')
render :show, status: :unprocessable_entity
end
end

private

def casted_settings
settings = {}

params[:settings].each do |k, v|
settings[k] = { value: v }
end

settings
end
end
end
18 changes: 10 additions & 8 deletions app/controllers/registrant/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def new
@domain = Domain.new

Tld::Estonian::MIN_DOMAIN_CONTACT_COUNT.times do |i|
admin_contact = Contact.find_by(code: current_user.code)
tech_contact = Contact.find_by(code: Setting.code_of_technical_contact)
admin_contact = Contact.find_by(code: current_user.code, role: :priv)
tech_contact = Contact.find_by(code: Setting.code_of_technical_contact || current_user.code)

if i % 2 == 0
@domain.admin_domain_contacts.build(contact: admin_contact)
Expand Down Expand Up @@ -79,13 +79,15 @@ def create
@invoice = pending.create_invoice_by_pending_action(domain_price.price.to_f)

if @invoice
flash.now[:notice] = t('.success')
flash[:notice] = t('.success')

render turbo_stream: [
turbo_stream.append('flash', partial: 'layouts/flash'),
turbo_stream.append('payment_method', partial: 'registrant/domains/payment_form',
locals: { invoice: @invoice})
]
redirect_to registrant_domains_path, status: :see_other

# render turbo_stream: [
# turbo_stream.append('flash', partial: 'layouts/flash'),
# turbo_stream.append('payment_method', partial: 'registrant/domains/payment_form',
# locals: { invoice: @invoice})
# ]
else
flash[:alert] = @invoice.errors.full_messages
render turbo_stream: turbo_stream.replace('flash', partial: 'layouts/flash')
Expand Down
Loading
Loading