@zenify-omni/chat-ui-react-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +92 -0
- package/assets/asset-url.js +6 -0
- package/assets/icons/chatter_agent.js +27 -0
- package/assets/icons/chatter_chatbot.js +43 -0
- package/assets/icons/chatter_contact.js +36 -0
- package/assets/icons/email_icon.png +0 -0
- package/assets/icons/emoji/angry.svg +56 -0
- package/assets/icons/emoji/haha.svg +20 -0
- package/assets/icons/emoji/like.svg +10 -0
- package/assets/icons/emoji/like_out_line.png +0 -0
- package/assets/icons/emoji/love.svg +10 -0
- package/assets/icons/emoji/sad.svg +46 -0
- package/assets/icons/emoji/wow.svg +51 -0
- package/assets/icons/instagram.js +29 -0
- package/assets/icons/not_found.png +0 -0
- package/assets/icons/not_found_template.svg +9 -0
- package/assets/icons/phone_icon.png +0 -0
- package/assets/icons/shopee.js +17 -0
- package/assets/icons/sms_icon.png +0 -0
- package/assets/icons/tiktok.js +17 -0
- package/assets/icons/whatsapp.js +28 -0
- package/assets/icons/zalo.js +17 -0
- package/assets/icons/zalo_icon.png +0 -0
- package/assets/icons/zns_icon.png +0 -0
- package/assets/images/emoji.webp +0 -0
- package/assets/images/error.png +0 -0
- package/assets/images/menu.png +0 -0
- package/assets/images/money.png +0 -0
- package/assets/images/success.png +0 -0
- package/assets/public-urls.js +78 -0
- package/components/campaign-detail-route/select/group.js +38 -0
- package/components/campaign-detail-route/select/multi-groups.js +43 -0
- package/components/chat-route/chat-box/ads-context-card.js +143 -0
- package/components/chat-route/chat-box/chat-drop-file.js +18 -0
- package/components/chat-route/chat-box/chat-feedback/chat-insight.js +214 -0
- package/components/chat-route/chat-box/chat-feedback/index.js +127 -0
- package/components/chat-route/chat-box/chat-header-actions-inline.js +1055 -0
- package/components/chat-route/chat-box/chat-header.js +465 -0
- package/components/chat-route/chat-box/chat-input.js +1164 -0
- package/components/chat-route/chat-box/chat-message-action.js +399 -0
- package/components/chat-route/chat-box/chat-message-list.js +995 -0
- package/components/chat-route/chat-box/chat-message.js +2099 -0
- package/components/chat-route/chat-box/chat-reply-preview.js +317 -0
- package/components/chat-route/chat-box/common-groups-modal.js +430 -0
- package/components/chat-route/chat-box/constants.js +29 -0
- package/components/chat-route/chat-box/contact-card/index.js +87 -0
- package/components/chat-route/chat-box/edit-customer-alias-dialog.js +197 -0
- package/components/chat-route/chat-box/emoji-picker-combined.js +91 -0
- package/components/chat-route/chat-box/emoji-sprite.js +45 -0
- package/components/chat-route/chat-box/emojiMap.js +92 -0
- package/components/chat-route/chat-box/facebook-reconnect-notice.js +49 -0
- package/components/chat-route/chat-box/forward-message-modal.js +659 -0
- package/components/chat-route/chat-box/index.js +165 -0
- package/components/chat-route/chat-box/message-time.js +44 -0
- package/components/chat-route/chat-box/message-viewers.js +114 -0
- package/components/chat-route/chat-box/pasted-file-preview.js +138 -0
- package/components/chat-route/chat-box/pinned-messages.js +255 -0
- package/components/chat-route/chat-box/react-message/react-preview.js +83 -0
- package/components/chat-route/chat-box/react-message/reaction-button.js +200 -0
- package/components/chat-route/chat-box/right-side/chat-history.js +142 -0
- package/components/chat-route/chat-box/right-side/chat-tag-selector.js +232 -0
- package/components/chat-route/chat-box/right-side/create-personal-tag-modal.js +458 -0
- package/components/chat-route/chat-box/right-side/customer/customer-info-item.js +60 -0
- package/components/chat-route/chat-box/right-side/in-room-dialog.js +225 -0
- package/components/chat-route/chat-box/right-side/zalo-group/add-friend-dialog.js +154 -0
- package/components/chat-route/chat-box/right-side/zalo-group/send-message-dialog.js +165 -0
- package/components/chat-route/chat-box/send-contact-card-modal.js +102 -0
- package/components/chat-route/chat-box/send-contact-card.js +80 -0
- package/components/chat-route/chat-box/text-content.js +400 -0
- package/components/chat-route/chat-box/use-facebook-page-invalid.js +22 -0
- package/components/chat-route/chat-box/zalo-emoji-decoration.js +98 -0
- package/components/chat-route/chat-box/zalo-emoji-picker.js +74 -0
- package/components/chat-route/chat-box/zalo-personal-editor.js +590 -0
- package/components/chat-route/chat-box/zalo-reminder/create-zalo-reminder.js +868 -0
- package/components/chat-route/chat-box/zalo-reminder/use-send-zalo-reminder.js +98 -0
- package/components/chat-route/chat-box/zalo-reminder/zalo-reminder-content.js +294 -0
- package/components/chat-route/chat-box/zalo-rtf-utils.js +422 -0
- package/components/chat-route/chat-list/action-chat-item.js +116 -0
- package/components/chat-route/chat-list/assign-agent-dialog.js +170 -0
- package/components/chat-route/chat-list/assign-tag-dialog.js +242 -0
- package/components/chat-route/chat-list/chat-item-tags.js +105 -0
- package/components/chat-route/chat-list/chat-item.js +749 -0
- package/components/chat-route/chat-list/chat-list-item.js +370 -0
- package/components/chat-route/chat-list/chat-list-selection-bar.js +426 -0
- package/components/chat-route/chat-list/chat-search-preview.js +48 -0
- package/components/chat-route/chat-list/chat-sort-menu.js +89 -0
- package/components/chat-route/chat-list/edit-filter-modal.js +468 -0
- package/components/chat-route/chat-list/filter-chat-sources.js +222 -0
- package/components/chat-route/chat-list/filter-chat.js +501 -0
- package/components/chat-route/chat-list/filter-criteria-rows.js +845 -0
- package/components/chat-route/chat-list/filter-group-select.js +66 -0
- package/components/chat-route/chat-list/filter-pin-menu.js +165 -0
- package/components/chat-route/chat-list/friend-request/list-friend-request.js +287 -0
- package/components/chat-route/chat-list/index.js +243 -0
- package/components/chat-route/chat-list/inline-search-results.js +178 -0
- package/components/chat-route/chat-list/post-ids-field.js +104 -0
- package/components/chat-route/chat-list/quick-filter-bar.js +391 -0
- package/components/chat-route/chat-list/save-filter-popover.js +258 -0
- package/components/chat-route/chat-list/search-messages/index.js +225 -0
- package/components/chat-route/chat-list/search-result-header.js +51 -0
- package/components/chat-route/chat-list/util.js +604 -0
- package/components/chat-route/chat-toolbar.js +108 -0
- package/components/chat-route/hooks/use-reassign.js +111 -0
- package/components/chat-route/shared/close-conversation-dialog.js +111 -0
- package/components/chat-route/shared/force-transfer-dialog.js +109 -0
- package/components/chat-route/shared/in-queue-confirm-dialog.js +40 -0
- package/components/chat-route/util.js +146 -0
- package/components/chat-route/zalo/modal-action-zalo.js +76 -0
- package/components/chat-route/zalo/modal-add-friend-zalo.js +277 -0
- package/components/custom/SafeHTML.js +45 -0
- package/components/custom/audio-player.js +81 -0
- package/components/custom/avatar.js +95 -0
- package/components/custom/between-date-picker/index.js +86 -0
- package/components/custom/button-close.js +28 -0
- package/components/custom/button.js +80 -0
- package/components/custom/color-picker.js +81 -0
- package/components/custom/combobox.js +168 -0
- package/components/custom/custom-dialog.js +44 -0
- package/components/custom/custom-select.js +256 -0
- package/components/custom/cycle-value-helpers.js +11 -0
- package/components/custom/cycle-value.js +93 -0
- package/components/custom/date-time-picker/components/date-time-group.js +44 -0
- package/components/custom/date-time-picker/components/date-time-input.js +383 -0
- package/components/custom/date-time-picker/components/date-time-unit-input.js +138 -0
- package/components/custom/date-time-picker/components/month-year-picker.js +232 -0
- package/components/custom/date-time-picker/hooks/use-merge-refs.js +18 -0
- package/components/custom/date-time-picker/hooks/use-scroll-to-center.js +18 -0
- package/components/custom/date-time-picker/index.js +348 -0
- package/components/custom/field-file-upload/files-upload.js +87 -0
- package/components/custom/field-file-upload/image-upload.js +115 -0
- package/components/custom/field-file-upload/preview-images-modal.js +284 -0
- package/components/custom/field-file-upload/preview-list-file.js +134 -0
- package/components/custom/field-file-upload/preview-list-image.js +108 -0
- package/components/custom/field-file-upload/upload-custom.js +222 -0
- package/components/custom/field-generator.js +639 -0
- package/components/custom/field-layout-popover.js +304 -0
- package/components/custom/file-preview-modal.js +351 -0
- package/components/custom/html-edtior.js +100 -0
- package/components/custom/icon.js +49 -0
- package/components/custom/infinite-scroll-combobox.js +253 -0
- package/components/custom/inline-edit-popover.js +90 -0
- package/components/custom/inputs/calendar-input.js +0 -0
- package/components/custom/inputs/chip-input.js +136 -0
- package/components/custom/inputs/file-input.js +71 -0
- package/components/custom/inputs/mask-data/mask-data-input.js +80 -0
- package/components/custom/inputs/mask-data/mask-data-select.js +78 -0
- package/components/custom/inputs/mask-data/mask-data-textarea.js +75 -0
- package/components/custom/inputs/mask-data/reconcile-masked-edit.js +20 -0
- package/components/custom/jxl-decode.js +34 -0
- package/components/custom/jxl-image.js +68 -0
- package/components/custom/jxl-worker.js +12 -0
- package/components/custom/label.js +55 -0
- package/components/custom/layout.js +30 -0
- package/components/custom/multi-select-search-cc.js +179 -0
- package/components/custom/multiple-select-setting-tags.js +404 -0
- package/components/custom/multiple-selector.js +821 -0
- package/components/custom/pagination.js +95 -0
- package/components/custom/popup-confirm.js +120 -0
- package/components/custom/previews/facebook/facebook-appointment-booking-preview.js +83 -0
- package/components/custom/previews/facebook/facebook-audio-preview.js +130 -0
- package/components/custom/previews/facebook/facebook-event-preview.js +72 -0
- package/components/custom/previews/facebook/facebook-file-preview.js +95 -0
- package/components/custom/previews/facebook/facebook-group-preview.js +103 -0
- package/components/custom/previews/facebook/facebook-image-preview.js +81 -0
- package/components/custom/previews/facebook/facebook-page-preview.js +85 -0
- package/components/custom/previews/facebook/facebook-post-preview.js +77 -0
- package/components/custom/previews/facebook/facebook-reel-preview.js +83 -0
- package/components/custom/previews/facebook/facebook-sticker-preview.js +23 -0
- package/components/custom/previews/facebook/facebook-video-preview.js +114 -0
- package/components/custom/previews/facebook/index.js +24 -0
- package/components/custom/previews/file-preview.js +747 -0
- package/components/custom/previews/image-preview.js +288 -0
- package/components/custom/previews/instagram/index.js +4 -0
- package/components/custom/previews/instagram/instagram-share-post-preview.js +77 -0
- package/components/custom/previews/link-preview.js +166 -0
- package/components/custom/previews/product-preview.js +334 -0
- package/components/custom/previews/tiktok-order-preview.js +278 -0
- package/components/custom/previews/tiktok-product-preview.js +321 -0
- package/components/custom/previews/tiktok-voucher-preview.js +151 -0
- package/components/custom/previews/whatsapp/index.js +10 -0
- package/components/custom/previews/whatsapp/whatsapp-contact-card-preview.js +150 -0
- package/components/custom/previews/whatsapp/whatsapp-order-preview.js +38 -0
- package/components/custom/previews/whatsapp/whatsapp-poll-preview.js +29 -0
- package/components/custom/previews/whatsapp/whatsapp-product-preview.js +29 -0
- package/components/custom/retry-image.js +44 -0
- package/components/custom/search-input.js +26 -0
- package/components/custom/separator-with-text.js +14 -0
- package/components/custom/showToast.js +21 -0
- package/components/custom/sortable-header.js +62 -0
- package/components/custom/table-resize-line.js +92 -0
- package/components/custom/time-picker/index.js +73 -0
- package/components/custom/time-picker/time-picker-input.js +159 -0
- package/components/custom/time-picker/time-picker-utils.js +152 -0
- package/components/custom/viewers/audio-player.js +192 -0
- package/components/custom/viewers/code-viewer.js +140 -0
- package/components/custom/viewers/csv-viewer.js +174 -0
- package/components/custom/viewers/docx-viewer.js +145 -0
- package/components/custom/viewers/image-viewer.js +104 -0
- package/components/custom/viewers/markdown-viewer.js +124 -0
- package/components/custom/viewers/pdf-viewer.js +333 -0
- package/components/custom/viewers/spreadsheet-viewer.js +232 -0
- package/components/custom/viewers/unsupported-viewer.js +85 -0
- package/components/custom/viewers/video-player.js +241 -0
- package/components/customers-route/change-owner-modal.js +430 -0
- package/components/customers-route/contact-note-button.js +212 -0
- package/components/customers-route/customer-source.js +37 -0
- package/components/customers-route/table/columns.js +675 -0
- package/components/customers-route/table/edit-fields.js +125 -0
- package/components/customers-route/table/editable-cell.js +218 -0
- package/components/customers-route/table/note-cell.js +77 -0
- package/components/dialogs/invite-agent.js +677 -0
- package/components/error-boundary.js +53 -0
- package/components/leads-route/duplicate-phone-warning-toast.js +96 -0
- package/components/leads-route/table/columns.js +523 -0
- package/components/leads-route/table/contact-cell-name.js +82 -0
- package/components/leads-route/table/edit-fields.js +142 -0
- package/components/leads-route/table/editable-cell.js +228 -0
- package/components/org-tree/group-name-display.js +36 -0
- package/components/org-tree/group-tree-multi-select.js +208 -0
- package/components/org-tree/group-tree-select.js +220 -0
- package/components/posts-route/dialog-select-posts.js +284 -0
- package/components/reports-route/agents/multi-select-agents.js +55 -0
- package/components/reports-route/agents/multi-select-search-agents.js +43 -0
- package/components/settings-route/chat-layout/detail/constants.js +353 -0
- package/components/settings-route/chat-layout/detail/form.js +43 -0
- package/components/settings-route/chat-timeout/channel-multi-select.js +119 -0
- package/components/settings-route/multi-channel/facebook/hooks/use-facebook-sdk.js +3 -0
- package/components/settings-route/object-rule/util.js +79 -0
- package/components/settings-route/routing/settings-dialog.js +561 -0
- package/components/settings-route/switchboard/queue-new/constant.js +9 -0
- package/components/shared/linked-customer-fields/LinkedCustomerFields.js +91 -0
- package/components/shared/linked-customer-fields/use-linked-customer-fields.js +123 -0
- package/components/smartqc-route/qc-form/controls/multi-select-search-agents.js +50 -0
- package/components/ui/alert-dialog.js +112 -0
- package/components/ui/avatar.js +44 -0
- package/components/ui/badge.js +54 -0
- package/components/ui/button.js +48 -0
- package/components/ui/calendar.js +70 -0
- package/components/ui/card.js +58 -0
- package/components/ui/carousel.js +238 -0
- package/components/ui/checkbox.js +27 -0
- package/components/ui/command.js +111 -0
- package/components/ui/context-menu.js +154 -0
- package/components/ui/dialog.js +104 -0
- package/components/ui/dropdown-menu.js +169 -0
- package/components/ui/form.js +104 -0
- package/components/ui/input.js +115 -0
- package/components/ui/label.js +20 -0
- package/components/ui/popover.js +29 -0
- package/components/ui/radio-group.js +53 -0
- package/components/ui/scroll-area.js +38 -0
- package/components/ui/select.js +147 -0
- package/components/ui/separator.js +24 -0
- package/components/ui/sheet.js +113 -0
- package/components/ui/skeleton.js +17 -0
- package/components/ui/slider.js +26 -0
- package/components/ui/sonner.js +76 -0
- package/components/ui/switch.js +54 -0
- package/components/ui/table-v2.js +269 -0
- package/components/ui/table.js +245 -0
- package/components/ui/tabs.js +89 -0
- package/components/ui/textarea.js +33 -0
- package/components/ui/tooltip.js +40 -0
- package/components/workflow-editor/nodes/ticket/picker-field.js +233 -0
- package/components/zalo-login-qr.js +237 -0
- package/components/zalo-login-status-modal.js +45 -0
- package/config/env.js +27 -0
- package/config/hmr.js +8 -0
- package/config/navigation.js +54 -0
- package/config/runtime.js +46 -0
- package/config/theme.js +274 -0
- package/constants/brand-colors.js +32 -0
- package/constants/chat-icon.js +34 -0
- package/dist/chat.css +1 -0
- package/exceptions/throw-exception.js +15 -0
- package/hooks/use-chat-attachments.js +106 -0
- package/hooks/use-chat-configs.js +62 -0
- package/hooks/use-chat-customer.js +33 -0
- package/hooks/use-chat-display-config-sync.js +72 -0
- package/hooks/use-chat-permission.js +68 -0
- package/hooks/use-chat-room-detail.js +44 -0
- package/hooks/use-chat-selection.js +26 -0
- package/hooks/use-chat-sort.js +69 -0
- package/hooks/use-chat-surface.js +8 -0
- package/hooks/use-common-filter-options.js +70 -0
- package/hooks/use-crm-organization-filter-options.js +0 -0
- package/hooks/use-crm-organizations-data.js +23 -0
- package/hooks/use-debounce.js +14 -0
- package/hooks/use-dynamic-fields.js +7 -0
- package/hooks/use-facebook-notice.js +24 -0
- package/hooks/use-feature-flags.js +6 -0
- package/hooks/use-field-layout-override.js +46 -0
- package/hooks/use-file-upload.js +119 -0
- package/hooks/use-file-viewer.js +93 -0
- package/hooks/use-frozen-columns.js +29 -0
- package/hooks/use-horizontal-scroll.js +41 -0
- package/hooks/use-image-preview-queue.js +101 -0
- package/hooks/use-inline-editable-cell.js +97 -0
- package/hooks/use-intersection-observer.js +24 -0
- package/hooks/use-interval.js +20 -0
- package/hooks/use-latest-message-id.js +13 -0
- package/hooks/use-lead-filter-options.js +0 -0
- package/hooks/use-logout-listener.js +43 -0
- package/hooks/use-org-tree.js +43 -0
- package/hooks/use-permission.js +33 -0
- package/hooks/use-quick-filters.js +175 -0
- package/hooks/use-resizable-table.js +0 -0
- package/hooks/use-setting-common.js +389 -0
- package/hooks/use-settings.js +41 -0
- package/hooks/use-sort-bindings.js +24 -0
- package/hooks/use-table-display-config.js +0 -0
- package/hooks/use-tenant-config.js +99 -0
- package/hooks/use-update-user-config.js +150 -0
- package/hooks/use-zalo-connection.js +57 -0
- package/hooks/use-zalo-mention-list.js +31 -0
- package/index.css +624 -0
- package/index.js +100 -0
- package/lib/deal-name.js +27 -0
- package/lib/i18n/react.js +7 -0
- package/lib/i18n/use-language.js +0 -0
- package/lib/query-client.js +34 -0
- package/lib/utils.js +25 -0
- package/package.json +108 -0
- package/provider/chat-context.js +9 -0
- package/provider/chat-provider.js +177 -0
- package/provider/chat-room-context.js +9 -0
- package/provider/chat-room-hooks.js +8 -0
- package/provider/chat-room-provider.js +84 -0
- package/provider/hooks.js +22 -0
- package/provider/index.js +42 -0
- package/public/contact-card-user.svg +25 -0
- package/public/images/icons/facebook.svg +1 -0
- package/public/images/icons/instagram.svg +1 -0
- package/public/images/icons/shopee.svg +1 -0
- package/public/images/icons/whatsapp.svg +1 -0
- package/public/images/icons/zalo.png +0 -0
- package/public/images/images.jpg +0 -0
- package/public/images/ticket_sources/api.png +0 -0
- package/public/images/ticket_sources/email.png +0 -0
- package/public/images/ticket_sources/facebook.png +0 -0
- package/public/images/ticket_sources/hand.png +0 -0
- package/public/images/ticket_sources/instagram.png +0 -0
- package/public/images/ticket_sources/livechat.png +0 -0
- package/public/images/ticket_sources/shopee.svg +1 -0
- package/public/images/ticket_sources/sms.png +0 -0
- package/public/images/ticket_sources/telephone-call-in.png +0 -0
- package/public/images/ticket_sources/telephone-call-out.png +0 -0
- package/public/images/ticket_sources/tiktok.png +0 -0
- package/public/images/ticket_sources/tiktok_shop.png +0 -0
- package/public/images/ticket_sources/whatsapp.png +0 -0
- package/public/images/ticket_sources/whatsapp.svg +1 -0
- package/public/images/ticket_sources/zalo.png +0 -0
- package/public/placeholder.svg +13 -0
- package/store/app-status-store.js +17 -0
- package/store/chat-display-config-store.js +182 -0
- package/store/chat-display-config.resolvers.js +88 -0
- package/store/chat-store-helpers.js +62 -0
- package/store/chat-store.js +931 -0
- package/store/crm-organization-list-filter-store.js +126 -0
- package/store/customer-list-filter-store.js +139 -0
- package/store/devtools.js +9 -0
- package/store/duplicate-phone-warning-store.js +18 -0
- package/store/entity-extract-store.js +72 -0
- package/store/file-preview-store.js +27 -0
- package/store/filter-store.js +289 -0
- package/store/index.js +22 -0
- package/store/knowledge-crawl-store.js +53 -0
- package/store/lead-list-filter-store.js +142 -0
- package/store/list-pagination-state.js +44 -0
- package/store/lumi-learn-from-chat-store.js +69 -0
- package/store/merge-suggestion-store.js +27 -0
- package/store/notification-store.js +63 -0
- package/store/preview-image-store.js +22 -0
- package/store/settings-store/multi-channel/email-list-store.js +20 -0
- package/store/settings-store/multi-channel/facebook-list-store.js +22 -0
- package/store/settings-store/multi-channel/google-list-store.js +20 -0
- package/store/settings-store/multi-channel/instagram-list-store.js +20 -0
- package/store/settings-store/multi-channel/misa-list-store.js +20 -0
- package/store/settings-store/multi-channel/nhanhvn-list-store.js +20 -0
- package/store/settings-store/multi-channel/shopee-list-store.js +20 -0
- package/store/settings-store/multi-channel/shopee-order-list-store.js +20 -0
- package/store/settings-store/multi-channel/sms-list-store.js +20 -0
- package/store/settings-store/multi-channel/tiktok-business-list-store.js +20 -0
- package/store/settings-store/multi-channel/tiktok-list-store.js +20 -0
- package/store/settings-store/multi-channel/zalo-list-store.js +22 -0
- package/store/settings-store/multi-channel/zalo-user-list-store.js +25 -0
- package/store/smart-qc-store/smart-qc-list-filter-store.js +70 -0
- package/store/tenant-config-store.js +21 -0
- package/store/user-detail-store.js +17 -0
- package/store/user-status-store.js +33 -0
- package/store/workflow-store.js +24 -0
- package/store/workspace-store.js +32 -0
- package/tailwind-preset.js +129 -0
- package/utils/chat-actions.js +414 -0
- package/utils/chat_socket.js +1225 -0
- package/utils/extra-columns.js +108 -0
- package/utils/file.js +316 -0
- package/utils/html-to-plain-text.js +12 -0
- package/utils/notification.js +71 -0
- package/utils/replaceZaloSprite.js +64 -0
- package/utils/show-be-error.js +17 -0
- package/utils/typing_socket.js +101 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import i18n from "@zenify-omni/chat-js/lib/i18n/index.js";
|
|
3
|
+
import { useState, useMemo, useEffect } from "react";
|
|
4
|
+
import {
|
|
5
|
+
MessageCircle,
|
|
6
|
+
EllipsisVertical,
|
|
7
|
+
ChevronDown,
|
|
8
|
+
ChevronUp,
|
|
9
|
+
PinOff,
|
|
10
|
+
FileText,
|
|
11
|
+
Image,
|
|
12
|
+
Sticker
|
|
13
|
+
} from "lucide-react";
|
|
14
|
+
import { sendMessage } from "../../../utils/chat_socket.js";
|
|
15
|
+
import useChatStore from "../../../store/chat-store.js";
|
|
16
|
+
import { useShallow } from "zustand/shallow";
|
|
17
|
+
import {
|
|
18
|
+
DropdownMenu,
|
|
19
|
+
DropdownMenuContent,
|
|
20
|
+
DropdownMenuItem,
|
|
21
|
+
DropdownMenuTrigger
|
|
22
|
+
} from "../../ui/dropdown-menu.js";
|
|
23
|
+
import DOMPurify from "dompurify";
|
|
24
|
+
import { maskData } from "@zenify-omni/chat-js/utils/data.js";
|
|
25
|
+
import { useTranslation } from "react-i18next";
|
|
26
|
+
const PIN_MSG_TYPE = {
|
|
27
|
+
TEXT: 1,
|
|
28
|
+
IMAGE: 32,
|
|
29
|
+
STICKER: 36,
|
|
30
|
+
FILE: 46
|
|
31
|
+
};
|
|
32
|
+
const parsePinParams = (params) => {
|
|
33
|
+
try {
|
|
34
|
+
return typeof params === "string" ? JSON.parse(params) : params;
|
|
35
|
+
} catch {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
function PinnedMessages({
|
|
40
|
+
chatRoomId,
|
|
41
|
+
isChatAllowed,
|
|
42
|
+
ticket,
|
|
43
|
+
pinnedData
|
|
44
|
+
}) {
|
|
45
|
+
const { t } = useTranslation();
|
|
46
|
+
const [expanded, setExpanded] = useState(false);
|
|
47
|
+
const [setFindPinSelected] = useChatStore(
|
|
48
|
+
useShallow((state) => [state.setFindPinSelected])
|
|
49
|
+
);
|
|
50
|
+
const handleClickPin = (pin) => {
|
|
51
|
+
if (pin.chat_message_id) {
|
|
52
|
+
setFindPinSelected(pin.chat_message_id);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
setExpanded(false);
|
|
57
|
+
}, [chatRoomId]);
|
|
58
|
+
const handleUnpin = (topicId) => {
|
|
59
|
+
if (!ticket) return;
|
|
60
|
+
const contentOption = {
|
|
61
|
+
unpin: {
|
|
62
|
+
type: "unpin_message",
|
|
63
|
+
topic_id: topicId
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
sendMessage(
|
|
67
|
+
ticket,
|
|
68
|
+
"",
|
|
69
|
+
"unpin_message",
|
|
70
|
+
{ is_personal_zalo: ticket?.is_personal_zalo },
|
|
71
|
+
null,
|
|
72
|
+
contentOption
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
const pins = useMemo(() => {
|
|
76
|
+
if (!pinnedData?.data?.data?.length) return [];
|
|
77
|
+
return pinnedData.data.data.map((pin) => {
|
|
78
|
+
const params = parsePinParams(pin.params);
|
|
79
|
+
const msgType = params.msg_type || PIN_MSG_TYPE.TEXT;
|
|
80
|
+
const rawTitle = params.title || "";
|
|
81
|
+
let parsedTitle = null;
|
|
82
|
+
if (msgType !== PIN_MSG_TYPE.TEXT) {
|
|
83
|
+
try {
|
|
84
|
+
parsedTitle = typeof rawTitle === "string" ? JSON.parse(rawTitle) : rawTitle;
|
|
85
|
+
} catch {
|
|
86
|
+
if (rawTitle) {
|
|
87
|
+
parsedTitle = { url: rawTitle };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
id: pin.id,
|
|
93
|
+
msgType,
|
|
94
|
+
rawTitle,
|
|
95
|
+
parsedTitle,
|
|
96
|
+
senderName: pin.senderAlias || params.senderName || "",
|
|
97
|
+
createTime: pin.createTime,
|
|
98
|
+
chat_message_id: pin.chat_message_id || ""
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
}, [pinnedData]);
|
|
102
|
+
const renderPinContent = (pin) => {
|
|
103
|
+
switch (pin.msgType) {
|
|
104
|
+
case PIN_MSG_TYPE.FILE: {
|
|
105
|
+
const fileName = pin.parsedTitle?.url?.split("/").pop() || i18n.t("chat:label.attachedFile", {
|
|
106
|
+
defaultValue: "T\u1EC7p \u0111\xEDnh k\xE8m"
|
|
107
|
+
});
|
|
108
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
109
|
+
/* @__PURE__ */ jsx(FileText, { size: 14, className: "shrink-0" }),
|
|
110
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: fileName })
|
|
111
|
+
] });
|
|
112
|
+
}
|
|
113
|
+
case PIN_MSG_TYPE.IMAGE: {
|
|
114
|
+
const imageUrl = pin.parsedTitle?.thumb || pin.parsedTitle?.url;
|
|
115
|
+
const imageName = pin.parsedTitle?.thumb || pin.parsedTitle?.url?.split("/").pop() || i18n.t("chat:label.attachedFile", {
|
|
116
|
+
defaultValue: "T\u1EC7p \u0111\xEDnh k\xE8m"
|
|
117
|
+
});
|
|
118
|
+
return imageUrl ? /* @__PURE__ */ jsx(
|
|
119
|
+
"img",
|
|
120
|
+
{
|
|
121
|
+
src: imageUrl,
|
|
122
|
+
alt: imageName,
|
|
123
|
+
className: "size-8 rounded object-cover",
|
|
124
|
+
referrerPolicy: "no-referrer"
|
|
125
|
+
}
|
|
126
|
+
) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
127
|
+
/* @__PURE__ */ jsx(Image, { size: 14, className: "shrink-0" }),
|
|
128
|
+
/* @__PURE__ */ jsx("span", { children: t("common:label.image", { defaultValue: "H\xECnh \u1EA3nh" }) })
|
|
129
|
+
] });
|
|
130
|
+
}
|
|
131
|
+
case PIN_MSG_TYPE.STICKER:
|
|
132
|
+
return pin.parsedTitle?.url ? /* @__PURE__ */ jsx(
|
|
133
|
+
"img",
|
|
134
|
+
{
|
|
135
|
+
src: pin.parsedTitle.url,
|
|
136
|
+
alt: "Sticker",
|
|
137
|
+
className: "size-8 rounded object-cover",
|
|
138
|
+
referrerPolicy: "no-referrer"
|
|
139
|
+
}
|
|
140
|
+
) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
141
|
+
/* @__PURE__ */ jsx(Sticker, { size: 14, className: "shrink-0" }),
|
|
142
|
+
/* @__PURE__ */ jsx("span", { children: "Sticker" })
|
|
143
|
+
] });
|
|
144
|
+
default:
|
|
145
|
+
return /* @__PURE__ */ jsx("span", { className: "truncate", children: /* @__PURE__ */ jsx(
|
|
146
|
+
"span",
|
|
147
|
+
{
|
|
148
|
+
dangerouslySetInnerHTML: {
|
|
149
|
+
// Che SĐT/email trước khi sanitize — cùng pattern với
|
|
150
|
+
// text-content.jsx.
|
|
151
|
+
__html: DOMPurify.sanitize(maskData(pin.rawTitle))
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
) });
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
if (!pins.length) return null;
|
|
158
|
+
const latestPin = pins[0];
|
|
159
|
+
return /* @__PURE__ */ jsxs("div", { className: "pointer-events-auto absolute left-1/2 top-2 z-50 w-[98%] -translate-x-1/2 rounded-lg border bg-card opacity-100 shadow-md transition-all duration-200 ease-in-out", children: [
|
|
160
|
+
/* @__PURE__ */ jsxs(
|
|
161
|
+
"div",
|
|
162
|
+
{
|
|
163
|
+
onClick: () => {
|
|
164
|
+
handleClickPin(latestPin);
|
|
165
|
+
},
|
|
166
|
+
className: "flex cursor-pointer items-center gap-3 px-4 py-2",
|
|
167
|
+
children: [
|
|
168
|
+
/* @__PURE__ */ jsx("div", { className: "flex size-9 shrink-0 items-center justify-center rounded-full", children: /* @__PURE__ */ jsx(MessageCircle, { size: 18, className: "text-muted-foreground" }) }),
|
|
169
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
170
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: t("common:label.message", { defaultValue: "Tin nh\u1EAFn" }) }),
|
|
171
|
+
/* @__PURE__ */ jsxs("p", { className: "flex items-center truncate text-sm text-muted-foreground", children: [
|
|
172
|
+
latestPin.senderName && /* @__PURE__ */ jsxs("span", { className: "mr-1", children: [
|
|
173
|
+
maskData(latestPin.senderName),
|
|
174
|
+
": "
|
|
175
|
+
] }),
|
|
176
|
+
renderPinContent(latestPin)
|
|
177
|
+
] })
|
|
178
|
+
] }),
|
|
179
|
+
pins.length > 1 && /* @__PURE__ */ jsx(
|
|
180
|
+
"button",
|
|
181
|
+
{
|
|
182
|
+
onClick: (e) => {
|
|
183
|
+
e.stopPropagation();
|
|
184
|
+
if (pins.length > 1) {
|
|
185
|
+
setExpanded((prev) => !prev);
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
className: "shrink-0 rounded p-1 text-muted-foreground hover:bg-accent",
|
|
189
|
+
children: expanded ? /* @__PURE__ */ jsx(ChevronUp, { size: 16 }) : /* @__PURE__ */ jsx(ChevronDown, { size: 16 })
|
|
190
|
+
}
|
|
191
|
+
),
|
|
192
|
+
isChatAllowed && /* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
193
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
194
|
+
"button",
|
|
195
|
+
{
|
|
196
|
+
className: "shrink-0 rounded p-1 text-muted-foreground hover:bg-accent",
|
|
197
|
+
onClick: (e) => e.stopPropagation(),
|
|
198
|
+
children: /* @__PURE__ */ jsx(EllipsisVertical, { size: 16 })
|
|
199
|
+
}
|
|
200
|
+
) }),
|
|
201
|
+
/* @__PURE__ */ jsx(DropdownMenuContent, { align: "end", children: /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: () => handleUnpin(latestPin.id), children: [
|
|
202
|
+
/* @__PURE__ */ jsx(PinOff, { size: 14, className: "mr-2" }),
|
|
203
|
+
t("chat:action.unpin", { defaultValue: "B\u1ECF ghim" })
|
|
204
|
+
] }) })
|
|
205
|
+
] })
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
),
|
|
209
|
+
/* @__PURE__ */ jsx(
|
|
210
|
+
"div",
|
|
211
|
+
{
|
|
212
|
+
className: "grid transition-[grid-template-rows] duration-200 ease-in-out",
|
|
213
|
+
style: { gridTemplateRows: expanded ? "1fr" : "0fr" },
|
|
214
|
+
children: /* @__PURE__ */ jsx("div", { className: "overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "max-h-[200px] overflow-y-auto border-t", children: pins.slice(1).map((pin) => /* @__PURE__ */ jsxs(
|
|
215
|
+
"div",
|
|
216
|
+
{
|
|
217
|
+
onClick: () => handleClickPin(pin),
|
|
218
|
+
className: "flex cursor-pointer items-center gap-3 px-4 py-2 hover:bg-accent/50",
|
|
219
|
+
children: [
|
|
220
|
+
/* @__PURE__ */ jsx("div", { className: "flex size-9 shrink-0 items-center justify-center rounded-full", children: /* @__PURE__ */ jsx(MessageCircle, { size: 18, className: "text-muted-foreground" }) }),
|
|
221
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
222
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: t("common:label.message", { defaultValue: "Tin nh\u1EAFn" }) }),
|
|
223
|
+
/* @__PURE__ */ jsxs("p", { className: "flex items-center truncate text-sm text-muted-foreground", children: [
|
|
224
|
+
pin.senderName && /* @__PURE__ */ jsxs("span", { className: "mr-1", children: [
|
|
225
|
+
maskData(pin.senderName),
|
|
226
|
+
": "
|
|
227
|
+
] }),
|
|
228
|
+
renderPinContent(pin)
|
|
229
|
+
] })
|
|
230
|
+
] }),
|
|
231
|
+
isChatAllowed && /* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
232
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
233
|
+
"button",
|
|
234
|
+
{
|
|
235
|
+
onClick: (e) => e.stopPropagation(),
|
|
236
|
+
className: "shrink-0 rounded p-1 text-muted-foreground hover:bg-accent",
|
|
237
|
+
children: /* @__PURE__ */ jsx(EllipsisVertical, { size: 16 })
|
|
238
|
+
}
|
|
239
|
+
) }),
|
|
240
|
+
/* @__PURE__ */ jsx(DropdownMenuContent, { align: "end", children: /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: () => handleUnpin(pin.id), children: [
|
|
241
|
+
/* @__PURE__ */ jsx(PinOff, { size: 14, className: "mr-2" }),
|
|
242
|
+
t("chat:action.unpin", { defaultValue: "B\u1ECF ghim" })
|
|
243
|
+
] }) })
|
|
244
|
+
] })
|
|
245
|
+
]
|
|
246
|
+
},
|
|
247
|
+
pin.id
|
|
248
|
+
)) }) })
|
|
249
|
+
}
|
|
250
|
+
)
|
|
251
|
+
] });
|
|
252
|
+
}
|
|
253
|
+
export {
|
|
254
|
+
PinnedMessages as default
|
|
255
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
isFacebook,
|
|
4
|
+
isZalo,
|
|
5
|
+
isZaloPersonal
|
|
6
|
+
} from "../../util.js";
|
|
7
|
+
import { SourceDetailTicket } from "@zenify-omni/chat-js/constants/chat-source.js";
|
|
8
|
+
import { FB_REACTIONS } from "../constants.js";
|
|
9
|
+
import { ZALO_REACTIONS } from "./reaction-button.js";
|
|
10
|
+
const isWhatsApp = (ticket) => ticket?.source === SourceDetailTicket.WHATSAPP;
|
|
11
|
+
function ReactionPreview({
|
|
12
|
+
reactions = [],
|
|
13
|
+
ticket,
|
|
14
|
+
isPending = false
|
|
15
|
+
}) {
|
|
16
|
+
const isWA = isWhatsApp(ticket);
|
|
17
|
+
if (!isZalo(ticket) && !isZaloPersonal(ticket) && !isFacebook(ticket) && !isWA) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
if (!Array.isArray(reactions) || reactions.length === 0) return null;
|
|
21
|
+
if (isWA) {
|
|
22
|
+
const uniqueEmojis = [...new Set(reactions.map((r) => r.emoji))].slice(0, 3);
|
|
23
|
+
const totalReact2 = reactions.length;
|
|
24
|
+
return /* @__PURE__ */ jsxs(
|
|
25
|
+
"div",
|
|
26
|
+
{
|
|
27
|
+
className: `absolute bottom-0.5 right-6 inline-flex items-center justify-center gap-1 rounded-full bg-background px-1.5 py-0.5 shadow-xl ${isPending ? "animate-pulse opacity-80" : ""}`,
|
|
28
|
+
children: [
|
|
29
|
+
uniqueEmojis.map((emoji, index) => /* @__PURE__ */ jsx(
|
|
30
|
+
"span",
|
|
31
|
+
{
|
|
32
|
+
className: "flex h-4 w-4 items-center justify-center text-xs",
|
|
33
|
+
children: emoji
|
|
34
|
+
},
|
|
35
|
+
`${emoji}-${index}`
|
|
36
|
+
)),
|
|
37
|
+
totalReact2 > 0 && /* @__PURE__ */ jsx("span", { className: "ml-1 text-[10px] font-medium text-muted-foreground", children: totalReact2 })
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
const isFB = isFacebook(ticket);
|
|
43
|
+
const reactionSource = isFB ? FB_REACTIONS : ZALO_REACTIONS;
|
|
44
|
+
const getIconReact = (reaction) => {
|
|
45
|
+
if (isFB) {
|
|
46
|
+
return reactionSource.find((r) => r.rType === reaction?.reaction)?.icon || reaction?.emoji;
|
|
47
|
+
}
|
|
48
|
+
return reactionSource.find(
|
|
49
|
+
(r) => r.key === reaction || r.key === reaction?.rType
|
|
50
|
+
)?.icon;
|
|
51
|
+
};
|
|
52
|
+
const sortedReactions = [...reactions].sort(
|
|
53
|
+
(a, b) => isFB ? (a.timestamp || 0) - (b.timestamp || 0) : new Date(a.updated_at).getTime() - new Date(b.updated_at).getTime()
|
|
54
|
+
);
|
|
55
|
+
const visibleReactions = sortedReactions.filter((reaction, index, arr) => {
|
|
56
|
+
return isFB ? index === arr.findIndex((item) => item.reaction === reaction.reaction) : index === arr.findIndex((item) => item.rType === reaction.rType);
|
|
57
|
+
}).slice(0, 3);
|
|
58
|
+
const totalReact = sortedReactions.length;
|
|
59
|
+
return /* @__PURE__ */ jsxs(
|
|
60
|
+
"div",
|
|
61
|
+
{
|
|
62
|
+
className: `absolute bottom-0.5 right-6 inline-flex items-center justify-center gap-1 rounded-full bg-background px-1.5 py-0.5 shadow-xl ${isPending ? "animate-pulse opacity-80" : ""}`,
|
|
63
|
+
children: [
|
|
64
|
+
visibleReactions.map((reaction, index) => {
|
|
65
|
+
const icon = getIconReact(reaction) || reaction?.emoji;
|
|
66
|
+
if (!icon) return null;
|
|
67
|
+
return /* @__PURE__ */ jsx(
|
|
68
|
+
"span",
|
|
69
|
+
{
|
|
70
|
+
className: "flex h-4 w-4 items-center justify-center text-xs",
|
|
71
|
+
children: icon
|
|
72
|
+
},
|
|
73
|
+
`${reaction?.rType ?? reaction?.reaction}-${reaction?.updated_at ?? reaction?.timestamp}-${index}`
|
|
74
|
+
);
|
|
75
|
+
}),
|
|
76
|
+
totalReact > 0 && /* @__PURE__ */ jsx("span", { className: "ml-1 text-[10px] font-medium text-muted-foreground", children: totalReact })
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
ReactionPreview as default
|
|
83
|
+
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { FB_REACTIONS } from "../constants.js";
|
|
3
|
+
import { X } from "lucide-react";
|
|
4
|
+
import { cn } from "../../../../lib/utils.js";
|
|
5
|
+
import {
|
|
6
|
+
DropdownMenu,
|
|
7
|
+
DropdownMenuTrigger,
|
|
8
|
+
DropdownMenuContent,
|
|
9
|
+
DropdownMenuItem
|
|
10
|
+
} from "../../../ui/dropdown-menu.js";
|
|
11
|
+
import { isFacebook } from "../../util.js";
|
|
12
|
+
import { sendMessage } from "../../../../utils/chat_socket.js";
|
|
13
|
+
import { MessageType } from "@zenify-omni/chat-js/constants/chat-message.js";
|
|
14
|
+
import { useCallback, useState, useRef } from "react";
|
|
15
|
+
import Icon from "../../../custom/icon.js";
|
|
16
|
+
import useChatStore from "../../../../store/chat-store.js";
|
|
17
|
+
const FB_REACTION_CONFIRM_TIMEOUT_MS = 8e3;
|
|
18
|
+
const pendingFbReactionTimers = /* @__PURE__ */ new Map();
|
|
19
|
+
const ZALO_REACTIONS = [
|
|
20
|
+
{ key: 3, rType: 3, rIcon: "/-strong", icon: /* @__PURE__ */ jsx(Icon, { name: "emoji_like" }) },
|
|
21
|
+
{ key: 5, rType: 5, rIcon: "/-heart", icon: /* @__PURE__ */ jsx(Icon, { name: "emoji_love" }) },
|
|
22
|
+
{ key: 0, rType: 0, rIcon: ":>", icon: /* @__PURE__ */ jsx(Icon, { name: "emoji_haha" }) },
|
|
23
|
+
{ key: 32, rType: 32, rIcon: ":o", icon: /* @__PURE__ */ jsx(Icon, { name: "emoji_wow" }) },
|
|
24
|
+
{ key: 2, rType: 2, rIcon: ":-(", icon: /* @__PURE__ */ jsx(Icon, { name: "emoji_sad" }) },
|
|
25
|
+
{ key: 20, rType: 20, rIcon: ":-h", icon: /* @__PURE__ */ jsx(Icon, { name: "emoji_angry" }) },
|
|
26
|
+
{ key: "un_react", rType: -1, rIcon: "", icon: /* @__PURE__ */ jsx(X, { size: 16 }) }
|
|
27
|
+
];
|
|
28
|
+
const FB_UN_REACT = {
|
|
29
|
+
key: "un_react",
|
|
30
|
+
rType: "",
|
|
31
|
+
rIcon: "",
|
|
32
|
+
icon: /* @__PURE__ */ jsx(X, { size: 16 })
|
|
33
|
+
};
|
|
34
|
+
function ReactionButton({ isMychat, chatRoom, message }) {
|
|
35
|
+
const [open, setOpen] = useState(false);
|
|
36
|
+
const closeTimerRef = useRef(null);
|
|
37
|
+
const clearCloseTimer = () => {
|
|
38
|
+
if (closeTimerRef.current) {
|
|
39
|
+
clearTimeout(closeTimerRef.current);
|
|
40
|
+
closeTimerRef.current = null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const handleOpen = () => {
|
|
44
|
+
clearCloseTimer();
|
|
45
|
+
setOpen(true);
|
|
46
|
+
};
|
|
47
|
+
const handleClose = () => {
|
|
48
|
+
clearCloseTimer();
|
|
49
|
+
closeTimerRef.current = setTimeout(() => {
|
|
50
|
+
setOpen(false);
|
|
51
|
+
}, 120);
|
|
52
|
+
};
|
|
53
|
+
const getReactOption = () => {
|
|
54
|
+
const isFb = isFacebook(chatRoom);
|
|
55
|
+
const options = isFb ? FB_REACTIONS : ZALO_REACTIONS;
|
|
56
|
+
if (!getLastMyReact()) {
|
|
57
|
+
return options.filter((r) => r.key !== "un_react");
|
|
58
|
+
}
|
|
59
|
+
return isFb ? [...options, FB_UN_REACT] : options;
|
|
60
|
+
};
|
|
61
|
+
const isShowReact = message?.extra_data?.reactions && message?.extra_data?.reactions?.length;
|
|
62
|
+
const isPendingFbReaction = "_pendingReactionTs" in (message || {});
|
|
63
|
+
const getLastMyReact = () => {
|
|
64
|
+
const isFb = isFacebook(chatRoom);
|
|
65
|
+
const reacts = message?.extra_data?.reactions?.filter(
|
|
66
|
+
(e) => isFb ? e.user_id === chatRoom?.source_id : e.uid_from === chatRoom?.source_id
|
|
67
|
+
);
|
|
68
|
+
if (reacts && reacts.length > 0) {
|
|
69
|
+
return [...reacts].sort(
|
|
70
|
+
(a, b) => isFb ? (b.timestamp || 0) - (a.timestamp || 0) : new Date(b.updated_at) - new Date(a.updated_at)
|
|
71
|
+
)[0];
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
};
|
|
75
|
+
const getIconReact = () => {
|
|
76
|
+
const myReact = getLastMyReact();
|
|
77
|
+
if (myReact) {
|
|
78
|
+
const isFb = isFacebook(chatRoom);
|
|
79
|
+
const reactionSource = isFb ? FB_REACTIONS : ZALO_REACTIONS;
|
|
80
|
+
const matchKey = isFb ? myReact?.reaction : myReact?.rType;
|
|
81
|
+
return /* @__PURE__ */ jsx(
|
|
82
|
+
"span",
|
|
83
|
+
{
|
|
84
|
+
className: "flex h-4 w-4 items-center justify-center text-xs",
|
|
85
|
+
children: reactionSource.find((r) => r.rType === matchKey)?.icon
|
|
86
|
+
},
|
|
87
|
+
`${matchKey}-${myReact?.updated_at || myReact?.timestamp}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
};
|
|
92
|
+
const handleSendMessage = useCallback(
|
|
93
|
+
(msg, type = "text", fileName = null, react) => {
|
|
94
|
+
const content = msg?.trim();
|
|
95
|
+
const contentOption = {};
|
|
96
|
+
const options = {
|
|
97
|
+
is_personal_zalo: chatRoom?.is_personal_zalo
|
|
98
|
+
};
|
|
99
|
+
if (react) {
|
|
100
|
+
const isFb = isFacebook(chatRoom);
|
|
101
|
+
contentOption.reaction = {
|
|
102
|
+
type: MessageType.REACTION,
|
|
103
|
+
r_type: react.rType,
|
|
104
|
+
r_icon: react.rIcon,
|
|
105
|
+
msg_id: isFb ? message.extra_data?.msg_id : message.content?.meta?.msgId,
|
|
106
|
+
cli_msg_id: isFb ? void 0 : message.content?.meta?.cliMsgId
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
sendMessage(chatRoom, content, type, options, fileName, contentOption);
|
|
110
|
+
},
|
|
111
|
+
[chatRoom, message]
|
|
112
|
+
);
|
|
113
|
+
const applyOptimisticFbReaction = (react) => {
|
|
114
|
+
const roomId = chatRoom?._id;
|
|
115
|
+
const msgId = message?._id;
|
|
116
|
+
if (!roomId || !msgId) return;
|
|
117
|
+
const myUserId = chatRoom?.source_id;
|
|
118
|
+
const previousReactions = message?.extra_data?.reactions || [];
|
|
119
|
+
const opTs = Date.now();
|
|
120
|
+
const nextReactions = react.key === "un_react" ? previousReactions.filter((r) => r.user_id !== myUserId) : [
|
|
121
|
+
...previousReactions.filter((r) => r.user_id !== myUserId),
|
|
122
|
+
{
|
|
123
|
+
user_id: myUserId,
|
|
124
|
+
reaction: react.rType,
|
|
125
|
+
emoji: react.rIcon,
|
|
126
|
+
timestamp: opTs
|
|
127
|
+
}
|
|
128
|
+
];
|
|
129
|
+
useChatStore.getState().applyOptimisticReaction(roomId, msgId, nextReactions, opTs);
|
|
130
|
+
const timerKey = `${roomId}:${msgId}`;
|
|
131
|
+
const prevTimer = pendingFbReactionTimers.get(timerKey);
|
|
132
|
+
if (prevTimer) clearTimeout(prevTimer);
|
|
133
|
+
const timer = setTimeout(() => {
|
|
134
|
+
pendingFbReactionTimers.delete(timerKey);
|
|
135
|
+
useChatStore.getState().rollbackPendingReaction(roomId, msgId, opTs, previousReactions);
|
|
136
|
+
}, FB_REACTION_CONFIRM_TIMEOUT_MS);
|
|
137
|
+
pendingFbReactionTimers.set(timerKey, timer);
|
|
138
|
+
};
|
|
139
|
+
const onSelect = (react) => {
|
|
140
|
+
if (isFacebook(chatRoom)) {
|
|
141
|
+
applyOptimisticFbReaction(react);
|
|
142
|
+
}
|
|
143
|
+
handleSendMessage("", "reaction", null, react);
|
|
144
|
+
setOpen(false);
|
|
145
|
+
};
|
|
146
|
+
return /* @__PURE__ */ jsxs(DropdownMenu, { open, onOpenChange: setOpen, modal: false, children: [
|
|
147
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
148
|
+
"button",
|
|
149
|
+
{
|
|
150
|
+
type: "button",
|
|
151
|
+
onMouseEnter: handleOpen,
|
|
152
|
+
onMouseLeave: handleClose,
|
|
153
|
+
onClick: (e) => e.preventDefault(),
|
|
154
|
+
className: cn(
|
|
155
|
+
"inset-shadow-sm h-5 w-5 rounded-full bg-card p-0.5 text-muted-foreground opacity-0 transition-opacity duration-200 group-hover:opacity-100",
|
|
156
|
+
"data-[state=open]:!opacity-100",
|
|
157
|
+
"rounded-full",
|
|
158
|
+
(getIconReact() || isShowReact) && "opacity-100",
|
|
159
|
+
isPendingFbReaction && "animate-pulse !opacity-60"
|
|
160
|
+
),
|
|
161
|
+
children: getIconReact() ? getIconReact() : /* @__PURE__ */ jsx(Icon, { name: "emoji_like_outline", size: 16 })
|
|
162
|
+
}
|
|
163
|
+
) }),
|
|
164
|
+
/* @__PURE__ */ jsx(
|
|
165
|
+
DropdownMenuContent,
|
|
166
|
+
{
|
|
167
|
+
align: isMychat ? "end" : "start",
|
|
168
|
+
side: "top",
|
|
169
|
+
sideOffset: 4,
|
|
170
|
+
onMouseEnter: handleOpen,
|
|
171
|
+
onMouseLeave: handleClose,
|
|
172
|
+
onCloseAutoFocus: (e) => e.preventDefault(),
|
|
173
|
+
className: "flex w-fit flex-row gap-1 overflow-hidden rounded-full px-2.5 py-2 opacity-90",
|
|
174
|
+
children: getReactOption().map((r, index) => /* @__PURE__ */ jsx(
|
|
175
|
+
DropdownMenuItem,
|
|
176
|
+
{
|
|
177
|
+
onClick: () => onSelect(r),
|
|
178
|
+
className: "cursor-pointer p-0 hover:bg-transparent focus:bg-transparent",
|
|
179
|
+
children: /* @__PURE__ */ jsx(
|
|
180
|
+
"span",
|
|
181
|
+
{
|
|
182
|
+
className: "mx-1 inline-flex text-xl opacity-0",
|
|
183
|
+
style: {
|
|
184
|
+
animation: "reaction-pop-in 220ms ease-out forwards",
|
|
185
|
+
animationDelay: `${index * 30}ms`
|
|
186
|
+
},
|
|
187
|
+
children: /* @__PURE__ */ jsx("span", { className: "inline-block scale-125 transition-all duration-100 ease-out hover:-translate-y-1 hover:scale-150", children: r.icon })
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
},
|
|
191
|
+
r.key
|
|
192
|
+
))
|
|
193
|
+
}
|
|
194
|
+
)
|
|
195
|
+
] });
|
|
196
|
+
}
|
|
197
|
+
export {
|
|
198
|
+
ZALO_REACTIONS,
|
|
199
|
+
ReactionButton as default
|
|
200
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, Fragment } from "react";
|
|
3
|
+
import { ArrowLeft, LoaderCircle, ChevronDown } from "lucide-react";
|
|
4
|
+
import useIntersectionObserver from "../../../../hooks/use-intersection-observer.js";
|
|
5
|
+
import { Button } from "../../../custom/button.js";
|
|
6
|
+
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
7
|
+
import { getLastChatHistory } from "@zenify-omni/chat-js/api/chat.js";
|
|
8
|
+
import ChatMessage from "../chat-message.js";
|
|
9
|
+
import { toast } from "sonner";
|
|
10
|
+
import { normalizeChatMessagesBulk } from "../../../../store/chat-store.js";
|
|
11
|
+
import SeparatorWithText from "../../../custom/separator-with-text.js";
|
|
12
|
+
import QUERY_KEY from "@zenify-omni/chat-js/constants/use-query-key.js";
|
|
13
|
+
import { useTranslation } from "react-i18next";
|
|
14
|
+
import i18n from "@zenify-omni/chat-js/lib/i18n/index.js";
|
|
15
|
+
const PAGE_LIMIT = 20;
|
|
16
|
+
function ChatHistory({ selectedChat = {}, onHideHistory }) {
|
|
17
|
+
const { t } = useTranslation();
|
|
18
|
+
const ticketId = selectedChat._id;
|
|
19
|
+
const [topRef, isTopRefVisible] = useIntersectionObserver({
|
|
20
|
+
root: null,
|
|
21
|
+
threshold: 0.1
|
|
22
|
+
});
|
|
23
|
+
const [bottomRef, isBottomRefVisible] = useIntersectionObserver({
|
|
24
|
+
root: null,
|
|
25
|
+
threshold: 0.1
|
|
26
|
+
});
|
|
27
|
+
const containerRef = useRef(null);
|
|
28
|
+
const topMsgIdRef = useRef(null);
|
|
29
|
+
const scrollHeightRef = useRef(0);
|
|
30
|
+
const {
|
|
31
|
+
isLoading,
|
|
32
|
+
data: queryData,
|
|
33
|
+
hasNextPage,
|
|
34
|
+
fetchNextPage,
|
|
35
|
+
isFetchingNextPage
|
|
36
|
+
} = useInfiniteQuery({
|
|
37
|
+
queryKey: [QUERY_KEY.GET_LAST_CHAT_HISTORY, { ticketId }],
|
|
38
|
+
queryFn: async ({ pageParam = 1 }) => {
|
|
39
|
+
const { data } = await getLastChatHistory(
|
|
40
|
+
ticketId,
|
|
41
|
+
selectedChat.requester_id,
|
|
42
|
+
pageParam,
|
|
43
|
+
PAGE_LIMIT
|
|
44
|
+
);
|
|
45
|
+
if (!data || !data.length) {
|
|
46
|
+
toast.error(
|
|
47
|
+
i18n.t("chat:toast.loadOldMessagesFail", {
|
|
48
|
+
defaultValue: "T\u1EA3i tin nh\u1EAFn c\u0169 th\u1EA5t b\u1EA1i"
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
return data.reverse();
|
|
54
|
+
},
|
|
55
|
+
getNextPageParam: (lastPage) => {
|
|
56
|
+
if (!lastPage) return;
|
|
57
|
+
const lastPageLength = lastPage.length;
|
|
58
|
+
if (lastPageLength < PAGE_LIMIT) return null;
|
|
59
|
+
return lastPage[0]?._id;
|
|
60
|
+
},
|
|
61
|
+
initialPageParam: null
|
|
62
|
+
});
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!isTopRefVisible) return;
|
|
65
|
+
if (isLoading || isFetchingNextPage) return;
|
|
66
|
+
if (!hasNextPage) return;
|
|
67
|
+
fetchNextPage();
|
|
68
|
+
}, [isTopRefVisible]);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const scrollTimeout = setTimeout(() => {
|
|
71
|
+
bottomRef.current.scrollIntoView();
|
|
72
|
+
}, 100);
|
|
73
|
+
return () => clearTimeout(scrollTimeout);
|
|
74
|
+
}, [ticketId]);
|
|
75
|
+
let messages = [];
|
|
76
|
+
if (!isLoading) {
|
|
77
|
+
for (let i = (queryData?.pages?.length || 0) - 1; i >= 0; i--) {
|
|
78
|
+
const page = queryData?.pages[i] || [];
|
|
79
|
+
messages = [...messages, ...page];
|
|
80
|
+
}
|
|
81
|
+
messages = normalizeChatMessagesBulk(messages);
|
|
82
|
+
}
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const topMsgId = messages[0]?._id;
|
|
85
|
+
if (!topMsgId) return;
|
|
86
|
+
const msgContainer = containerRef.current;
|
|
87
|
+
const prevScrollHeight = scrollHeightRef.current;
|
|
88
|
+
if (!topMsgIdRef.current) {
|
|
89
|
+
topMsgIdRef.current = topMsgId;
|
|
90
|
+
}
|
|
91
|
+
if (topMsgIdRef.current !== topMsgId) {
|
|
92
|
+
topMsgIdRef.current = topMsgId;
|
|
93
|
+
msgContainer.scrollTop = msgContainer.scrollHeight - prevScrollHeight;
|
|
94
|
+
}
|
|
95
|
+
scrollHeightRef.current = msgContainer.scrollHeight;
|
|
96
|
+
}, [messages.length]);
|
|
97
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-full grow flex-col", children: [
|
|
98
|
+
/* @__PURE__ */ jsxs("div", { className: "flex h-[80px] items-center space-x-3 border-b pl-5", children: [
|
|
99
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: onHideHistory, children: /* @__PURE__ */ jsx(ArrowLeft, { size: 16 }) }),
|
|
100
|
+
/* @__PURE__ */ jsx("h4", { className: "text-md font-semibold", children: t("chat:title.recentMessageHistory", {
|
|
101
|
+
defaultValue: "L\u1ECBch s\u1EED tin nh\u1EAFn g\u1EA7n nh\u1EA5t v\u1EDBi kh\xE1ch h\xE0ng"
|
|
102
|
+
}) })
|
|
103
|
+
] }),
|
|
104
|
+
/* @__PURE__ */ jsxs("div", { className: "relative h-[calc(100%-80px)] bg-primary-foreground", children: [
|
|
105
|
+
/* @__PURE__ */ jsxs(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
ref: containerRef,
|
|
109
|
+
className: "h-full gap-2 overflow-y-scroll px-4 pb-4",
|
|
110
|
+
children: [
|
|
111
|
+
/* @__PURE__ */ jsx("div", { ref: topRef }),
|
|
112
|
+
messages?.length && !isLoading && !isFetchingNextPage ? messages.map((message) => {
|
|
113
|
+
if (message.dateLabel) {
|
|
114
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
115
|
+
/* @__PURE__ */ jsx(SeparatorWithText, { text: message.dateLabel }),
|
|
116
|
+
/* @__PURE__ */ jsx(ChatMessage, { message })
|
|
117
|
+
] }, message._id);
|
|
118
|
+
}
|
|
119
|
+
return /* @__PURE__ */ jsx(ChatMessage, { message }, message._id);
|
|
120
|
+
}) : /* @__PURE__ */ jsx("div", { className: "text-center text-sm", children: /* @__PURE__ */ jsx("span", { className: "italic", children: t("chat:empty.noChatHistory", {
|
|
121
|
+
defaultValue: "Kh\xF4ng t\xECm th\u1EA5y l\u1ECBch s\u1EED tr\xF2 chuy\u1EC7n"
|
|
122
|
+
}) }) }),
|
|
123
|
+
/* @__PURE__ */ jsx("div", { ref: bottomRef })
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
),
|
|
127
|
+
(isLoading || isFetchingNextPage) && /* @__PURE__ */ jsx("div", { className: "absolute right-[50%] top-2 rounded-full bg-card p-1", children: /* @__PURE__ */ jsx(LoaderCircle, { className: "animate-spin", size: 32 }) }),
|
|
128
|
+
!isBottomRefVisible && /* @__PURE__ */ jsx(
|
|
129
|
+
"div",
|
|
130
|
+
{
|
|
131
|
+
className: "z-1 absolute bottom-2 right-[40%] cursor-pointer rounded-full bg-card p-1 text-muted-foreground shadow-xl",
|
|
132
|
+
onClick: () => bottomRef.current.scrollIntoView({ behavior: "smooth" }),
|
|
133
|
+
"aria-label": "Scroll to bottom",
|
|
134
|
+
children: /* @__PURE__ */ jsx(ChevronDown, { size: 32, className: "translate-y-[1px] scale-[0.9]" })
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
] })
|
|
138
|
+
] });
|
|
139
|
+
}
|
|
140
|
+
export {
|
|
141
|
+
ChatHistory
|
|
142
|
+
};
|