-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨
Marketplace
: VendorRepresentative
manages Products
- #2044 OK this should probably be split into a number of smaller steps, each with reasonable test coverage; but I wanted to get something working so we can turn the keys over to the folks at Oaklandia. This makes it so: - A `Neighborhood` `Operator` or `Space` `Member` can add a `VendorRepresentative` to a `Marketplace` - The `VendorRepresentative` can add, remove, and update `Products` YOLO YOLO YOLO
- Loading branch information
Showing
16 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Marketplace | ||
class VendorRepresentative < Record | ||
self.table_name = :marketplace_vendor_representatives | ||
|
||
belongs_to :marketplace, inverse_of: :vendor_representatives | ||
has_one :room, through: :marketplace | ||
belongs_to :person | ||
|
||
attribute :email_address, :string | ||
validates :email_address, uniqueness: true, presence: true | ||
|
||
location(parent: :marketplace) | ||
|
||
def claimed? | ||
person.present? | ||
end | ||
|
||
def claimable? | ||
matching_person.present? | ||
end | ||
|
||
def matching_person | ||
Person.joins(:authentication_methods).find_by(authentication_methods: {contact_location: email_address}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace | ||
class VendorRepresentativePolicy < Policy | ||
alias_method :vendor_representative, :object | ||
def permitted_attributes(_params = nil) | ||
%i[email_address person_id] | ||
end | ||
|
||
def update? | ||
return false unless current_person.authenticated? | ||
|
||
super | ||
end | ||
alias_method :create?, :update? | ||
|
||
def show? | ||
true | ||
end | ||
|
||
class Scope < ApplicationScope | ||
def resolve | ||
scope.all | ||
end | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
app/furniture/marketplace/vendor_representatives/_form.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<%= render CardComponent.new(dom_id: dom_id(vendor_representative)) do %> | ||
<%= form_with model: vendor_representative.location do |f| %> | ||
<%= render "email_field", { attribute: :email_address, form: f } %> | ||
|
||
<%= f.submit %> | ||
<%- end %> | ||
<%- end %> |
35 changes: 35 additions & 0 deletions
35
app/furniture/marketplace/vendor_representatives/index.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<%- breadcrumb :marketplace_vendor_representatives, marketplace %> | ||
|
||
<%= render CardComponent.new do |card| %> | ||
|
||
<%- marketplace.vendor_representatives.each do |vendor_representative| %> | ||
<div class="flex flex-row gap-3"> | ||
<span class="flex-initial"> | ||
<%- if vendor_representative.claimed? %> | ||
✅ | ||
<%- else %> | ||
<%- if vendor_representative.claimable? %> | ||
<%= button_to "👍", vendor_representative.location, method: :put, params: { vendor_representative: { person_id: vendor_representative.matching_person.id } }%> | ||
<%- else %> | ||
<span class="button">🛌</span> | ||
<%- end %> | ||
<%- end %> | ||
</span> | ||
<span class="flex-grow"> | ||
<%= vendor_representative.email_address %> | ||
</span> | ||
<span class="flex-initial"> | ||
<%- if policy(vendor_representative).destroy? %> | ||
<%= button_to "🗑️", vendor_representative.location, method: :delete %> | ||
<%- end %> | ||
</span> | ||
</div> | ||
<%- end %> | ||
|
||
<%- card.with_footer(variant: :action_bar) do %> | ||
<%- new_vendor_representative = marketplace.vendor_representatives.new %> | ||
<%- if policy(new_vendor_representative).create? %> | ||
<%= link_to t("marketplace.vendor_representatives.new.link_to"), marketplace.location(:new, child: :vendor_representative), class: "button w-full" %> | ||
<%- end %> | ||
<%- end %> | ||
<%- end %> |
3 changes: 3 additions & 0 deletions
3
app/furniture/marketplace/vendor_representatives/new.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%- breadcrumb :new_marketplace_vendor_representative, vendor_representative %> | ||
|
||
<%= render "form", vendor_representative: vendor_representative %> |
45 changes: 45 additions & 0 deletions
45
app/furniture/marketplace/vendor_representatives_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace | ||
class VendorRepresentativesController < Controller | ||
expose :vendor_representative, scope: -> { vendor_representatives }, model: VendorRepresentative | ||
expose :vendor_representatives, -> { policy_scope(marketplace.vendor_representatives) } | ||
|
||
def new | ||
authorize(vendor_representative) | ||
end | ||
|
||
def create | ||
authorize(vendor_representative).save | ||
|
||
if vendor_representative.persisted? | ||
redirect_to marketplace.location(child: :vendor_representatives), notice: t(".success", name: vendor_representative.email_address) | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def index | ||
skip_authorization | ||
end | ||
|
||
def update | ||
if authorize(vendor_representative).update(vendor_representative_params) | ||
redirect_to marketplace.location(child: :vendor_representatives), notice: t(".success", name: vendor_representative.email_address) | ||
|
||
else | ||
redirect_to marketplace.location(child: :vendor_representatives), notice: t(".failure", name: vendor_representative.email_address) | ||
|
||
end | ||
end | ||
|
||
def destroy | ||
authorize(vendor_representative).destroy | ||
redirect_to marketplace.location(child: :vendor_representatives), notice: t(".success", name: vendor_representative.email_address) | ||
end | ||
|
||
def vendor_representative_params | ||
policy(VendorRepresentative).permit(params.require(:vendor_representative)) | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
db/migrate/20240207040004_marketplace_create_vendor_representatives.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class MarketplaceCreateVendorRepresentatives < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :marketplace_vendor_representatives, id: :uuid do |t| | ||
t.references :marketplace, type: :uuid, foreign_key: {to_table: :furnitures} | ||
t.references :person, type: :uuid, foreign_key: true, null: true | ||
|
||
t.string :email_address | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters