Skip to content

Commit

Permalink
Add create action on properties controller
Browse files Browse the repository at this point in the history
This completes the ability to create a new product property in the new
admin UI.

Co-authored-by: Harmony Evangelina <[email protected]>
  • Loading branch information
forkata and harmonymjb committed Nov 14, 2024
1 parent bb3b2a7 commit b2ea1b7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions admin/app/controllers/solidus_admin/properties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<turbo-stream action="refresh" />'
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])

Expand All @@ -46,5 +73,9 @@ def set_index_page
properties,
)
end

def property_params
params.require(:property).permit(:name, :presentation)
end
end
end
2 changes: 2 additions & 0 deletions admin/config/locales/properties.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ en:
solidus_admin:
properties:
title: "Properties"
create:
success: "Property was successfully created."
destroy:
success: "Properties were successfully removed."
14 changes: 14 additions & 0 deletions admin/spec/features/properties_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b2ea1b7

Please sign in to comment.