|
1 |
| -export default class ProactiveReportingConfigs { |
2 |
| - public readonly gapBetweenModals: number; // Time in seconds |
3 |
| - public readonly modalDelayAfterDetection: number; // Time in seconds |
4 |
| - public readonly enabled: boolean; |
| 1 | +import { Logger } from '../utils/logger'; |
| 2 | +import InstabugConstants from '../utils/InstabugConstants'; |
5 | 3 |
|
6 |
| - // Private constructor to ensure it can only be created through the builder |
7 |
| - private constructor( |
8 |
| - gapBetweenModals: number, |
9 |
| - modalDelayAfterDetection: number, |
10 |
| - enabled: boolean, |
11 |
| - ) { |
12 |
| - this.gapBetweenModals = gapBetweenModals; |
13 |
| - this.modalDelayAfterDetection = modalDelayAfterDetection; |
14 |
| - this.enabled = enabled; |
15 |
| - } |
16 |
| - |
17 |
| - // Static method to get the builder instance |
18 |
| - static Builder = class { |
19 |
| - public gapBetweenModals: number = 30; // Default: 30 seconds |
20 |
| - public modalDelayAfterDetection: number = 15; // Default: 15 seconds |
21 |
| - public enabled: boolean = true; // Default: enabled |
22 |
| - |
23 |
| - // Logger method to handle logging |
24 |
| - public logWarning(message: string): void { |
25 |
| - console.warn(`Warning: ${message}`); |
26 |
| - } |
27 |
| - /** |
28 |
| - * controls the time gap between showing 2 proactive reporting dialogs in seconds |
29 |
| - */ |
30 |
| - setGapBetweenModals(gap: number): this { |
31 |
| - if (gap <= 0) { |
32 |
| - this.logWarning( |
33 |
| - 'gapBetweenModals must be a positive number. Using default value of 30 seconds.', |
34 |
| - ); |
35 |
| - return this; |
36 |
| - } |
37 |
| - this.gapBetweenModals = gap; |
38 |
| - return this; |
39 |
| - } |
| 4 | +export interface ProactiveReportingConfigOptions { |
| 5 | + gapBetweenModals: number; |
| 6 | + modalDelayAfterDetection: number; |
| 7 | + enabled: boolean; |
| 8 | +} |
40 | 9 |
|
41 |
| - /** |
42 |
| - * controls the time gap between detecting a frustrating experience |
43 |
| - */ |
44 |
| - setModalDelayAfterDetection(delay: number): this { |
45 |
| - if (delay <= 0) { |
46 |
| - this.logWarning( |
47 |
| - 'modalDelayAfterDetection must be a positive number. Using default value of 15 seconds.', |
48 |
| - ); |
49 |
| - return this; |
50 |
| - } |
51 |
| - this.modalDelayAfterDetection = delay; |
52 |
| - return this; |
53 |
| - } |
| 10 | +export function createProactiveReportingConfig( |
| 11 | + { |
| 12 | + gapBetweenModals = 24, |
| 13 | + modalDelayAfterDetection = 20, |
| 14 | + enabled = true, |
| 15 | + }: ProactiveReportingConfigOptions = { |
| 16 | + gapBetweenModals: 24, |
| 17 | + modalDelayAfterDetection: 20, |
| 18 | + enabled: true, |
| 19 | + }, |
| 20 | +) { |
| 21 | + // Validation and defaults |
| 22 | + if (gapBetweenModals <= 0) { |
| 23 | + Logger.warn(InstabugConstants.GAP_MODEL_ERROR_MESSAGE); |
| 24 | + gapBetweenModals = 24; // Use default value if invalid |
| 25 | + } |
54 | 26 |
|
55 |
| - /** |
56 |
| - * controls the state of the feature |
57 |
| - */ |
58 |
| - isEnabled(enabled: boolean): this { |
59 |
| - this.enabled = enabled; |
60 |
| - return this; |
61 |
| - } |
| 27 | + if (modalDelayAfterDetection <= 0) { |
| 28 | + Logger.warn(InstabugConstants.MODAL_DETECTION_ERROR_MESSAGE); |
| 29 | + modalDelayAfterDetection = 20; // Use default value if invalid |
| 30 | + } |
62 | 31 |
|
63 |
| - build(): ProactiveReportingConfigs { |
64 |
| - return new ProactiveReportingConfigs( |
65 |
| - this.gapBetweenModals, |
66 |
| - this.modalDelayAfterDetection, |
67 |
| - this.enabled, |
68 |
| - ); |
69 |
| - } |
| 32 | + return { |
| 33 | + gapBetweenModals, |
| 34 | + modalDelayAfterDetection, |
| 35 | + enabled, |
70 | 36 | };
|
71 | 37 | }
|
0 commit comments