Skip to content

Commit

Permalink
Marketplace Started on the CRUD actions for delivery_area.
Browse files Browse the repository at this point in the history
- #1136

TODO: finish building create, edit, destroy flows.

Co-authored-by: Zee Spencer <[email protected]>
Co-authored-by: Ana <[email protected]>
Co-authored-by: Dalton Pruitt <[email protected]>
  • Loading branch information
4 people committed Mar 23, 2023
1 parent e8a68ce commit 7ed72a4
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/furniture/marketplace/breadcrumbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
link "Edit", product.location(:edit)
end

crumb :marketplace_delivery_areas do |marketplace|
parent :edit_marketplace, marketplace
link t("marketplace.delivery_areas.index.link_to"), marketplace.location(child: :delivery_areas)
end

crumb :new_delivery_area do |delivery_area|
parent :marketplace_delivery_areas, delivery_area.marketplace
link "Add a Delivery Area", marketplace.location(:new, child: :delivery_area)
end

crumb :marketplace_tax_rates do |marketplace|
parent :edit_marketplace, marketplace
link t("marketplace.tax_rates.index.link_to"), marketplace.location(child: :tax_rates)
Expand Down
10 changes: 10 additions & 0 deletions app/furniture/marketplace/delivery_area.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Marketplace
class DeliveryArea < Record
self.table_name = "marketplace_delivery_areas"
self.location_parent = :marketplace

belongs_to :marketplace, inverse_of: :delivery_areas

monetize :price_cents
end
end
15 changes: 15 additions & 0 deletions app/furniture/marketplace/delivery_area_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Marketplace
class DeliveryAreaPolicy < ApplicationPolicy
alias_method :delivery_area, :object

def create?
person.operator? || person.member_of?(delivery_area.marketplace.space)
end

class Scope < ApplicationScope
def resolve
scope.all
end
end
end
end
6 changes: 6 additions & 0 deletions app/furniture/marketplace/delivery_areas/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= form_with(model: delivery_area.location) do |delivery_area_form| %>
<%= render "text_field", attribute: :label, form: delivery_area_form %>
<%= render "money_field", attribute: :price, form: delivery_area_form, required: true, step: 0.01, min: 0 %>

<%= delivery_area_form.submit %>
<%- end %>
12 changes: 12 additions & 0 deletions app/furniture/marketplace/delivery_areas/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%- breadcrumb(:marketplace_delivery_areas, marketplace) %>

<section class="max-w-2xl self-stretch mx-auto">
<main>
<div class="mt-3 grid grid-cols-1 gap-5 sm:gap-6 sm:grid-cols-2 lg:grid-cols-4">
<%= render delivery_areas %>
</div>
</main>
<footer class="text-center">
<%= link_to(t("marketplace.delivery_areas.new.link_to"), marketplace.location(:new, child: :delivery_area)) %>
</footer>
</section>
2 changes: 2 additions & 0 deletions app/furniture/marketplace/delivery_areas/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%- breadcrumb :new_delivery_area, delivery_area %>
<%= render "form", delivery_area: delivery_area %>
18 changes: 18 additions & 0 deletions app/furniture/marketplace/delivery_areas_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Marketplace
class DeliveryAreasController < Controller
def index
end

def new
delivery_area
end

helper_method def delivery_area
@delivery_area ||= authorize(delivery_areas.new)
end

helper_method def delivery_areas
@delivery_areas ||= policy_scope(marketplace.delivery_areas)
end
end
end
3 changes: 3 additions & 0 deletions app/furniture/marketplace/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

en:
marketplace:
delivery_areas:
index:
link_to: "Delivery Areas"
delivery_window:
edit: "Change Delivery Window"
delivery_info:
Expand Down
1 change: 1 addition & 0 deletions app/furniture/marketplace/marketplace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Marketplace < Furniture
has_many :orders, inverse_of: :marketplace

has_many :tax_rates, inverse_of: :marketplace
has_many :delivery_areas, inverse_of: :marketplace

def has_controller_edit?
true
Expand Down
2 changes: 2 additions & 0 deletions app/furniture/marketplace/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def self.append_routes(router)

router.resources :tax_rates

router.resources :delivery_areas

router.resources :orders, only: [:show, :index]
router.resources :products
router.resource :stripe_account
Expand Down

0 comments on commit 7ed72a4

Please sign in to comment.