From c7f78f90e870033afc08bc79bee78a872f5f5244 Mon Sep 17 00:00:00 2001 From: LengTech11 Date: Fri, 29 Nov 2024 11:14:57 +0700 Subject: [PATCH] close #2103 add check_in and uncheck_in to admin order_guest --- .../spree/admin/guests_controller.rb | 42 ++++++++++++++-- .../admin/guests/_check_in_status.html.erb | 50 +++++++++++++++++++ app/views/spree/admin/guests/edit.html.erb | 37 +++++++++++++- config/routes.rb | 4 ++ 4 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 app/views/spree/admin/guests/_check_in_status.html.erb diff --git a/app/controllers/spree/admin/guests_controller.rb b/app/controllers/spree/admin/guests_controller.rb index e76ae98a6..b63e5f6e1 100644 --- a/app/controllers/spree/admin/guests_controller.rb +++ b/app/controllers/spree/admin/guests_controller.rb @@ -5,6 +5,7 @@ class GuestsController < Spree::Admin::ResourceController helper SpreeCmCommissioner::Admin::GuestHelper before_action :load_order + before_action :load_guest, only: %i[check_in uncheck_in edit update destroy] def model_class SpreeCmCommissioner::Guest @@ -35,21 +36,52 @@ def remove_guest end end - def new - @line_item = @order.line_items.find(params[:line_item_id]) - @kyc_fields = @line_item.kyc_fields + def edit + @check_in = @guest.check_in end - def edit - @kyc_fields = @object.line_item.kyc_fields + def check_in + result = SpreeCmCommissioner::CheckInBulkCreator.call( + check_ins_attributes: [{ guest_id: @guest.id }], + check_in_by: spree_current_user + ) + + if result.success? + flash[:success] = "Guest #{@guest.full_name} has been checked in." + else + flash[:error] = result.message.to_s.titleize + end + + redirect_to collection_url + end + + def uncheck_in + result = SpreeCmCommissioner::CheckInDestroyer.call( + guest_ids: [@guest.id], + destroyed_by: spree_current_user + ) + + if result.success? + flash[:success] = "Guest #{@guest.full_name} has been unchecked." + else + flash[:error] = result.message.to_s.titleize + end + + redirect_to collection_url end + private + def permitted_resource_params params.require(object_name).permit(:first_name, :last_name, :gender, :dob, :occupation_id, :nationality_id, :age, :emergency_contact, :line_item_id, :seat_number, :phone_number ) end + + def load_guest + @guest = @order.guests.find(params[:id]) + end end end end diff --git a/app/views/spree/admin/guests/_check_in_status.html.erb b/app/views/spree/admin/guests/_check_in_status.html.erb new file mode 100644 index 000000000..6eb8ba42d --- /dev/null +++ b/app/views/spree/admin/guests/_check_in_status.html.erb @@ -0,0 +1,50 @@ +
+
+

<%= Spree.t(:check_in_states) %>

+
+ <% if @check_in.present? %> + + + + + <% else %> +
+ <%= Spree.t(:no_check_in_found) %> +
+ <% end %> +
diff --git a/app/views/spree/admin/guests/edit.html.erb b/app/views/spree/admin/guests/edit.html.erb index c715fc7dc..cf4341b8a 100644 --- a/app/views/spree/admin/guests/edit.html.erb +++ b/app/views/spree/admin/guests/edit.html.erb @@ -1,8 +1,43 @@ <% content_for :page_title do %> -<%= link_to plural_resource_name(SpreeCmCommissioner::Guest), spree.admin_order_guests_url(@order) %> / + <%= link_to plural_resource_name(SpreeCmCommissioner::Guest), spree.admin_order_guests_url(@order) %> / <%= Spree.t(:guest_infomation) %> <% end %> +<% content_for(:sidebar) do %> + <% if @guest.check_in.present? %> + <%= render partial: 'check_in_status' %> + <% else %> +
+
+
<%= Spree.t(:check_in_status) %>
+

Click button below to manually check_in guest

+ <%= link_to 'Check In', check_in_admin_order_guest_path(@order, @guest), method: :post, class: 'btn btn-outline-primary' %> +
+
+ <% end %> +<% end %> + + + + <%= form_with model: @object, url: { action: 'update' }, html: { multipart: true } do |f| %>
<%= render partial: 'form', locals: { f: f } %> diff --git a/config/routes.rb b/config/routes.rb index 9c1157e77..e26ae3cf4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -240,6 +240,10 @@ post :add_guest delete :remove_guest end + member do + post :check_in + post :uncheck_in + end end end