diff --git a/admin/app/components/solidus_admin/properties/index/component.rb b/admin/app/components/solidus_admin/properties/index/component.rb index c7d9b0a699f..391dac2eb69 100644 --- a/admin/app/components/solidus_admin/properties/index/component.rb +++ b/admin/app/components/solidus_admin/properties/index/component.rb @@ -21,11 +21,18 @@ def row_url(property) spree.admin_property_path(property) end + def turbo_frames + %w[ + new_property_modal + ] + end + def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: spree.new_admin_property_path, + href: solidus_admin.new_property_path, + data: { turbo_frame: :new_property_modal }, icon: "add-line", ) end diff --git a/admin/app/controllers/solidus_admin/properties_controller.rb b/admin/app/controllers/solidus_admin/properties_controller.rb index 2b5a54b0f83..7d8cd239c16 100644 --- a/admin/app/controllers/solidus_admin/properties_controller.rb +++ b/admin/app/controllers/solidus_admin/properties_controller.rb @@ -23,6 +23,33 @@ def new end end + def create + @property = Spree::Property.new(property_params) + + if @property.save + respond_to do |format| + flash[:notice] = t('.success') + + format.html do + redirect_to solidus_admin.properties_path, status: :see_other + end + + format.turbo_stream do + render turbo_stream: '' + end + end + else + set_index_page + + respond_to do |format| + format.html do + page_component = component('properties/new').new(page: @page, property: @property) + render page_component, status: :unprocessable_entity + end + end + end + end + def destroy @properties = Spree::Property.where(id: params[:id]) @@ -46,5 +73,9 @@ def set_index_page properties, ) end + + def property_params + params.require(:property).permit(:name, :presentation) + end end end diff --git a/admin/config/locales/properties.en.yml b/admin/config/locales/properties.en.yml index 5bc4aec5cbb..736c66a46ef 100644 --- a/admin/config/locales/properties.en.yml +++ b/admin/config/locales/properties.en.yml @@ -2,5 +2,7 @@ en: solidus_admin: properties: title: "Properties" + create: + success: "Property was successfully created." destroy: success: "Properties were successfully removed." diff --git a/admin/spec/features/properties_spec.rb b/admin/spec/features/properties_spec.rb index a9ca9e12a84..41619c0c225 100644 --- a/admin/spec/features/properties_spec.rb +++ b/admin/spec/features/properties_spec.rb @@ -35,5 +35,19 @@ within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") end + + it "enables creation of a new property" do + within("dialog") do + fill_in "Name", with: "new prop" + fill_in "Presentation", with: "New prop" + + click_on "Add Property" + end + + expect(page).not_to have_selector("dialog") + expect(page).to have_content("Property was successfully created.") + + expect(page).to have_content("New prop") + end end end