-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🥔✨
Marketplace
: UI to manage OrderNotificationMethod
- #1511
- Loading branch information
Showing
13 changed files
with
186 additions
and
1 deletion.
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
11 changes: 11 additions & 0 deletions
11
app/furniture/marketplace/order_notification_method_component.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,11 @@ | ||
<%= render CardComponent.new(dom_id: dom_id(order_notification_method), classes: "flex flex-col justify-between gap-y-2 w-full") do %> | ||
|
||
<div class="font-bold"> | ||
<%= contact_location %> | ||
</div> | ||
|
||
<footer class="mt-3 flex flex-row justify-between"> | ||
<%= render edit_button if edit_button? %> | ||
<%= render destroy_button if destroy_button? %> | ||
</footer> | ||
<%- end %> |
36 changes: 36 additions & 0 deletions
36
app/furniture/marketplace/order_notification_method_component.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,36 @@ | ||
class Marketplace | ||
class OrderNotificationMethodComponent < ApplicationComponent | ||
attr_accessor :order_notification_method | ||
delegate :contact_location, to: :order_notification_method | ||
|
||
def initialize(order_notification_method:, **kwargs) | ||
super(**kwargs) | ||
|
||
self.order_notification_method = order_notification_method | ||
end | ||
|
||
def edit_button | ||
super(title: t("marketplace.order_notification_methods.edit.link_to", contact_location: contact_location), | ||
href: order_notification_method.location(:edit)) | ||
end | ||
|
||
def edit_button? | ||
order_notification_method.persisted? && policy(order_notification_method).edit? | ||
end | ||
|
||
def destroy_button | ||
return unless destroy_button? | ||
|
||
ButtonComponent.new(label: "#{t("icons.destroy")} #{t("destroy.link_to")}", | ||
title: t("marketplace.order_notification_methods.destroy.link_to", contact_location: contact_location), | ||
href: order_notification_method.location, turbo_stream: true, | ||
method: :delete, | ||
confirm: t("destroy.confirm"), | ||
scheme: :secondary) | ||
end | ||
|
||
def destroy_button? | ||
order_notification_method.persisted? && policy(order_notification_method).destroy? | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
app/furniture/marketplace/order_notification_method_policy.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,7 @@ | ||
class Marketplace | ||
class OrderNotificationMethodPolicy < Policy | ||
def permitted_attributes(_) | ||
[:contact_location] | ||
end | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
app/furniture/marketplace/order_notification_methods/_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,6 @@ | ||
<%= form_with(model: order_notification_method.location) do |form| %> | ||
<%= render "email_field", attribute: :contact_location, form: form %> | ||
<%= form.submit %> | ||
<%- end %> |
2 changes: 2 additions & 0 deletions
2
app/furniture/marketplace/order_notification_methods/edit.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,2 @@ | ||
<%- breadcrumb :edit_marketplace_order_notification_method, order_notification_method %> | ||
<%= render "form", order_notification_method: order_notification_method %> |
23 changes: 23 additions & 0 deletions
23
app/furniture/marketplace/order_notification_methods/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,23 @@ | ||
<%- breadcrumb(:marketplace_order_notification_methods, marketplace) %> | ||
<%= render Marketplace::ManagementComponent.new(marketplace: marketplace) do %> | ||
<section class="mt-3"> | ||
<main> | ||
|
||
<%= render Marketplace::OrderNotificationMethodComponent.with_collection(order_notification_methods) %> | ||
|
||
</main> | ||
|
||
<div class="text-center mt-3"> | ||
<%- order_notification_methods = marketplace.order_notification_methods.new %> | ||
<%- if policy(order_notification_methods).create? %> | ||
<%= render ButtonComponent.new( | ||
label: "#{t('marketplace.order_notification_methods.new.link_to')} #{t('icons.new')}", | ||
title: t('marketplace.order_notification_methods.new.link_to'), | ||
href: marketplace.location(:new, child: :order_notification_method), | ||
method: :get, | ||
scheme: :secondary) %> | ||
<%- end %> | ||
</div> | ||
</section> | ||
<% end %> |
2 changes: 2 additions & 0 deletions
2
app/furniture/marketplace/order_notification_methods/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,2 @@ | ||
<%- breadcrumb :new_marketplace_order_notification_method, order_notification_method %> | ||
<%= render "form", order_notification_method: order_notification_method %> |
59 changes: 59 additions & 0 deletions
59
app/furniture/marketplace/order_notification_methods_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,59 @@ | ||
class Marketplace | ||
class OrderNotificationMethodsController < Controller | ||
def new | ||
order_notification_method | ||
end | ||
|
||
def edit | ||
order_notification_method | ||
end | ||
|
||
def update | ||
if order_notification_method.update(order_notification_method_params) | ||
redirect_to marketplace.location(child: :order_notification_methods), notice: t(".success", contact_location: order_notification_method.contact_location) | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def create | ||
if order_notification_method.save | ||
redirect_to marketplace.location(child: :order_notification_methods) | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def destroy | ||
order_notification_method.destroy | ||
|
||
respond_to do |format| | ||
format.turbo_stream do | ||
if order_notification_method.destroyed? | ||
render turbo_stream: turbo_stream.remove(order_notification_method) | ||
else | ||
render turbo_stream: turbo_stream.replace(order_notification_method) | ||
end | ||
end | ||
end | ||
end | ||
|
||
helper_method delegate :order_notification_methods, to: :marketplace | ||
|
||
helper_method def order_notification_method | ||
if params[:id] | ||
order_notification_methods.find(params[:id]) | ||
elsif params[:order_notification_method] | ||
order_notification_methods.new(order_notification_method_params) | ||
else | ||
order_notification_methods.new | ||
end.tap do |order_notification_method| | ||
authorize(order_notification_method) | ||
end | ||
end | ||
|
||
def order_notification_method_params | ||
policy(OrderNotificationMethod).permit(params.require(:order_notification_method)) | ||
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