-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonboarding_systray.esm.js
More file actions
65 lines (59 loc) · 2.09 KB
/
Copy pathonboarding_systray.esm.js
File metadata and controls
65 lines (59 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/** @odoo-module **/
import {Component, onWillStart, useState} from "@odoo/owl";
import {registry} from "@web/core/registry";
import {useService} from "@web/core/utils/hooks";
/**
* Systray bell that surfaces unfinished farm-onboarding sessions.
*
* Hidden when the current user has no pending session (count == 0),
* so non-farm users see nothing. When pending, a pulsing dot draws
* the eye; click opens the wizard via the existing
* `action_open_for_current_user` server action.
*
* Deliberately lightweight — one `search_count` RPC on mount, no
* polling. The bell hides immediately on click (optimistic); if the
* user backs out of the wizard without finishing, the next page
* reload will surface it again.
*/
export class FarmOnboardingSystray extends Component {
static template = "farm_onboarding.SystrayBell";
static props = {};
setup() {
this.orm = useService("orm");
this.action = useService("action");
this.state = useState({pending: 0, loaded: false});
onWillStart(async () => {
// The systray is registered globally; users without
// farm_base.group_farm_user will hit AccessError on the
// search_count. Swallow it so we don't spam the console —
// a user who can't access the wizard shouldn't see the bell.
try {
this.state.pending = await this.orm.call(
"farm.onboarding.session",
"count_pending_for_current_user",
[]
);
} catch {
this.state.pending = 0;
} finally {
this.state.loaded = true;
}
});
}
async openWizard() {
const action = await this.orm.call(
"farm.onboarding.session",
"action_open_for_current_user",
[]
);
await this.action.doAction(action);
this.state.pending = 0;
}
}
registry
.category("systray")
.add(
"farm_onboarding.SystrayBell",
{Component: FarmOnboardingSystray},
{sequence: 100}
);