diff --git a/erpnext/public/js/hub/components/item_card.js b/erpnext/public/js/hub/components/item_card.js index e6471c6d89c..7cb228118c7 100644 --- a/erpnext/public/js/hub/components/item_card.js +++ b/erpnext/public/js/hub/components/item_card.js @@ -1,12 +1,4 @@ function get_item_card_html(item) { - if (item.recent_message) { - return get_buying_item_message_card_html(item); - } - - if (item.recent_messages) { - return get_selling_item_message_card_html(item); - } - const item_name = item.item_name || item.name; const title = strip_html(item_name); const img_url = item.image; @@ -120,20 +112,23 @@ function get_buying_item_message_card_html(item) { const content = strip_html(message.content) // route - if (!item.route) { - item.route = `marketplace/item/${item.hub_item_code}` - } - + item.route = `marketplace/buying/${item.hub_item_code}` const item_html = ` -
See All
`; + + html = get_item_card_container_html( + items, + __(category), + get_item_card_html, + see_all_link + ); + this.$wrapper.append(html); + }); + } + } +} diff --git a/erpnext/public/js/hub/pages/messages.js b/erpnext/public/js/hub/pages/messages.js index d02b3026238..f8faa99934c 100644 --- a/erpnext/public/js/hub/pages/messages.js +++ b/erpnext/public/js/hub/pages/messages.js @@ -1,21 +1,18 @@ import SubPage from './subpage'; import { get_item_card_container_html } from '../components/items_container'; +import { get_buying_item_message_card_html } from '../components/item_card'; +import { get_selling_item_message_card_html } from '../components/item_card'; import { get_empty_state } from '../components/empty_state'; -erpnext.hub.Messages = class Messages extends SubPage { - make_wrapper() { - super.make_wrapper(); - } - +erpnext.hub.Buying = class Buying extends SubPage { refresh() { - const messages_of = this.options[0]; - this.get_items_for_messages(messages_of).then((items) => { + this.get_items_for_messages().then((items) => { this.empty(); if (items.length) { items.map(item => { - item.route = `marketplace/${messages_of.toLowerCase()}/${item.hub_item_code}` + item.route = `marketplace/buying/${item.hub_item_code}` }) - this.render(items, __(messages_of)); + this.render(items, __('Buying')); } if (!items.length && !items.length) { @@ -25,7 +22,7 @@ erpnext.hub.Messages = class Messages extends SubPage { } render(items = [], title) { - const html = get_item_card_container_html(items, title); + const html = get_item_card_container_html(items, title, get_buying_item_message_card_html); this.$wrapper.append(html); } @@ -34,18 +31,40 @@ erpnext.hub.Messages = class Messages extends SubPage { this.$wrapper.html(empty_state); } - get_items_for_messages(messages_of) { - if (messages_of === 'Buying') { - return hub.call('get_buying_items_for_messages', {}, 'action:send_message'); - } else if (messages_of === 'Selling') { - return hub.call('get_selling_items_for_messages'); - } else { - frappe.throw('Invalid message type'); - } + get_items_for_messages() { + return hub.call('get_buying_items_for_messages', {}, 'action:send_message'); + } +} + +erpnext.hub.Selling = class Selling extends SubPage { + refresh() { + this.get_items_for_messages().then((items) => { + this.empty(); + if (items.length) { + items.map(item => { + item.route = `marketplace/selling/${item.hub_item_code}` + }) + this.render(items, __('Selling')); + } + + if (!items.length && !items.length) { + this.render_empty_state(); + } + }); } - get_interactions() { - return hub.call('get_sellers_with_interactions', { for_seller: hub.settings.company_email }); + render(items = [], title) { + const html = get_item_card_container_html(items, title, get_selling_item_message_card_html); + this.$wrapper.append(html); + } + + render_empty_state() { + const empty_state = get_empty_state(__('You haven\'t interacted with any seller yet.')); + this.$wrapper.html(empty_state); + } + + get_items_for_messages() { + return hub.call('get_selling_items_for_messages', {}); } } @@ -82,4 +101,4 @@ function get_message_html(message) {${message.content}