@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,102 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import i18n from "@zenify-omni/chat-js/lib/i18n/index.js";
|
|
3
|
+
import { memo, useMemo, useState } from "react";
|
|
4
|
+
import { Loader2, Search, Send } from "lucide-react";
|
|
5
|
+
import { Dialog, DialogContent, DialogHeader } from "../../ui/dialog.js";
|
|
6
|
+
import { Input } from "../../ui/input.js";
|
|
7
|
+
import { Avatar, AvatarFallback, AvatarImage } from "../../ui/avatar.js";
|
|
8
|
+
import { Button } from "../../ui/button.js";
|
|
9
|
+
import { useQuery } from "@tanstack/react-query";
|
|
10
|
+
import { getListFriendZaloGroup } from "@zenify-omni/chat-js/api/chat.js";
|
|
11
|
+
import { throwException } from "../../../exceptions/throw-exception.js";
|
|
12
|
+
import { getUser } from "@zenify-omni/chat-js/utils/auth.js";
|
|
13
|
+
import { sendContactCardMessage } from "./send-contact-card.js";
|
|
14
|
+
const FriendCardItem = memo(({ friend, onSend }) => {
|
|
15
|
+
const displayName = friend?.name || friend?.zalo_name || "Unknown";
|
|
16
|
+
const initial = displayName.charAt(0).toUpperCase();
|
|
17
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-4 py-2", children: [
|
|
18
|
+
/* @__PURE__ */ jsxs(Avatar, { className: "h-9 w-9 flex-shrink-0", children: [
|
|
19
|
+
/* @__PURE__ */ jsx(AvatarImage, { src: friend?.avatar, alt: displayName }),
|
|
20
|
+
/* @__PURE__ */ jsx(AvatarFallback, { className: "text-xs", children: initial })
|
|
21
|
+
] }),
|
|
22
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
23
|
+
/* @__PURE__ */ jsx("p", { className: "truncate text-sm", children: displayName }),
|
|
24
|
+
/* @__PURE__ */ jsx("p", { className: "truncate text-xs text-muted-foreground", children: friend?.phone || "--" })
|
|
25
|
+
] }),
|
|
26
|
+
/* @__PURE__ */ jsxs(
|
|
27
|
+
Button,
|
|
28
|
+
{
|
|
29
|
+
variant: "outline",
|
|
30
|
+
size: "sm",
|
|
31
|
+
className: "h-7 gap-1 px-2 text-xs text-primary",
|
|
32
|
+
onClick: () => onSend(friend),
|
|
33
|
+
children: [
|
|
34
|
+
/* @__PURE__ */ jsx(Send, { className: "h-3.5 w-3.5" }),
|
|
35
|
+
i18n.t("common:action.send", {
|
|
36
|
+
defaultValue: "G\u1EEDi"
|
|
37
|
+
})
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
] });
|
|
42
|
+
});
|
|
43
|
+
FriendCardItem.displayName = "FriendCardItem";
|
|
44
|
+
const useZaloFriendList = (zaloId, open) => {
|
|
45
|
+
return useQuery({
|
|
46
|
+
queryKey: ["SendContactCardModal:friends", zaloId],
|
|
47
|
+
queryFn: async () => {
|
|
48
|
+
const { data } = await getListFriendZaloGroup(zaloId);
|
|
49
|
+
return data?.data ?? [];
|
|
50
|
+
},
|
|
51
|
+
enabled: !!zaloId && open,
|
|
52
|
+
onError: throwException
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
function SendContactCardModal({ open, onOpenChange, zaloId, chatRoom }) {
|
|
56
|
+
const user = getUser();
|
|
57
|
+
const [searchText, setSearchText] = useState("");
|
|
58
|
+
const { data: friendList = [], isLoading } = useZaloFriendList(zaloId, open);
|
|
59
|
+
const filtered = useMemo(() => {
|
|
60
|
+
const trimmed = searchText.trim().toLowerCase();
|
|
61
|
+
if (!trimmed) return friendList;
|
|
62
|
+
return friendList.filter(
|
|
63
|
+
(f) => f?.name?.toLowerCase().includes(trimmed) || f?.zalo_name?.toLowerCase().includes(trimmed) || f?.phone?.toLowerCase().includes(trimmed)
|
|
64
|
+
);
|
|
65
|
+
}, [friendList, searchText]);
|
|
66
|
+
const handleSend = (friend) => {
|
|
67
|
+
onOpenChange(false);
|
|
68
|
+
sendContactCardMessage({ chatRoom, user, contact: friend });
|
|
69
|
+
};
|
|
70
|
+
return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(DialogContent, { className: "flex max-h-[80vh] max-w-md flex-col gap-1 overflow-hidden p-0", children: [
|
|
71
|
+
/* @__PURE__ */ jsx(DialogHeader, { className: "px-4 pb-1 pt-5", children: /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold", children: i18n.t("chat:label.guiDanhThiep", {
|
|
72
|
+
defaultValue: "G\u1EEDi danh thi\u1EBFp"
|
|
73
|
+
}) }) }),
|
|
74
|
+
/* @__PURE__ */ jsx("div", { className: "px-4 pt-2", children: /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
75
|
+
/* @__PURE__ */ jsx(Search, { className: "absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" }),
|
|
76
|
+
/* @__PURE__ */ jsx(
|
|
77
|
+
Input,
|
|
78
|
+
{
|
|
79
|
+
className: "h-8 pl-8 text-sm",
|
|
80
|
+
placeholder: i18n.t("chat:placeholder.searchNameOrPhone", {
|
|
81
|
+
defaultValue: "T\xECm ki\u1EBFm t\xEAn ho\u1EB7c s\u1ED1 \u0111i\u1EC7n tho\u1EA1i"
|
|
82
|
+
}),
|
|
83
|
+
value: searchText,
|
|
84
|
+
onChange: (e) => setSearchText(e.target.value)
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
] }) }),
|
|
88
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-y-auto py-2", children: isLoading ? /* @__PURE__ */ jsx("div", { className: "flex h-32 items-center justify-center", children: /* @__PURE__ */ jsx(Loader2, { className: "h-5 w-5 animate-spin text-muted-foreground" }) }) : filtered.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex h-32 items-center justify-center", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: i18n.t("chat:empty.noFriends", {
|
|
89
|
+
defaultValue: "Kh\xF4ng c\xF3 b\u1EA1n b\xE8 n\xE0o"
|
|
90
|
+
}) }) }) : filtered.map((friend) => /* @__PURE__ */ jsx(
|
|
91
|
+
FriendCardItem,
|
|
92
|
+
{
|
|
93
|
+
friend,
|
|
94
|
+
onSend: handleSend
|
|
95
|
+
},
|
|
96
|
+
friend.zalo_id
|
|
97
|
+
)) })
|
|
98
|
+
] }) });
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
SendContactCardModal
|
|
102
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import i18n from "@zenify-omni/chat-js/lib/i18n/index.js";
|
|
2
|
+
import { v4 as uuidv4 } from "uuid";
|
|
3
|
+
import { toast } from "sonner";
|
|
4
|
+
import useChatStore from "../../../store/chat-store.js";
|
|
5
|
+
import { sendZaloPersonalContactCard } from "@zenify-omni/chat-js/api/chat.js";
|
|
6
|
+
import { throwException } from "../../../exceptions/throw-exception.js";
|
|
7
|
+
import { isZaloGroup } from "../util.js";
|
|
8
|
+
const buildContactCardContent = (contact, contactName, qr) => ({
|
|
9
|
+
type: "contact_card",
|
|
10
|
+
text: contactName,
|
|
11
|
+
meta: {
|
|
12
|
+
content_obj: {
|
|
13
|
+
title: contactName,
|
|
14
|
+
phone: contact.phone,
|
|
15
|
+
avatar: contact.avatar,
|
|
16
|
+
zalo_id: contact.zalo_id,
|
|
17
|
+
...qr ? { qr } : {}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
async function sendContactCardMessage({ chatRoom, user, contact }) {
|
|
22
|
+
const clientMsgId = uuidv4();
|
|
23
|
+
const contactName = contact.name || contact.zalo_name;
|
|
24
|
+
const roomId = chatRoom._id;
|
|
25
|
+
useChatStore.getState().addNewMessage(roomId, {
|
|
26
|
+
_id: clientMsgId,
|
|
27
|
+
client_msg_id: clientMsgId,
|
|
28
|
+
room_id: roomId,
|
|
29
|
+
chatter_id: user?._id,
|
|
30
|
+
chatter_name: user?.name,
|
|
31
|
+
chatter_type: "agent",
|
|
32
|
+
source: chatRoom.source,
|
|
33
|
+
session_id: chatRoom.session?._id,
|
|
34
|
+
session: chatRoom.session,
|
|
35
|
+
content: buildContactCardContent(contact, contactName),
|
|
36
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
37
|
+
status: "pending"
|
|
38
|
+
});
|
|
39
|
+
try {
|
|
40
|
+
const { data: body } = await sendZaloPersonalContactCard({
|
|
41
|
+
sourceId: chatRoom?.source_id,
|
|
42
|
+
userZaloId: chatRoom?.source_room_id,
|
|
43
|
+
isGroup: isZaloGroup(chatRoom),
|
|
44
|
+
roomId,
|
|
45
|
+
sessionId: chatRoom.session?._id,
|
|
46
|
+
clientMsgId,
|
|
47
|
+
chatterId: user?._id,
|
|
48
|
+
chatterName: user?.name,
|
|
49
|
+
chatterAvatar: user?.avatar,
|
|
50
|
+
contactZaloId: contact.zalo_id,
|
|
51
|
+
contactName,
|
|
52
|
+
contactPhone: contact.phone,
|
|
53
|
+
contactAvatar: contact.avatar
|
|
54
|
+
});
|
|
55
|
+
if (body?.success) {
|
|
56
|
+
useChatStore.getState().updateMessageByClientMsgId(roomId, clientMsgId, {
|
|
57
|
+
_id: body.data.chat_message_id,
|
|
58
|
+
status: "success",
|
|
59
|
+
content: buildContactCardContent(contact, contactName, body.data.qr)
|
|
60
|
+
});
|
|
61
|
+
} else {
|
|
62
|
+
useChatStore.getState().updateMessageByClientMsgId(roomId, clientMsgId, {
|
|
63
|
+
_id: body?.data?.chat_message_id ?? clientMsgId,
|
|
64
|
+
status: "failed"
|
|
65
|
+
});
|
|
66
|
+
toast.error(
|
|
67
|
+
body?.data?.error || i18n.t("chat:label.guiDanhThiepThatBai", {
|
|
68
|
+
defaultValue: "G\u1EEDi danh thi\u1EBFp th\u1EA5t b\u1EA1i"
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
useChatStore.getState().updateMessageByClientMsgId(roomId, clientMsgId, { status: "failed" });
|
|
74
|
+
throwException(err);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
buildContactCardContent,
|
|
79
|
+
sendContactCardMessage
|
|
80
|
+
};
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useCallback } from "react";
|
|
3
|
+
import { cn } from "../../../lib/utils.js";
|
|
4
|
+
import { formatDayWithTime } from "@zenify-omni/chat-js/utils/date.js";
|
|
5
|
+
import { Button } from "../../custom/button.js";
|
|
6
|
+
import { Separator } from "../../ui/separator.js";
|
|
7
|
+
import { EMAIL_REGEX } from "@zenify-omni/chat-js/constants/regex.js";
|
|
8
|
+
import { LinkPreview } from "../../custom/previews/link-preview.js";
|
|
9
|
+
import useChatStore from "../../../store/chat-store.js";
|
|
10
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
11
|
+
import { updateContact } from "@zenify-omni/chat-js/api/contact.js";
|
|
12
|
+
import { autoAssignTagChatRoom } from "@zenify-omni/chat-js/api/chatroom.js";
|
|
13
|
+
import { AutoAssignTagTrigger } from "@zenify-omni/chat-js/constants/auto-assign-tag.js";
|
|
14
|
+
import { showDuplicatePhoneWarning } from "../../leads-route/duplicate-phone-warning-toast.js";
|
|
15
|
+
import { isDuplicateContactWarning } from "@zenify-omni/chat-js/constants/user.js";
|
|
16
|
+
import { throwException } from "../../../exceptions/throw-exception.js";
|
|
17
|
+
import { showInfoToast, showSuccessToast } from "../../ui/sonner.js";
|
|
18
|
+
import { convertURLsToLinks, getFirstURL } from "@zenify-omni/chat-js/utils/string.js";
|
|
19
|
+
import { replaceEmoticons } from "@zenify-omni/chat-js/utils/emoticon.js";
|
|
20
|
+
import { replaceZaloSprite } from "../../../utils/replaceZaloSprite.js";
|
|
21
|
+
import { maskData } from "@zenify-omni/chat-js/utils/data.js";
|
|
22
|
+
import { findVNPhonesInText, isVNPhoneLike } from "@zenify-omni/chat-js/lib/phone.js";
|
|
23
|
+
import SafeHTML from "../../custom/SafeHTML.js";
|
|
24
|
+
import { MessageTime } from "./message-time.js";
|
|
25
|
+
import { getUser } from "@zenify-omni/chat-js/utils/auth.js";
|
|
26
|
+
import {
|
|
27
|
+
isZaloGroup,
|
|
28
|
+
isZaloGeneralChannel,
|
|
29
|
+
isZaloPersonChannel,
|
|
30
|
+
isAgentStyle
|
|
31
|
+
} from "../util.js";
|
|
32
|
+
import { ChatReplyPreview } from "./chat-reply-preview.js";
|
|
33
|
+
import QUERY_KEY from "@zenify-omni/chat-js/constants/use-query-key.js";
|
|
34
|
+
import { CHATTER_TYPES } from "./constants.js";
|
|
35
|
+
import { getZaloMessageStyles, zaloRtfToDisplayHtml } from "./zalo-rtf-utils.js";
|
|
36
|
+
import { useTranslation } from "react-i18next";
|
|
37
|
+
import i18n from "@zenify-omni/chat-js/lib/i18n/index.js";
|
|
38
|
+
const CUSTOMER_TYPES = [CHATTER_TYPES.CONTACT, CHATTER_TYPES.CUSTOMER];
|
|
39
|
+
const TOAST_MESSAGES = {
|
|
40
|
+
EMAIL_EXISTS: "Email \u0111\xE3 t\u1ED3n t\u1EA1i",
|
|
41
|
+
PHONE_EXISTS: "S\u1ED1 \u0111i\u1EC7n tho\u1EA1i \u0111\xE3 t\u1ED3n t\u1EA1i",
|
|
42
|
+
BOTH_EXIST: "Email v\xE0 s\u1ED1 \u0111i\u1EC7n tho\u1EA1i \u0111\xE3 t\u1ED3n t\u1EA1i",
|
|
43
|
+
UPDATE_SUCCESS: "C\u1EADp nh\u1EADt th\xF4ng tin li\xEAn h\u1EC7 th\xE0nh c\xF4ng",
|
|
44
|
+
UPDATE_FAILED: "C\u1EADp nh\u1EADt li\xEAn h\u1EC7 th\u1EA5t b\u1EA1i"
|
|
45
|
+
};
|
|
46
|
+
const wrapWithHighlight = (text) => `<strong class="underline text-primary">${text}</strong>`;
|
|
47
|
+
const wrapOrder = (text) => `<strong class="underline text-chart-9">${text}</strong>`;
|
|
48
|
+
const highlightPatterns = (str, regex) => {
|
|
49
|
+
if (!str) return str;
|
|
50
|
+
return str.replace(regex, wrapWithHighlight);
|
|
51
|
+
};
|
|
52
|
+
const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
53
|
+
const highlightEntities = (str, values, wrap) => {
|
|
54
|
+
if (!str || !values?.length) return str;
|
|
55
|
+
const uniq = [...new Set(values.filter(Boolean).map(String))].sort(
|
|
56
|
+
(a, b) => b.length - a.length
|
|
57
|
+
);
|
|
58
|
+
if (!uniq.length) return str;
|
|
59
|
+
const pattern = new RegExp(uniq.map(escapeRegExp).join("|"), "g");
|
|
60
|
+
return str.replace(pattern, wrap);
|
|
61
|
+
};
|
|
62
|
+
const extractMatches = (content, regex) => {
|
|
63
|
+
if (!content) return [];
|
|
64
|
+
const freshRegex = new RegExp(regex.source, regex.flags);
|
|
65
|
+
return [...content.matchAll(freshRegex)].map((match) => match[0]);
|
|
66
|
+
};
|
|
67
|
+
const normalizePhoneNumber = (phone) => phone?.replace(/\D/g, "") ?? "";
|
|
68
|
+
const getMessageStyleClass = (msg, ticket, userId) => {
|
|
69
|
+
if (msg.target) {
|
|
70
|
+
return "bg-[--label-orange] text-[--label-orange-foreground]";
|
|
71
|
+
}
|
|
72
|
+
const isAgentMessage = msg.chatter_type === CHATTER_TYPES.AGENT;
|
|
73
|
+
const isNonGroupOrGeneral = !isZaloGroup(ticket) || isZaloGeneralChannel(ticket);
|
|
74
|
+
const isPersonChannelOwner = isZaloPersonChannel(ticket) && userId === msg.chatter_id;
|
|
75
|
+
const isSameSource = msg.source_id && ticket?.source_id && msg.source_id === ticket.source_id;
|
|
76
|
+
if (isSameSource || isAgentMessage && isNonGroupOrGeneral || isPersonChannelOwner) {
|
|
77
|
+
return "border border-chat-own-bubble bg-chat-own-bubble text-accent-foreground";
|
|
78
|
+
}
|
|
79
|
+
if (msg.chatter_type === CHATTER_TYPES.CHATBOT) {
|
|
80
|
+
return "bg-[--label-orange] text-accent-foreground";
|
|
81
|
+
}
|
|
82
|
+
return "bg-card text-foreground";
|
|
83
|
+
};
|
|
84
|
+
const useContactUpdate = (ticketId, updateRequester) => {
|
|
85
|
+
const queryClient = useQueryClient();
|
|
86
|
+
return useMutation({
|
|
87
|
+
mutationKey: ["updateContact", ticketId],
|
|
88
|
+
mutationFn: async (payload) => {
|
|
89
|
+
const { error, message, data } = await updateContact(payload);
|
|
90
|
+
if (error) {
|
|
91
|
+
throwException({
|
|
92
|
+
title: TOAST_MESSAGES.UPDATE_FAILED,
|
|
93
|
+
message
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return data ?? {};
|
|
97
|
+
},
|
|
98
|
+
onSuccess: (data, variables) => {
|
|
99
|
+
if (isDuplicateContactWarning(data?.type)) {
|
|
100
|
+
showDuplicatePhoneWarning(variables.id, data);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
showSuccessToast(TOAST_MESSAGES.UPDATE_SUCCESS);
|
|
104
|
+
updateRequester(ticketId, data);
|
|
105
|
+
queryClient.invalidateQueries({
|
|
106
|
+
queryKey: [QUERY_KEY.GET_CUSTOMER_DETAIL, data._id]
|
|
107
|
+
});
|
|
108
|
+
useChatStore.getState().setSubInfoExpanded(true);
|
|
109
|
+
},
|
|
110
|
+
onError: throwException
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
const useExtractedContactInfo = (content, chatterType, aiEntities) => {
|
|
114
|
+
return useMemo(() => {
|
|
115
|
+
if (!CUSTOMER_TYPES.includes(chatterType) || !content) {
|
|
116
|
+
return { emails: [], phoneNumbers: [], processedContent: content };
|
|
117
|
+
}
|
|
118
|
+
const regexEmails = extractMatches(content, EMAIL_REGEX).map(
|
|
119
|
+
(e) => e.toLowerCase()
|
|
120
|
+
);
|
|
121
|
+
const libPhones = findVNPhonesInText(content);
|
|
122
|
+
const aiPhones = (aiEntities?.phones || []).filter(
|
|
123
|
+
(p) => isVNPhoneLike(String(p))
|
|
124
|
+
);
|
|
125
|
+
const aiEmails = (aiEntities?.emails || []).map(
|
|
126
|
+
(e) => String(e).toLowerCase()
|
|
127
|
+
);
|
|
128
|
+
const aiOrders = aiEntities?.orders || [];
|
|
129
|
+
const emails = [.../* @__PURE__ */ new Set([...regexEmails, ...aiEmails])];
|
|
130
|
+
const phoneNumbers = [.../* @__PURE__ */ new Set([...libPhones, ...aiPhones])];
|
|
131
|
+
let processedContent = content;
|
|
132
|
+
processedContent = highlightEntities(processedContent, aiOrders, wrapOrder);
|
|
133
|
+
if (regexEmails.length) {
|
|
134
|
+
processedContent = highlightPatterns(processedContent, EMAIL_REGEX);
|
|
135
|
+
}
|
|
136
|
+
processedContent = highlightEntities(
|
|
137
|
+
processedContent,
|
|
138
|
+
libPhones,
|
|
139
|
+
wrapWithHighlight
|
|
140
|
+
);
|
|
141
|
+
const missedPhones = aiPhones.filter((p) => !libPhones.includes(p));
|
|
142
|
+
const missedEmails = aiEmails.filter((e) => !regexEmails.includes(e));
|
|
143
|
+
processedContent = highlightEntities(
|
|
144
|
+
processedContent,
|
|
145
|
+
[...missedPhones, ...missedEmails],
|
|
146
|
+
wrapWithHighlight
|
|
147
|
+
);
|
|
148
|
+
return { emails, phoneNumbers, processedContent };
|
|
149
|
+
}, [content, chatterType, aiEntities]);
|
|
150
|
+
};
|
|
151
|
+
function SaveContactButton({ onClick, isLoading }) {
|
|
152
|
+
const { t } = useTranslation();
|
|
153
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
154
|
+
/* @__PURE__ */ jsx(Separator, {}),
|
|
155
|
+
/* @__PURE__ */ jsx("div", { className: "my-1 flex w-full flex-row justify-end py-2", children: /* @__PURE__ */ jsx(Button, { loading: isLoading, onClick, children: t("chat:action.saveContact", { defaultValue: "L\u01B0u li\xEAn h\u1EC7" }) }) })
|
|
156
|
+
] });
|
|
157
|
+
}
|
|
158
|
+
function TextContent({
|
|
159
|
+
msg,
|
|
160
|
+
className,
|
|
161
|
+
isReply,
|
|
162
|
+
// `ticket` ở luồng chat thực chất là chat room. Prop `chatRoom` là tên đúng,
|
|
163
|
+
// fallback về `ticket` vì một số nơi gọi TextContent chưa truyền prop mới.
|
|
164
|
+
chatRoom: chatRoomProp,
|
|
165
|
+
ticket,
|
|
166
|
+
ticketId,
|
|
167
|
+
requester,
|
|
168
|
+
timeText,
|
|
169
|
+
undoToggle,
|
|
170
|
+
isUndoPlaceholder,
|
|
171
|
+
undoByName
|
|
172
|
+
}) {
|
|
173
|
+
const { t } = useTranslation();
|
|
174
|
+
const user = getUser();
|
|
175
|
+
const chatRoom = chatRoomProp ?? ticket;
|
|
176
|
+
const updateRequester = useChatStore((state) => state.updateRequester);
|
|
177
|
+
const { emails, phoneNumbers, processedContent } = useExtractedContactInfo(
|
|
178
|
+
msg.content.text,
|
|
179
|
+
msg.chatter_type,
|
|
180
|
+
void 0
|
|
181
|
+
);
|
|
182
|
+
const updateMutation = useContactUpdate(ticket?._id, updateRequester);
|
|
183
|
+
const autoAssignTagsMutation = useMutation({
|
|
184
|
+
mutationFn: autoAssignTagChatRoom
|
|
185
|
+
});
|
|
186
|
+
const handleSaveInfo = useCallback(() => {
|
|
187
|
+
if (!requester) {
|
|
188
|
+
showInfoToast(
|
|
189
|
+
i18n.t("chat:empty.noContactInfoToSave", {
|
|
190
|
+
defaultValue: "Kh\xF4ng t\xECm th\u1EA5y th\xF4ng tin li\xEAn h\u1EC7 \u0111\u1EC3 l\u01B0u"
|
|
191
|
+
})
|
|
192
|
+
);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const payload = {};
|
|
196
|
+
const emailsToAdd = [...emails];
|
|
197
|
+
const phonesToAdd = [...phoneNumbers].map(normalizePhoneNumber);
|
|
198
|
+
let isEmailExisting = false;
|
|
199
|
+
let isPhoneExisting = false;
|
|
200
|
+
if (emailsToAdd.length) {
|
|
201
|
+
const existingIndex = emailsToAdd.indexOf(requester.email);
|
|
202
|
+
if (existingIndex !== -1) {
|
|
203
|
+
emailsToAdd.splice(existingIndex, 1);
|
|
204
|
+
isEmailExisting = true;
|
|
205
|
+
}
|
|
206
|
+
if (!requester.email && emailsToAdd.length) {
|
|
207
|
+
payload.email = emailsToAdd.shift();
|
|
208
|
+
}
|
|
209
|
+
if (emailsToAdd.length) {
|
|
210
|
+
payload.$addToSet = {
|
|
211
|
+
...payload.$addToSet,
|
|
212
|
+
sub_email: { $each: emailsToAdd }
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (phonesToAdd.length) {
|
|
217
|
+
const existingIndex = phonesToAdd.indexOf(requester.phone);
|
|
218
|
+
if (existingIndex !== -1) {
|
|
219
|
+
phonesToAdd.splice(existingIndex, 1);
|
|
220
|
+
isPhoneExisting = true;
|
|
221
|
+
}
|
|
222
|
+
if (!requester.phone && phonesToAdd.length) {
|
|
223
|
+
payload.phone = phonesToAdd.shift();
|
|
224
|
+
}
|
|
225
|
+
if (phonesToAdd.length) {
|
|
226
|
+
payload.$addToSet = {
|
|
227
|
+
...payload.$addToSet,
|
|
228
|
+
sub_phone: { $each: phonesToAdd }
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (Object.keys(payload).length === 0) {
|
|
233
|
+
if (isEmailExisting && isPhoneExisting) {
|
|
234
|
+
showInfoToast(TOAST_MESSAGES.BOTH_EXIST);
|
|
235
|
+
} else if (isPhoneExisting) {
|
|
236
|
+
showInfoToast(TOAST_MESSAGES.PHONE_EXISTS);
|
|
237
|
+
} else if (isEmailExisting) {
|
|
238
|
+
showInfoToast(TOAST_MESSAGES.EMAIL_EXISTS);
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const savedPhones = [
|
|
243
|
+
payload.phone,
|
|
244
|
+
...payload.$addToSet?.sub_phone?.$each ?? []
|
|
245
|
+
].filter(Boolean);
|
|
246
|
+
const contactId = requester._id || chatRoom?.requester_id || chatRoom?.customer_ids?.[0];
|
|
247
|
+
updateMutation.mutate(
|
|
248
|
+
{ id: contactId, data: payload },
|
|
249
|
+
{
|
|
250
|
+
onSuccess: (data) => {
|
|
251
|
+
if (isDuplicateContactWarning(data?.type)) return;
|
|
252
|
+
if (!savedPhones.length || !chatRoom?._id) return;
|
|
253
|
+
autoAssignTagsMutation.mutate({
|
|
254
|
+
chatRoomId: chatRoom._id,
|
|
255
|
+
data: {
|
|
256
|
+
triggers: [
|
|
257
|
+
{
|
|
258
|
+
type: AutoAssignTagTrigger.SAVE_CONTACT,
|
|
259
|
+
context: { phones: savedPhones, contact_id: contactId }
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
}, [
|
|
268
|
+
emails,
|
|
269
|
+
phoneNumbers,
|
|
270
|
+
requester,
|
|
271
|
+
chatRoom,
|
|
272
|
+
updateMutation,
|
|
273
|
+
autoAssignTagsMutation
|
|
274
|
+
]);
|
|
275
|
+
const { displayContent, allowStyledRtf } = useMemo(() => {
|
|
276
|
+
const rawText = msg.content?.text ?? "";
|
|
277
|
+
const looksLikeHtml = /<\/?[a-z][\s\S]*>/i.test(rawText);
|
|
278
|
+
const styles = getZaloMessageStyles(msg);
|
|
279
|
+
const isIncoming = CUSTOMER_TYPES.includes(msg.chatter_type);
|
|
280
|
+
if (styles.length > 0 && rawText && !looksLikeHtml) {
|
|
281
|
+
const html = zaloRtfToDisplayHtml(rawText, styles);
|
|
282
|
+
const maskedHtml = isIncoming ? maskData(html) : html;
|
|
283
|
+
return {
|
|
284
|
+
displayContent: replaceEmoticons(
|
|
285
|
+
replaceZaloSprite(convertURLsToLinks(maskedHtml))
|
|
286
|
+
),
|
|
287
|
+
allowStyledRtf: true
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
const text = processedContent ?? "";
|
|
291
|
+
const maskedText = isIncoming ? maskData(text) : text;
|
|
292
|
+
const withLineBreaks = maskedText?.replace(/\n/g, "<br/>");
|
|
293
|
+
return {
|
|
294
|
+
displayContent: replaceEmoticons(
|
|
295
|
+
replaceZaloSprite(convertURLsToLinks(withLineBreaks))
|
|
296
|
+
),
|
|
297
|
+
allowStyledRtf: false
|
|
298
|
+
};
|
|
299
|
+
}, [msg, processedContent]);
|
|
300
|
+
const messageStyleClass = getMessageStyleClass(msg, ticket, user?._id);
|
|
301
|
+
const hasContactActions = useMemo(() => {
|
|
302
|
+
const hasExtracted = emails.length > 0 || phoneNumbers.length > 0;
|
|
303
|
+
if (!hasExtracted) return false;
|
|
304
|
+
if (!requester) return true;
|
|
305
|
+
const existingPhones = new Set(
|
|
306
|
+
[requester.phone, ...requester.sub_phone || []].map(normalizePhoneNumber).filter(Boolean)
|
|
307
|
+
);
|
|
308
|
+
const hasNewPhone = phoneNumbers.some(
|
|
309
|
+
(phone) => !existingPhones.has(normalizePhoneNumber(phone))
|
|
310
|
+
);
|
|
311
|
+
const existingEmails = new Set(
|
|
312
|
+
[requester.email, ...requester.sub_email || []].filter(Boolean).map((email) => String(email).toLowerCase())
|
|
313
|
+
);
|
|
314
|
+
const hasNewEmail = emails.some(
|
|
315
|
+
(email) => !existingEmails.has(String(email).toLowerCase())
|
|
316
|
+
);
|
|
317
|
+
return hasNewPhone || hasNewEmail;
|
|
318
|
+
}, [emails, phoneNumbers, requester]);
|
|
319
|
+
const previewUrl = useMemo(() => {
|
|
320
|
+
if (isReply) return null;
|
|
321
|
+
const rawText = msg.content?.text;
|
|
322
|
+
if (!rawText) return null;
|
|
323
|
+
return getFirstURL(rawText);
|
|
324
|
+
}, [msg.content?.text, isReply]);
|
|
325
|
+
return /* @__PURE__ */ jsxs(
|
|
326
|
+
"div",
|
|
327
|
+
{
|
|
328
|
+
className: cn(
|
|
329
|
+
"w-full break-words rounded-[8px] px-4 py-2 shadow-md",
|
|
330
|
+
messageStyleClass,
|
|
331
|
+
isReply && "m-0 truncate border-none bg-transparent !p-0 text-xs text-card-foreground shadow-none",
|
|
332
|
+
className
|
|
333
|
+
),
|
|
334
|
+
title: formatDayWithTime(msg.created_at),
|
|
335
|
+
children: [
|
|
336
|
+
msg.extra_data?.reply_msg_info && !isUndoPlaceholder && /* @__PURE__ */ jsx(
|
|
337
|
+
ChatReplyPreview,
|
|
338
|
+
{
|
|
339
|
+
isAgent: isAgentStyle({ msg, ticket, user }),
|
|
340
|
+
ticketId,
|
|
341
|
+
isView: true,
|
|
342
|
+
classNameContent: "text-card-foreground",
|
|
343
|
+
className: "!m-0",
|
|
344
|
+
replyContent: {
|
|
345
|
+
...msg.extra_data?.reply_msg_info,
|
|
346
|
+
_id: msg.extra_data?.reply_msg_info?.chat_message_id || msg.extra_data?.reply_msg_info?._id
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
),
|
|
350
|
+
undoToggle ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
|
|
351
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
352
|
+
/* @__PURE__ */ jsx(
|
|
353
|
+
SafeHTML,
|
|
354
|
+
{
|
|
355
|
+
isReply: true,
|
|
356
|
+
className: cn("flex-1", isUndoPlaceholder && "italic opacity-60"),
|
|
357
|
+
html: displayContent,
|
|
358
|
+
allowStyledRtf
|
|
359
|
+
}
|
|
360
|
+
),
|
|
361
|
+
undoToggle
|
|
362
|
+
] }),
|
|
363
|
+
undoByName && isUndoPlaceholder && /* @__PURE__ */ jsx("span", { className: "self-end text-[11px] italic text-muted-foreground", children: t("chat:label.performedBy", {
|
|
364
|
+
undoByName,
|
|
365
|
+
defaultValue: "Th\u1EF1c hi\u1EC7n b\u1EDFi: {undoByName}"
|
|
366
|
+
}) })
|
|
367
|
+
] }) : /* @__PURE__ */ jsx(
|
|
368
|
+
SafeHTML,
|
|
369
|
+
{
|
|
370
|
+
isReply: true,
|
|
371
|
+
html: displayContent,
|
|
372
|
+
allowStyledRtf
|
|
373
|
+
}
|
|
374
|
+
),
|
|
375
|
+
previewUrl && /* @__PURE__ */ jsx("div", { className: "mt-2", children: /* @__PURE__ */ jsx(LinkPreview, { url: previewUrl, compact: true }) }),
|
|
376
|
+
hasContactActions && /* @__PURE__ */ jsx(
|
|
377
|
+
SaveContactButton,
|
|
378
|
+
{
|
|
379
|
+
onClick: handleSaveInfo,
|
|
380
|
+
isLoading: updateMutation.isPending
|
|
381
|
+
}
|
|
382
|
+
),
|
|
383
|
+
msg.extra_data?.tag === "HUMAN_AGENT" && /* @__PURE__ */ jsx("div", { className: "text-xs italic text-muted-foreground", children: t("chat:message.humanAgentTagNote", {
|
|
384
|
+
defaultValue: "*Tin nh\u1EAFn \u0111\u01B0\u1EE3c g\u1EEDi v\u1EDBi Human Agent tag"
|
|
385
|
+
}) }),
|
|
386
|
+
/* @__PURE__ */ jsx(
|
|
387
|
+
MessageTime,
|
|
388
|
+
{
|
|
389
|
+
timeText,
|
|
390
|
+
status: msg?.status,
|
|
391
|
+
agentReads: msg?.agent_reads
|
|
392
|
+
}
|
|
393
|
+
)
|
|
394
|
+
]
|
|
395
|
+
}
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
export {
|
|
399
|
+
TextContent
|
|
400
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { getPageDetail } from "@zenify-omni/chat-js/api/settings/channel.js";
|
|
3
|
+
import QUERY_KEY from "@zenify-omni/chat-js/constants/use-query-key.js";
|
|
4
|
+
import { isFacebook } from "../util.js";
|
|
5
|
+
function useFacebookPageInvalid(chatRoom) {
|
|
6
|
+
const isFacebookChat = isFacebook(chatRoom);
|
|
7
|
+
const pageId = chatRoom?.source_id;
|
|
8
|
+
const { data: page } = useQuery({
|
|
9
|
+
queryKey: [QUERY_KEY.GET_SOCIAL_PAGE_DETAIL, pageId],
|
|
10
|
+
queryFn: async () => {
|
|
11
|
+
const resp = await getPageDetail(pageId);
|
|
12
|
+
return resp?.data ?? null;
|
|
13
|
+
},
|
|
14
|
+
enabled: isFacebookChat && !!pageId,
|
|
15
|
+
staleTime: 60 * 1e3
|
|
16
|
+
});
|
|
17
|
+
if (!isFacebookChat || !pageId || page?.is_valid == null) return false;
|
|
18
|
+
return page.is_valid != 1 && page.is_valid != true;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
useFacebookPageInvalid
|
|
22
|
+
};
|