@servicetitan/onboarding-ui 7.1.0 → 7.3.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/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- export * from './company-profile';
2
1
  export * from './address-suggestion-popover';
2
+ export * from './company-profile';
3
+ export * from './components';
4
+ export * from './customer-types';
3
5
  export * from './hooks';
6
+ export * from './pusher';
4
7
  export * from './utils';
5
- export * from './customer-types';
6
- export * from './components';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- export * from './company-profile';
2
1
  export * from './address-suggestion-popover';
2
+ export * from './company-profile';
3
+ export * from './components';
4
+ export * from './customer-types';
3
5
  export * from './hooks';
6
+ export * from './pusher';
4
7
  export * from './utils';
5
- export * from './customer-types';
6
- export * from './components';
7
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './presence.store';
2
+ export * from './pusher.store';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pusher/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './presence.store';
2
+ export * from './pusher.store';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pusher/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { PusherStore } from './pusher.store';
2
+ interface MemberInfo {
3
+ EnteredDate: number;
4
+ Name: string;
5
+ IsFromAdmin: boolean;
6
+ }
7
+ interface Member {
8
+ id: string;
9
+ info: MemberInfo;
10
+ }
11
+ export declare class PresenceStore {
12
+ private pusherStore;
13
+ private instance?;
14
+ constructor(pusherStore: PusherStore);
15
+ initialize: (channelName: string) => Promise<void>;
16
+ dispose: () => void;
17
+ get first(): Member;
18
+ get amIFirst(): boolean;
19
+ private get channel();
20
+ get allMembers(): Member[];
21
+ get users(): Member[];
22
+ private get me();
23
+ get lastUser(): string;
24
+ }
25
+ export {};
26
+ //# sourceMappingURL=presence.store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presence.store.d.ts","sourceRoot":"","sources":["../../src/pusher/presence.store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,UAAU,UAAU;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;CACxB;AACD,UAAU,MAAM;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,CAAC;CACpB;AAED,qBACa,aAAa;IAGW,OAAO,CAAC,WAAW;IAFxC,OAAO,CAAC,QAAQ,CAAC,CAAkB;gBAEN,WAAW,EAAE,WAAW;IAKjE,UAAU,gBAAuB,MAAM,mBAOrC;IAGF,OAAO,aAGL;IAEF,IACI,KAAK,WAER;IAED,IACI,QAAQ,YAEX;IAGD,OAAO,KAAK,OAAO,GAKlB;IAED,IACI,UAAU,aAMb;IAED,IACI,KAAK,aAIR;IAGD,OAAO,KAAK,EAAE,GAEb;IAED,IACI,QAAQ,WAEX;CACJ"}
@@ -0,0 +1,151 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ import { inject, injectable } from '@servicetitan/react-ioc';
23
+ import { action, computed, makeObservable, observable } from 'mobx';
24
+ import { PresenceChannel } from 'pusher-js';
25
+ import { sortBy } from '../utils';
26
+ import { PusherStore } from './pusher.store';
27
+ let PresenceStore = class PresenceStore {
28
+ constructor(pusherStore) {
29
+ Object.defineProperty(this, "pusherStore", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: pusherStore
34
+ });
35
+ Object.defineProperty(this, "instance", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ Object.defineProperty(this, "initialize", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: (channelName) => __awaiter(this, void 0, void 0, function* () {
46
+ const presenceChannelName = this.pusherStore.combinePresenceChannelName(channelName);
47
+ this.instance = this.pusherStore.pusher.subscribe(presenceChannelName);
48
+ return new Promise((resolve, reject) => {
49
+ this.channel.bind('pusher:subscription_succeeded', resolve);
50
+ this.channel.bind('pusher:subscription_error', reject);
51
+ });
52
+ })
53
+ });
54
+ Object.defineProperty(this, "dispose", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: () => {
59
+ this.pusherStore.pusher.unsubscribe(this.channel.name);
60
+ this.instance = undefined;
61
+ }
62
+ });
63
+ makeObservable(this);
64
+ }
65
+ get first() {
66
+ return this.users[0];
67
+ }
68
+ get amIFirst() {
69
+ var _a, _b;
70
+ return ((_a = this.first) === null || _a === void 0 ? void 0 : _a.id) === ((_b = this.me) === null || _b === void 0 ? void 0 : _b.id);
71
+ }
72
+ get channel() {
73
+ if (!this.instance) {
74
+ throw new Error('Presence channel is not initialized');
75
+ }
76
+ return this.instance;
77
+ }
78
+ get allMembers() {
79
+ const result = [];
80
+ for (const id in this.channel.members.members) {
81
+ result.push(this.channel.members.get(id));
82
+ }
83
+ return result;
84
+ }
85
+ get users() {
86
+ return this.allMembers
87
+ .filter(({ info: { IsFromAdmin } }) => !IsFromAdmin)
88
+ .sort(sortBy(member => member.info.EnteredDate));
89
+ }
90
+ get me() {
91
+ return this.channel.members.me;
92
+ }
93
+ get lastUser() {
94
+ var _a, _b, _c;
95
+ return (_c = (_b = (_a = this.users[this.users.length - 1]) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.Name) !== null && _c !== void 0 ? _c : '-';
96
+ }
97
+ };
98
+ __decorate([
99
+ observable,
100
+ __metadata("design:type", PresenceChannel)
101
+ ], PresenceStore.prototype, "instance", void 0);
102
+ __decorate([
103
+ action,
104
+ __metadata("design:type", Object)
105
+ ], PresenceStore.prototype, "initialize", void 0);
106
+ __decorate([
107
+ action,
108
+ __metadata("design:type", Object)
109
+ ], PresenceStore.prototype, "dispose", void 0);
110
+ __decorate([
111
+ computed,
112
+ __metadata("design:type", Object),
113
+ __metadata("design:paramtypes", [])
114
+ ], PresenceStore.prototype, "first", null);
115
+ __decorate([
116
+ computed,
117
+ __metadata("design:type", Object),
118
+ __metadata("design:paramtypes", [])
119
+ ], PresenceStore.prototype, "amIFirst", null);
120
+ __decorate([
121
+ computed,
122
+ __metadata("design:type", Object),
123
+ __metadata("design:paramtypes", [])
124
+ ], PresenceStore.prototype, "channel", null);
125
+ __decorate([
126
+ computed,
127
+ __metadata("design:type", Object),
128
+ __metadata("design:paramtypes", [])
129
+ ], PresenceStore.prototype, "allMembers", null);
130
+ __decorate([
131
+ computed,
132
+ __metadata("design:type", Object),
133
+ __metadata("design:paramtypes", [])
134
+ ], PresenceStore.prototype, "users", null);
135
+ __decorate([
136
+ computed,
137
+ __metadata("design:type", Object),
138
+ __metadata("design:paramtypes", [])
139
+ ], PresenceStore.prototype, "me", null);
140
+ __decorate([
141
+ computed,
142
+ __metadata("design:type", Object),
143
+ __metadata("design:paramtypes", [])
144
+ ], PresenceStore.prototype, "lastUser", null);
145
+ PresenceStore = __decorate([
146
+ injectable(),
147
+ __param(0, inject(PusherStore)),
148
+ __metadata("design:paramtypes", [PusherStore])
149
+ ], PresenceStore);
150
+ export { PresenceStore };
151
+ //# sourceMappingURL=presence.store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presence.store.js","sourceRoot":"","sources":["../../src/pusher/presence.store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAa7C,IAAa,aAAa,GAA1B,MAAa,aAAa;IAGtB,YAAyC,WAAwB;;;;;mBAAxB;;QAF7B;;;;;WAAmC;QAO/C;;;;mBAAa,CAAO,WAAmB,EAAE,EAAE;gBACvC,MAAM,mBAAmB,GAAG,IAAI,CAAC,WAAW,CAAC,0BAA0B,CAAC,WAAW,CAAC,CAAC;gBACrF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,mBAAmB,CAAoB,CAAC;gBAC1F,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBACzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,+BAA+B,EAAE,OAAO,CAAC,CAAC;oBAC5D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MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IACzD,CAAC;IAGD,IAAY,EAAE;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAY,CAAC;IAC7C,CAAC;IAGD,IAAI,QAAQ;;QACR,OAAO,MAAA,MAAA,MAAA,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,IAAI,0CAAE,IAAI,mCAAI,GAAG,CAAC;IAChE,CAAC;CACJ,CAAA;AAjEe;IAAX,UAAU;8BAAoB,eAAe;+CAAC;AAO/C;IADC,MAAM;;iDAQL;AAGF;IADC,MAAM;;8CAIL;AAGF;IADC,QAAQ;;;0CAGR;AAGD;IADC,QAAQ;;;6CAGR;AAGD;IADC,QAAQ;;;4CAMR;AAGD;IADC,QAAQ;;;+CAOR;AAGD;IADC,QAAQ;;;0CAKR;AAGD;IADC,QAAQ;;;uCAGR;AAGD;IADC,QAAQ;;;6CAGR;AAjEQ,aAAa;IADzB,UAAU,EAAE;IAII,WAAA,MAAM,CAAC,WAAW,CAAC,CAAA;qCAAsB,WAAW;GAHxD,aAAa,CAkEzB;SAlEY,aAAa"}
@@ -0,0 +1,21 @@
1
+ import Pusher, { Channel } from 'pusher-js';
2
+ export interface PusherConfig {
3
+ authEndpoint: string;
4
+ tenantId: string;
5
+ pusherNamespace: string;
6
+ globalPusherChannelName?: string;
7
+ appKey?: string;
8
+ }
9
+ export declare class PusherStore {
10
+ private instance?;
11
+ private config?;
12
+ constructor();
13
+ initialize: (config: PusherConfig) => void;
14
+ findChannel: (channelName: string) => Channel | undefined;
15
+ combineChannelName: (channelName: string) => string;
16
+ combinePresenceChannelName: (channelName: string) => string;
17
+ dispose: () => void;
18
+ private combineChannelSuffix;
19
+ get pusher(): Pusher;
20
+ }
21
+ //# sourceMappingURL=pusher.store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pusher.store.d.ts","sourceRoot":"","sources":["../../src/pusher/pusher.store.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,WAAW,YAAY;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAGD,qBACa,WAAW;IACR,OAAO,CAAC,QAAQ,CAAC,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAC,CAAe;;IAO1C,UAAU,WAAY,YAAY,UAOhC;IAGF,WAAW,gBAAiB,MAAM,KAAG,OAAO,GAAG,SAAS,CAEtD;IAGF,kBAAkB,gBAAiB,MAAM,YACe;IAGxD,0BAA0B,gBAAiB,MAAM,YACQ;IAGzD,OAAO,aAGL;IAEF,OAAO,CAAC,oBAAoB,CACkD;IAE9E,IACI,MAAM,WAKT;CACJ"}
@@ -0,0 +1,125 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { injectable } from '@servicetitan/react-ioc';
11
+ import { action, computed, makeObservable, observable } from 'mobx';
12
+ import Pusher from 'pusher-js';
13
+ const APP_KEY = '59831c16dcf080351f5b';
14
+ let PusherStore = class PusherStore {
15
+ constructor() {
16
+ Object.defineProperty(this, "instance", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ Object.defineProperty(this, "config", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
28
+ Object.defineProperty(this, "initialize", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: (config) => {
33
+ var _a;
34
+ this.instance = new Pusher((_a = config.appKey) !== null && _a !== void 0 ? _a : APP_KEY, {
35
+ authEndpoint: config.authEndpoint,
36
+ cluster: 'mt1',
37
+ });
38
+ this.config = config;
39
+ this.pusher.subscribe(this.combineChannelName('global'));
40
+ }
41
+ });
42
+ Object.defineProperty(this, "findChannel", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: (channelName) => {
47
+ return this.pusher.channels.find(this.combineChannelName(channelName));
48
+ }
49
+ });
50
+ Object.defineProperty(this, "combineChannelName", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: (channelName) => `private-${this.combineChannelSuffix(channelName)}`
55
+ });
56
+ Object.defineProperty(this, "combinePresenceChannelName", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: (channelName) => `presence-${this.combineChannelSuffix(channelName)}`
61
+ });
62
+ Object.defineProperty(this, "dispose", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: () => {
67
+ var _a;
68
+ (_a = this.instance) === null || _a === void 0 ? void 0 : _a.disconnect();
69
+ this.instance = undefined;
70
+ }
71
+ });
72
+ Object.defineProperty(this, "combineChannelSuffix", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: (channelName) => { var _a, _b; return `${(_a = this.config) === null || _a === void 0 ? void 0 : _a.pusherNamespace}-${channelName}-${(_b = this.config) === null || _b === void 0 ? void 0 : _b.tenantId}`; }
77
+ });
78
+ makeObservable(this);
79
+ }
80
+ get pusher() {
81
+ if (!this.instance) {
82
+ throw new Error('Pusher instance is not initialized');
83
+ }
84
+ return this.instance;
85
+ }
86
+ };
87
+ __decorate([
88
+ observable,
89
+ __metadata("design:type", Pusher)
90
+ ], PusherStore.prototype, "instance", void 0);
91
+ __decorate([
92
+ observable,
93
+ __metadata("design:type", Object)
94
+ ], PusherStore.prototype, "config", void 0);
95
+ __decorate([
96
+ action,
97
+ __metadata("design:type", Object)
98
+ ], PusherStore.prototype, "initialize", void 0);
99
+ __decorate([
100
+ action,
101
+ __metadata("design:type", Object)
102
+ ], PusherStore.prototype, "findChannel", void 0);
103
+ __decorate([
104
+ action,
105
+ __metadata("design:type", Object)
106
+ ], PusherStore.prototype, "combineChannelName", void 0);
107
+ __decorate([
108
+ action,
109
+ __metadata("design:type", Object)
110
+ ], PusherStore.prototype, "combinePresenceChannelName", void 0);
111
+ __decorate([
112
+ action,
113
+ __metadata("design:type", Object)
114
+ ], PusherStore.prototype, "dispose", void 0);
115
+ __decorate([
116
+ computed,
117
+ __metadata("design:type", Object),
118
+ __metadata("design:paramtypes", [])
119
+ ], PusherStore.prototype, "pusher", null);
120
+ PusherStore = __decorate([
121
+ injectable(),
122
+ __metadata("design:paramtypes", [])
123
+ ], PusherStore);
124
+ export { PusherStore };
125
+ //# sourceMappingURL=pusher.store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pusher.store.js","sourceRoot":"","sources":["../../src/pusher/pusher.store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACpE,OAAO,MAAmB,MAAM,WAAW,CAAC;AAS5C,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAGvC,IAAa,WAAW,GAAxB,MAAa,WAAW;IAIpB;QAHY;;;;;WAA0B;QAC1B;;;;;WAA8B;QAO1C;;;;mBAAa,CAAC,MAAoB,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D;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;CACJ,CAAA;AA9Ce;IAAX,UAAU;8BAAoB,MAAM;6CAAC;AAC1B;IAAX,UAAU;;2CAA+B;AAO1C;IADC,MAAM;;+CAQL;AAGF;IADC,MAAM;;gDAGL;AAGF;IADC,MAAM;;uDAEiD;AAGxD;IADC,MAAM;;+DAEkD;AAGzD;IADC,MAAM;;4CAIL;AAMF;IADC,QAAQ;;;yCAMR;AA9CQ,WAAW;IADvB,UAAU,EAAE;;GACA,WAAW,CA+CvB;SA/CY,WAAW"}
@@ -1,3 +1,4 @@
1
- export * from './step-version-helper';
2
1
  export * from './country-helpers';
2
+ export * from './sort-by';
3
+ export * from './step-version-helper';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC"}
@@ -1,3 +1,4 @@
1
- export * from './step-version-helper';
2
1
  export * from './country-helpers';
2
+ export * from './sort-by';
3
+ export * from './step-version-helper';
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const sortBy: <T>(selector: (item: T) => string | number, order?: 'asc' | 'desc') => (a: T, b: T) => number;
2
+ //# sourceMappingURL=sort-by.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort-by.d.ts","sourceRoot":"","sources":["../../src/utils/sort-by.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,6BACY,MAAM,GAAG,MAAM,UAAS,KAAK,GAAG,MAAM,2BAWhE,CAAC"}
@@ -0,0 +1,13 @@
1
+ export const sortBy = (selector, order = 'asc') => (a, b) => {
2
+ const aValue = selector(a);
3
+ const bValue = selector(b);
4
+ let result = 0;
5
+ if (aValue < bValue) {
6
+ result = -1;
7
+ }
8
+ else if (aValue > bValue) {
9
+ result = 1;
10
+ }
11
+ return order === 'asc' ? result : -result;
12
+ };
13
+ //# sourceMappingURL=sort-by.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort-by.js","sourceRoot":"","sources":["../../src/utils/sort-by.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GACf,CAAI,QAAsC,EAAE,QAAwB,KAAK,EAAE,EAAE,CAC7E,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;IACX,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,MAAM,GAAG,MAAM,EAAE;QACjB,MAAM,GAAG,CAAC,CAAC,CAAC;KACf;SAAM,IAAI,MAAM,GAAG,MAAM,EAAE;QACxB,MAAM,GAAG,CAAC,CAAC;KACd;IACD,OAAO,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/onboarding-ui",
3
- "version": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "description": "Shared components between servicetitan monolith and Onboarding",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@servicetitan/confirm": "^24.0.0",
35
- "@servicetitan/culture": ">=22.0.0",
35
+ "@servicetitan/culture": "^25.8.0",
36
36
  "@servicetitan/data-query": ">=22.0.0",
37
37
  "@servicetitan/design-system": ">=13.2.1",
38
38
  "@servicetitan/form": "^24.3.0",
@@ -57,6 +57,7 @@
57
57
  "@types/google.maps": "^3.45.6",
58
58
  "classnames": "~2.3.1",
59
59
  "contentful-resolve-response": "^1.3.0",
60
+ "pusher-js": "^8.3.0",
60
61
  "query-string": "^7.0.1",
61
62
  "react-input-mask": "^2.0.4"
62
63
  },
@@ -71,5 +72,5 @@
71
72
  "less": true,
72
73
  "webpack": false
73
74
  },
74
- "gitHead": "66af05bc2547584bc9eb034dfcd692ef256ba379"
75
+ "gitHead": "d29437d247da3428ed25fd9fc4004c1f3a94cf1e"
75
76
  }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
- export * from './company-profile';
2
1
  export * from './address-suggestion-popover';
2
+ export * from './company-profile';
3
+ export * from './components';
4
+ export * from './customer-types';
3
5
  export * from './hooks';
6
+ export * from './pusher';
4
7
  export * from './utils';
5
- export * from './customer-types';
6
- export * from './components';
@@ -0,0 +1,2 @@
1
+ export * from './presence.store';
2
+ export * from './pusher.store';
@@ -0,0 +1,84 @@
1
+ import { inject, injectable } from '@servicetitan/react-ioc';
2
+ import { action, computed, makeObservable, observable } from 'mobx';
3
+ import { PresenceChannel } from 'pusher-js';
4
+ import { sortBy } from '../utils';
5
+ import { PusherStore } from './pusher.store';
6
+
7
+ interface MemberInfo {
8
+ EnteredDate: number;
9
+ Name: string;
10
+ IsFromAdmin: boolean;
11
+ }
12
+ interface Member {
13
+ id: string;
14
+ info: MemberInfo;
15
+ }
16
+
17
+ @injectable()
18
+ export class PresenceStore {
19
+ @observable private instance?: PresenceChannel;
20
+
21
+ constructor(@inject(PusherStore) private pusherStore: PusherStore) {
22
+ makeObservable(this);
23
+ }
24
+
25
+ @action
26
+ initialize = async (channelName: string) => {
27
+ const presenceChannelName = this.pusherStore.combinePresenceChannelName(channelName);
28
+ this.instance = this.pusherStore.pusher.subscribe(presenceChannelName) as PresenceChannel;
29
+ return new Promise<void>((resolve, reject) => {
30
+ this.channel.bind('pusher:subscription_succeeded', resolve);
31
+ this.channel.bind('pusher:subscription_error', reject);
32
+ });
33
+ };
34
+
35
+ @action
36
+ dispose = () => {
37
+ this.pusherStore.pusher.unsubscribe(this.channel.name);
38
+ this.instance = undefined;
39
+ };
40
+
41
+ @computed
42
+ get first() {
43
+ return this.users[0];
44
+ }
45
+
46
+ @computed
47
+ get amIFirst() {
48
+ return this.first?.id === this.me?.id;
49
+ }
50
+
51
+ @computed
52
+ private get channel() {
53
+ if (!this.instance) {
54
+ throw new Error('Presence channel is not initialized');
55
+ }
56
+ return this.instance;
57
+ }
58
+
59
+ @computed
60
+ get allMembers() {
61
+ const result: Member[] = [];
62
+ for (const id in this.channel.members.members) {
63
+ result.push(this.channel.members.get(id));
64
+ }
65
+ return result;
66
+ }
67
+
68
+ @computed
69
+ get users() {
70
+ return this.allMembers
71
+ .filter(({ info: { IsFromAdmin } }) => !IsFromAdmin)
72
+ .sort(sortBy(member => member.info.EnteredDate));
73
+ }
74
+
75
+ @computed
76
+ private get me() {
77
+ return this.channel.members.me as Member;
78
+ }
79
+
80
+ @computed
81
+ get lastUser() {
82
+ return this.users[this.users.length - 1]?.info?.Name ?? '-';
83
+ }
84
+ }
@@ -0,0 +1,62 @@
1
+ import { injectable } from '@servicetitan/react-ioc';
2
+ import { action, computed, makeObservable, observable } from 'mobx';
3
+ import Pusher, { Channel } from 'pusher-js';
4
+
5
+ export interface PusherConfig {
6
+ authEndpoint: string;
7
+ tenantId: string;
8
+ pusherNamespace: string;
9
+ globalPusherChannelName?: string;
10
+ appKey?: string;
11
+ }
12
+ const APP_KEY = '59831c16dcf080351f5b';
13
+
14
+ @injectable()
15
+ export class PusherStore {
16
+ @observable private instance?: Pusher;
17
+ @observable private config?: PusherConfig;
18
+
19
+ constructor() {
20
+ makeObservable(this);
21
+ }
22
+
23
+ @action
24
+ initialize = (config: PusherConfig) => {
25
+ this.instance = new Pusher(config.appKey ?? APP_KEY, {
26
+ authEndpoint: config.authEndpoint,
27
+ cluster: 'mt1',
28
+ });
29
+ this.config = config;
30
+ this.pusher.subscribe(this.combineChannelName('global'));
31
+ };
32
+
33
+ @action
34
+ findChannel = (channelName: string): Channel | undefined => {
35
+ return this.pusher.channels.find(this.combineChannelName(channelName));
36
+ };
37
+
38
+ @action
39
+ combineChannelName = (channelName: string) =>
40
+ `private-${this.combineChannelSuffix(channelName)}`;
41
+
42
+ @action
43
+ combinePresenceChannelName = (channelName: string) =>
44
+ `presence-${this.combineChannelSuffix(channelName)}`;
45
+
46
+ @action
47
+ dispose = () => {
48
+ this.instance?.disconnect();
49
+ this.instance = undefined;
50
+ };
51
+
52
+ private combineChannelSuffix = (channelName: string) =>
53
+ `${this.config?.pusherNamespace}-${channelName}-${this.config?.tenantId}`;
54
+
55
+ @computed
56
+ get pusher() {
57
+ if (!this.instance) {
58
+ throw new Error('Pusher instance is not initialized');
59
+ }
60
+ return this.instance;
61
+ }
62
+ }
@@ -1,2 +1,3 @@
1
- export * from './step-version-helper';
2
1
  export * from './country-helpers';
2
+ export * from './sort-by';
3
+ export * from './step-version-helper';
@@ -0,0 +1,13 @@
1
+ export const sortBy =
2
+ <T>(selector: (item: T) => string | number, order: 'asc' | 'desc' = 'asc') =>
3
+ (a: T, b: T) => {
4
+ const aValue = selector(a);
5
+ const bValue = selector(b);
6
+ let result = 0;
7
+ if (aValue < bValue) {
8
+ result = -1;
9
+ } else if (aValue > bValue) {
10
+ result = 1;
11
+ }
12
+ return order === 'asc' ? result : -result;
13
+ };