/** @odoo-module **/ // Fusion Helpdesk — top systray icon with an unread-reply badge. // Sequence 99 places it just left of the attendance check-in button. import { Component, useState, onWillStart, onWillUnmount } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { rpc } from "@web/core/network/rpc"; import { useService } from "@web/core/utils/hooks"; import { FusionHelpdeskDialog } from "./fusion_helpdesk_dialog"; const POLL_MS = 120000; // refresh the unread badge every 2 minutes class FusionHelpdeskSystray extends Component { static template = "fusion_helpdesk.SystrayItem"; static props = {}; setup() { this.dialog = useService("dialog"); this.state = useState({ unread: 0 }); onWillStart(async () => { await this._refreshUnread(); }); // Poll so a reply that lands while the user is working still // surfaces without a page reload. Errors are swallowed server-side // (the endpoint always returns a count) so the badge never breaks. this._timer = setInterval(() => this._refreshUnread(), POLL_MS); onWillUnmount(() => clearInterval(this._timer)); } async _refreshUnread() { try { const res = await rpc("/fusion_helpdesk/unread_count", {}); this.state.unread = (res && res.count) || 0; } catch { // Network/config hiccup — leave the badge as-is, don't throw. } } onClick() { // If there are unread replies, drop straight into the inbox; // otherwise open the New report form (the primary action). const initialTab = this.state.unread > 0 ? "list" : "new"; this.dialog.add( FusionHelpdeskDialog, { initialTab }, { onClose: () => this._refreshUnread() } ); } } export const fusionHelpdeskSystrayItem = { Component: FusionHelpdeskSystray, }; registry .category("systray") .add("fusion_helpdesk.report_button", fusionHelpdeskSystrayItem, { sequence: 99, });