Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close #2103 add check_in and uncheck_in to admin order_guest #2104

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/controllers/spree/admin/guests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

def model_class
SpreeCmCommissioner::Guest
Expand Down Expand Up @@ -42,14 +43,51 @@ def new

def edit
@kyc_fields = @object.line_item.kyc_fields
@check_in = @object.check_in
end

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
50 changes: 50 additions & 0 deletions app/views/spree/admin/guests/_check_in_status.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<div class="card mb-3" id="order_tab_summary">
<div class="card-header">
<h3 class="card-title mb-0 h6"><%= Spree.t(:check_in_states) %></h3>
</div>
<% if @check_in.present? %>
<ul class="list-group list-group-flush">
<li class="list-group-item d-flex justify-content-between align-items-center">
<small><%= Spree.t(:verification_state) %></small>
<%= @check_in.verification_state || 'N/A' %>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<small><%= Spree.t(:check_in_type) %></small>
<%= content_tag(:strong, class: "badge #{badge_color_base_on_check_in_type(@check_in.check_in_type)} font-weight-bold uppercase") do %>
<%= @check_in.check_in_type&.titleize || 'N/A' %>
<% end %>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<small><%= Spree.t(:entry_type) %></small>
<%= content_tag(:strong, class: "badge #{badge_color_base_on_entry_type(@check_in.guest&.entry_type)} font-weight-bold uppercase") do %>
<%= SpreeCmCommissioner::CheckIn.entry_types.key(@check_in.guest&.entry_type)&.titleize || 'N/A' %>
<% end %>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<small><%= Spree.t(:check_in_method) %></small>
<%= content_tag(:strong, class: "badge #{badge_color_base_on_check_in_method(@check_in.check_in_method)} font-weight-bold uppercase") do %>
<%= @check_in.check_in_method || 'N/A' %>
<% end %>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<small><%= Spree.t(:check_in_by) %></small>
<%= @check_in.check_in_by&.full_name || 'N/A' %>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<small data-hook='admin_order_tab_date_completed_title'><%= Spree.t(:confirmed_at) %></small>
<span class="text-right small font-weight-bold" id='date_complete'>
<%= pretty_time(@check_in.confirmed_at) || 'N/A' %>
</span>
</li>
</ul>

<!-- Button trigger modal -->
<button type="button" class="btn btn-outline-danger m-3" data-toggle="modal" data-target="#uncheckInModal">
Uncheck In
</button>
<% else %>
<div class="alert alert-warning">
<%= Spree.t(:no_check_in_found) %>
</div>
<% end %>
</div>
37 changes: 36 additions & 1 deletion app/views/spree/admin/guests/edit.html.erb
Original file line number Diff line number Diff line change
@@ -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 @object.check_in.present? %>
<%= render partial: 'check_in_status' %>
<% else %>
<div class="card">
<div class="card-body">
<h5 class="card-title"><%= Spree.t(:check_in_status) %></h5>
<p class="card-text">Click button below to manually check_in guest</p>
<%= link_to 'Check In', check_in_admin_order_guest_path(@order, @object), method: :post, class: 'btn btn-outline-primary' %>
</div>
</div>
<% end %>
<% end %>

<!-- Verified Uncheck In Modal -->
<div class="modal fade" id="uncheckInModal" tabindex="-1" role="dialog" aria-labelledby="uncheckInModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="uncheckInModalLabel">Uncheck In Confirmation</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to uncheck in?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<%= link_to 'Confirm', uncheck_in_admin_order_guest_path, method: :post, class: 'btn btn-primary' %>
</div>
</div>
</div>
</div>

<%= form_with model: @object, url: { action: 'update' }, html: { multipart: true } do |f| %>
<fieldset>
<%= render partial: 'form', locals: { f: f } %>
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@
post :add_guest
delete :remove_guest
end
member do
post :check_in
post :uncheck_in
end
end
end

Expand Down