Skip to content

Commit

Permalink
Dynamically load customer info when creating new conversation - closes
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Nov 18, 2023
1 parent 4bb7e22 commit c2a8894
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 19 deletions.
30 changes: 30 additions & 0 deletions app/Http/Controllers/ConversationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,36 @@ public function ajax(Request $request)

break;

case 'load_customer_info':
$customer = Customer::getByEmail($request->customer_email);

if ($customer) {
// Previous conversations
$prev_conversations = [];

$mailbox = Mailbox::find($request->mailbox_id);

if ($mailbox && $mailbox->userHasAccess($user->id)) {
$conversation_id = (int)$request->conversation_id ?? 0;

$prev_conversations = $mailbox->conversations()
->where('customer_id', $customer->id)
->where('id', '<>', $conversation_id)
->where('status', '!=', Conversation::STATUS_SPAM)
->where('state', Conversation::STATE_PUBLISHED)
//->limit(self::PREV_CONVERSATIONS_LIMIT)
->orderBy('created_at', 'desc')
->paginate(self::PREV_CONVERSATIONS_LIMIT);
}

$response['html'] = \View::make('conversations/partials/customer_sidebar')->with([
'customer' => $customer,
'prev_conversations' => $prev_conversations,
])->render();
$response['status'] = 'success';
}
break;

default:
$response['msg'] = 'Unknown action';
break;
Expand Down
30 changes: 30 additions & 0 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,36 @@ function convEditorInit()
}).blur(function(event) {
onReplyBlur();
});

// New conversation: load customer info
$("#to").on('change', function(event) {
var to = $('#to').val()
//var clean_customer = true;
// Do not clean customer info if customer has not changed
/*if (Array.isArray(to) && to.length == 1 && typeof(to[0]) != "undefined") {
if (to[0] == $('#conv-layout-customer li.customer-email:first').text()) {
clean_customer = false;
}
}
if (clean_customer) {*/
$('#conv-layout-customer').html('');
// Load customer info
if (Array.isArray(to) && to.length == 1 && typeof(to[0]) != "undefined") {
fsAjax({
action: 'load_customer_info',
customer_email: to[0],
mailbox_id: getGlobalAttr('mailbox_id'),
conversation_id: getGlobalAttr('conversation_id')
}, laroute.route('conversations.ajax'), function(response) {
if (isAjaxSuccess(response) && typeof(response.html) != "undefined") {
$('#conv-layout-customer').html(response.html);
}
}, true, function() {
// Do nothing
});
}
});

// select2 does not react on keyup or keypress
$(".recipient-select, .draft-changer").on('change', function(event) {
onReplyChange();
Expand Down
44 changes: 25 additions & 19 deletions resources/views/conversations/partials/customer_sidebar.blade.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
@if (!empty($customer))
<div class="conv-customer-header"></div>
<div class="conv-customer-block conv-sidebar-block">
@include('customers/profile_snippet', ['customer' => $customer, 'main_email' => $conversation->customer_email, 'conversation' => $conversation])
<div class="dropdown customer-trigger" data-toggle="tooltip" title="{{ __("Settings") }}">
<a href="#" class="dropdown-toggle glyphicon glyphicon-cog" data-toggle="dropdown" ></a>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li role="presentation"><a href="{{ route('customers.update', ['id' => $customer->id]) }}" tabindex="-1" role="menuitem">{{ __("Edit Profile") }}</a></li>
@if (!$conversation->isChat())
<li role="presentation"><a href="{{ route('conversations.ajax_html', array_merge(['action' =>
'change_customer'], \Request::all(), ['conversation_id' => $conversation->id]) ) }}" data-trigger="modal" data-modal-title="{{ __("Change Customer") }}" data-modal-no-footer="true" data-modal-on-show="changeCustomerInit" tabindex="-1" role="menuitem">{{ __("Change Customer") }}</a></li>
@endif
@if (count($prev_conversations))
<li role="presentation" class="col3-hidden"><a data-toggle="collapse" href=".collapse-conv-prev" tabindex="-1" role="menuitem">{{ __("Previous Conversations") }}</a></li>
@endif
{{ \Eventy::action('conversation.customer.menu', $customer, $conversation) }}
{{-- No need to use this --}}
{{ \Eventy::action('customer_profile.menu', $customer, $conversation) }}
</ul>
</div>
@include('customers/profile_snippet', ['customer' => $customer, 'main_email' => $conversation->customer_email ?? '', 'conversation' => $conversation ?? null])
@if (isset($conversation))
<div class="dropdown customer-trigger" data-toggle="tooltip" title="{{ __("Settings") }}">
<a href="#" class="dropdown-toggle glyphicon glyphicon-cog" data-toggle="dropdown" ></a>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li role="presentation"><a href="{{ route('customers.update', ['id' => $customer->id]) }}" tabindex="-1" role="menuitem">{{ __("Edit Profile") }}</a></li>
@if (!$conversation->isChat())
<li role="presentation"><a href="{{ route('conversations.ajax_html', array_merge(['action' =>
'change_customer'], \Request::all(), ['conversation_id' => $conversation->id]) ) }}" data-trigger="modal" data-modal-title="{{ __("Change Customer") }}" data-modal-no-footer="true" data-modal-on-show="changeCustomerInit" tabindex="-1" role="menuitem">{{ __("Change Customer") }}</a></li>
@endif
@if (count($prev_conversations))
<li role="presentation" class="col3-hidden"><a data-toggle="collapse" href=".collapse-conv-prev" tabindex="-1" role="menuitem">{{ __("Previous Conversations") }}</a></li>
@endif
{{ \Eventy::action('conversation.customer.menu', $customer, $conversation) }}
{{-- No need to use this --}}
{{ \Eventy::action('customer_profile.menu', $customer, $conversation) }}
</ul>
</div>
@endif
{{--<div data-toggle="collapse" href="#collapse-conv-prev" class="customer-hist-trigger">
<div class="glyphicon glyphicon-list-alt" data-toggle="tooltip" title="{{ __("Previous Conversations") }}"></div>
</div>--}}
</div>
@action('conversation.before_prev_convs', $customer, $conversation, $mailbox)
@if (isset($conversation) && isset($mailbox))
@action('conversation.before_prev_convs', $customer, $conversation, $mailbox)
@endif
@if (count($prev_conversations))
@include('conversations/partials/prev_convs_short')
@endif
@action('conversation.after_prev_convs', $customer, $conversation, $mailbox)
@if (isset($conversation) && isset($mailbox))
@action('conversation.after_prev_convs', $customer, $conversation, $mailbox)
@endif
@endif

0 comments on commit c2a8894

Please sign in to comment.