Skip to content

Commit

Permalink
Unselect a Seat to remove it from visitor's Cart
Browse files Browse the repository at this point in the history
For comparison [see this commit][commit]

Nothing exciting here. The ergonomics is similar to the Stimulus version. We
continue to make use of `ButtonTo` and `form_props` to bring over the
conveniences of Rails to React.

[form_props]: https://github.com/thoughtbot/form_props
[commit]: seanpdoyle@3cd6b13
  • Loading branch information
jho406 committed Oct 8, 2023
1 parent 918fd12 commit 428af14
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/components/Cart.js
@@ -1,17 +1,18 @@
import React from 'react'
import SVG from 'react-inlinesvg';
import closeSvg from '../assets/images/icons/x-circle.svg'
import ButtonTo from './ButtonTo'

export default class extends React.Component {
render () {
const cartItems = this.props.cart.map(({rowNumber, price, removeSvg, id}) => (
const cartItems = this.props.cart.map(({rowNumber, price, removeSeatForm, id}) => (
<tr key={id}>
<td> {rowNumber} </td>
<td className="syos-table__cell--numerals"> {price} </td>
<td className="syos-u-text-align-right">
<button className="syos-button syos-button--transparent">
<ButtonTo {...removeSeatForm} className="syos-button syos-button--transparent">
<SVG src={ closeSvg } className="syos-icon" title="Remove"/>
</button>
</ButtonTo>
</td>
</tr>
))
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/selections_controller.rb
Expand Up @@ -6,4 +6,12 @@ def create

redirect_to venue_floor_seats_url(seat.venue, seat.floor)
end

def destroy
seat = Seat.find(params[:seat_id])

Current.cart.seat_selections.where(seat_id: seat).destroy_all

redirect_to venue_floor_seats_url(seat.venue, seat.floor)
end
end
3 changes: 3 additions & 0 deletions app/views/seats/_cart.json.props
Expand Up @@ -2,4 +2,7 @@ json.array! Current.cart.seats do |seat|
json.id seat.id
json.row_number seat.row_number
json.price number_to_currency(seat.section.price / 100.0)
json.removeSeatForm do
form_props(url: seat_selection_path(seat), method: :delete)
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -8,6 +8,7 @@

resources :seats, only: [] do
resources :selections, only: [:create]
resource :selection, only: [:destroy]
end

root to: redirect("/venues/benedum_center/floors/orchestra/seats")
Expand Down
11 changes: 11 additions & 0 deletions test/controllers/selections_controller_test.rb
Expand Up @@ -19,4 +19,15 @@ class SelectionsControllerTest < ActionDispatch::IntegrationTest

assert_equal cart.seats.ids, [seat.id]
end

test "#destroy when a Seat is already selected" do
seat_selection = create(:seat_selection)
cart = seat_selection.cart
seat = seat_selection.seat
cookies[:cart_token] = cart.token

delete seat_selection_path(seat, seat_selection)

assert_equal cart.seats.ids, []
end
end
18 changes: 18 additions & 0 deletions test/system/visitor_unselects_seat_test.rb
@@ -0,0 +1,18 @@
require "application_system_test_case"

class VisitorUnselectsSeatTest < ApplicationSystemTestCase
test "visiting the seat page" do
venue = create(:benedum_center)
floor = create(:orchestra, venue: venue)
section = create(:section, floor: floor, price: 10_00)
seat = create(:seat, row: "AA", number: "101", section: section)

visit "/venues/benedum_center/floors/orchestra/seats/AA-101"
click_on "Select"
click_on "Remove"

within "#cart-summary" do
assert_no_text "$10.00"
end
end
end

0 comments on commit 428af14

Please sign in to comment.