61 lines
5.3 KiB
PHTML
61 lines
5.3 KiB
PHTML
<?php
|
|
/** @var \Esun\CustomerMessage\Block\Adminhtml\Message\Index $block */
|
|
/** @var \Magento\Framework\Escaper $escaper */
|
|
$threads = $block->getThreads();
|
|
$thread = $block->getSelectedThread();
|
|
$entries = $block->getMessages($thread);
|
|
$order = $block->getOrder();
|
|
$orderId = $order ? (int)$order->getEntityId() : (int)($thread['order_id'] ?? 0);
|
|
$customerName = trim(implode(' ', array_filter([
|
|
(string)($thread['customer_firstname'] ?? ($order ? $order->getCustomerFirstname() : '')),
|
|
(string)($thread['customer_lastname'] ?? ($order ? $order->getCustomerLastname() : '')),
|
|
])));
|
|
$customerName = $customerName
|
|
?: (string)($thread['customer_email'] ?? ($order ? $order->getCustomerEmail() : ''))
|
|
?: (string)__('Customer');
|
|
?>
|
|
<div class="esun-admin-inbox">
|
|
<aside class="esun-admin-inbox__threads">
|
|
<div class="esun-admin-inbox__search"><input class="admin__control-text" type="search" placeholder="<?= $escaper->escapeHtmlAttr(__('Search conversations')) ?>" data-role="thread-search"></div>
|
|
<?php foreach ($threads as $item): ?>
|
|
<a class="esun-admin-thread <?= $thread && (int)$thread['thread_id'] === (int)$item['thread_id'] ? 'is-active' : '' ?>" data-search="<?= $escaper->escapeHtmlAttr(strtolower($item['customer_email'] . ' ' . $item['subject'] . ' ' . ($item['order_increment_id'] ?? ''))) ?>" href="<?= $escaper->escapeUrl($block->getUrl('esun_customer_message/message/index', ['thread_id' => (int)$item['thread_id']])) ?>">
|
|
<strong><?= $escaper->escapeHtml($item['customer_email']) ?></strong>
|
|
<span><?= $escaper->escapeHtml($item['subject']) ?></span>
|
|
<small><?= $escaper->escapeHtml(mb_substr((string)$item['last_content'], 0, 70)) ?></small>
|
|
<?php if ((int)$item['admin_unread_count']): ?><b><?= (int)$item['admin_unread_count'] ?></b><?php endif; ?>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</aside>
|
|
<section class="esun-admin-inbox__conversation">
|
|
<?php if ($thread || $order): ?>
|
|
<header><div><h1><?= $escaper->escapeHtml($thread['subject'] ?? __('Order #%1', $order->getIncrementId())) ?></h1><span><?= $escaper->escapeHtml($thread['customer_email'] ?? $order->getCustomerEmail()) ?></span></div><?php if ($orderId): ?><a href="<?= $escaper->escapeUrl($block->getUrl('sales/order/view', ['order_id' => $orderId])) ?>"><?= $escaper->escapeHtml(__('View Order')) ?></a><?php endif; ?></header>
|
|
<div class="esun-admin-inbox__entries">
|
|
<?php if ($entries): foreach ($entries as $entry): ?>
|
|
<article class="esun-admin-entry is-<?= $escaper->escapeHtmlAttr($entry['sender_type']) ?>">
|
|
<small><?= $escaper->escapeHtml($entry['sender_type'] === 'admin' ? __('Manager') : $customerName) ?> · <?= $escaper->escapeHtml($block->formatDate($entry['created_at'], \IntlDateFormatter::MEDIUM, true)) ?></small>
|
|
<div><?= nl2br($escaper->escapeHtml($entry['content'])) ?><?php if ($entry['attachments']): ?><div class="esun-admin-entry__images"><?php foreach ($entry['attachments'] as $attachment): ?><a href="<?= $escaper->escapeUrl($block->getUrl('esun_customer_message/attachment/view', ['id' => (int)$attachment['attachment_id']])) ?>" target="_blank" rel="noopener"><img src="<?= $escaper->escapeUrl($block->getUrl('esun_customer_message/attachment/view', ['id' => (int)$attachment['attachment_id']])) ?>" alt="<?= $escaper->escapeHtmlAttr($attachment['original_name']) ?>"></a><?php endforeach; ?></div><?php endif; ?></div>
|
|
</article>
|
|
<?php endforeach; else: ?><p class="esun-admin-inbox__empty"><?= $escaper->escapeHtml(__('Start an order conversation with this customer.')) ?></p><?php endif; ?>
|
|
</div>
|
|
<form class="esun-admin-reply" method="post" enctype="multipart/form-data" action="<?= $escaper->escapeUrl($block->getUrl('esun_customer_message/thread/reply')) ?>">
|
|
<?= $block->getBlockHtml('formkey') ?>
|
|
<?php if ($thread): ?><input type="hidden" name="thread_id" value="<?= (int)$thread['thread_id'] ?>"><?php endif; ?>
|
|
<?php if ($orderId): ?><input type="hidden" name="order_id" value="<?= $orderId ?>"><?php endif; ?>
|
|
<textarea class="admin__control-textarea" name="content" rows="4" placeholder="<?= $escaper->escapeHtmlAttr(__('Enter a reply...')) ?>"></textarea>
|
|
<div><label class="action-secondary"><span><?= $escaper->escapeHtml(__('Add Images')) ?></span><input type="file" name="images[]" accept="image/jpeg,image/png,image/webp" multiple hidden></label><small><?= $escaper->escapeHtml(__('Up to 5 JPG, PNG or WebP images, 5 MB each.')) ?></small><button class="action-primary" type="submit"><?= $escaper->escapeHtml(__('Send')) ?></button></div>
|
|
</form>
|
|
<?php else: ?>
|
|
<div class="esun-admin-inbox__placeholder"><h2><?= $escaper->escapeHtml(__('Customer Messages')) ?></h2><p><?= $escaper->escapeHtml(__('Select a conversation to view and reply.')) ?></p></div>
|
|
<?php endif; ?>
|
|
</section>
|
|
</div>
|
|
<script>
|
|
require(['jquery'], function ($) {
|
|
'use strict';
|
|
$('[data-role=thread-search]').on('input', function () {
|
|
var query = this.value.toLowerCase();
|
|
$('.esun-admin-thread').each(function () { $(this).toggle($(this).data('search').indexOf(query) !== -1); });
|
|
});
|
|
});
|
|
</script>
|