@solucx/react-native-solucx-widget 0.1.14 → 0.1.15
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/README.intern.md +513 -473
- package/README.md +285 -257
- package/package.json +23 -23
- package/src/SoluCXWidget.tsx +119 -119
- package/src/__tests__/urlUtils.test.ts +56 -56
- package/src/__tests__/useWidgetState.test.ts +188 -188
- package/src/components/CloseButton.tsx +36 -36
- package/src/components/InlineWidget.tsx +36 -32
- package/src/components/ModalWidget.tsx +59 -43
- package/src/components/OverlayWidget.tsx +88 -81
- package/src/constants/webViewConstants.ts +14 -14
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useHeightAnimation.ts +22 -0
- package/src/hooks/useWidgetHeight.ts +38 -0
- package/src/hooks/useWidgetState.ts +101 -77
- package/src/index.ts +8 -8
- package/src/interfaces/WidgetData.ts +19 -19
- package/src/interfaces/WidgetOptions.ts +7 -7
- package/src/interfaces/WidgetResponse.ts +15 -15
- package/src/interfaces/WidgetSamplerLog.ts +5 -5
- package/src/interfaces/index.ts +23 -23
- package/src/services/storage.ts +20 -20
- package/src/services/widgetEventService.ts +111 -111
- package/src/services/widgetValidationService.ts +86 -86
- package/src/styles/widgetStyles.ts +58 -83
- package/src/utils/urlUtils.ts +13 -13
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
import { EventKey, SurveyEventKey, WidgetResponse, WidgetOptions } from '../interfaces';
|
|
2
|
-
import { WidgetValidationService } from './widgetValidationService';
|
|
3
|
-
|
|
4
|
-
export class WidgetEventService {
|
|
5
|
-
private setIsWidgetVisible: (visible: boolean) => void;
|
|
6
|
-
private resize: (value: string) => void;
|
|
7
|
-
private open: () => void;
|
|
8
|
-
private validationService: WidgetValidationService;
|
|
9
|
-
private widgetOptions: WidgetOptions;
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
setIsWidgetVisible: (visible: boolean) => void,
|
|
13
|
-
resize: (value: string) => void,
|
|
14
|
-
open: () => void,
|
|
15
|
-
userId: string,
|
|
16
|
-
widgetOptions: WidgetOptions
|
|
17
|
-
) {
|
|
18
|
-
this.setIsWidgetVisible = setIsWidgetVisible;
|
|
19
|
-
this.resize = resize;
|
|
20
|
-
this.open = open;
|
|
21
|
-
this.validationService = new WidgetValidationService(userId);
|
|
22
|
-
this.widgetOptions = widgetOptions;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async handleMessage(message: string, isForm: boolean): Promise<WidgetResponse> {
|
|
26
|
-
const [eventKey, value = ""] = message.split("-");
|
|
27
|
-
const processedKey = isForm
|
|
28
|
-
? eventKey as EventKey
|
|
29
|
-
: this.adaptSurveyKeyToWidgetKey(eventKey as SurveyEventKey);
|
|
30
|
-
|
|
31
|
-
return await this.executeEvent(processedKey, value);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private async executeEvent(eventKey: EventKey, value: string): Promise<WidgetResponse> {
|
|
35
|
-
const eventHandlers = {
|
|
36
|
-
FORM_OPENED: () => this.handleFormOpened(),
|
|
37
|
-
FORM_CLOSE: () => this.handleFormClose(),
|
|
38
|
-
FORM_ERROR: (value: string) => this.handleFormError(value),
|
|
39
|
-
FORM_PAGECHANGED: (value: string) => this.handlePageChanged(value),
|
|
40
|
-
QUESTION_ANSWERED: () => this.handleQuestionAnswered(),
|
|
41
|
-
FORM_COMPLETED: () => this.handleFormCompleted(),
|
|
42
|
-
FORM_PARTIALCOMPLETED: () => this.handlePartialCompleted(),
|
|
43
|
-
FORM_RESIZE: (value: string) => this.handleResize(value),
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const handler = eventHandlers[eventKey];
|
|
47
|
-
return await (handler?.(value) || { status: "error", message: "Unknown event" });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private async handleFormOpened(): Promise<WidgetResponse> {
|
|
51
|
-
const canDisplay = await this.validationService.shouldDisplayWidget(this.widgetOptions);
|
|
52
|
-
|
|
53
|
-
if (!canDisplay) {
|
|
54
|
-
return { status: "error", message: "Widget not allowed" };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
this.open();
|
|
58
|
-
this.setIsWidgetVisible(true);
|
|
59
|
-
return { status: "success" };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private handleFormClose(): WidgetResponse {
|
|
63
|
-
this.setIsWidgetVisible(false);
|
|
64
|
-
return { status: "success" };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private handleFormError(value: string): WidgetResponse {
|
|
68
|
-
this.setIsWidgetVisible(false);
|
|
69
|
-
return { status: "error", message: value };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private handlePageChanged(value: string): WidgetResponse {
|
|
73
|
-
console.log("Page changed:", value);
|
|
74
|
-
return { status: "success" };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private handleQuestionAnswered(): WidgetResponse {
|
|
78
|
-
console.log("Question answered");
|
|
79
|
-
return { status: "success" };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private handleFormCompleted(): WidgetResponse {
|
|
83
|
-
// TODO: Implement completion logic
|
|
84
|
-
return { status: "success" };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private handlePartialCompleted(): WidgetResponse {
|
|
88
|
-
// TODO: Implement partial completion logic
|
|
89
|
-
return { status: "success" };
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private handleResize(value: string): WidgetResponse {
|
|
93
|
-
this.setIsWidgetVisible(true);
|
|
94
|
-
this.resize(value);
|
|
95
|
-
return { status: "success" };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private adaptSurveyKeyToWidgetKey(key: SurveyEventKey): EventKey {
|
|
99
|
-
const keyMapping = {
|
|
100
|
-
closeSoluCXWidget: "FORM_CLOSE",
|
|
101
|
-
dismissSoluCXWidget: "FORM_CLOSE",
|
|
102
|
-
completeSoluCXWidget: "FORM_COMPLETED",
|
|
103
|
-
partialSoluCXWidget: "FORM_PARTIALCOMPLETED",
|
|
104
|
-
resizeSoluCXWidget: "FORM_RESIZE",
|
|
105
|
-
openSoluCXWidget: "FORM_OPENED",
|
|
106
|
-
errorSoluCXWidget: "FORM_ERROR",
|
|
107
|
-
} as const;
|
|
108
|
-
|
|
109
|
-
return keyMapping[key] as EventKey;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
1
|
+
import { EventKey, SurveyEventKey, WidgetResponse, WidgetOptions } from '../interfaces';
|
|
2
|
+
import { WidgetValidationService } from './widgetValidationService';
|
|
3
|
+
|
|
4
|
+
export class WidgetEventService {
|
|
5
|
+
private setIsWidgetVisible: (visible: boolean) => void;
|
|
6
|
+
private resize: (value: string) => void;
|
|
7
|
+
private open: () => void;
|
|
8
|
+
private validationService: WidgetValidationService;
|
|
9
|
+
private widgetOptions: WidgetOptions;
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
setIsWidgetVisible: (visible: boolean) => void,
|
|
13
|
+
resize: (value: string) => void,
|
|
14
|
+
open: () => void,
|
|
15
|
+
userId: string,
|
|
16
|
+
widgetOptions: WidgetOptions
|
|
17
|
+
) {
|
|
18
|
+
this.setIsWidgetVisible = setIsWidgetVisible;
|
|
19
|
+
this.resize = resize;
|
|
20
|
+
this.open = open;
|
|
21
|
+
this.validationService = new WidgetValidationService(userId);
|
|
22
|
+
this.widgetOptions = widgetOptions;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async handleMessage(message: string, isForm: boolean): Promise<WidgetResponse> {
|
|
26
|
+
const [eventKey, value = ""] = message.split("-");
|
|
27
|
+
const processedKey = isForm
|
|
28
|
+
? eventKey as EventKey
|
|
29
|
+
: this.adaptSurveyKeyToWidgetKey(eventKey as SurveyEventKey);
|
|
30
|
+
|
|
31
|
+
return await this.executeEvent(processedKey, value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private async executeEvent(eventKey: EventKey, value: string): Promise<WidgetResponse> {
|
|
35
|
+
const eventHandlers = {
|
|
36
|
+
FORM_OPENED: () => this.handleFormOpened(),
|
|
37
|
+
FORM_CLOSE: () => this.handleFormClose(),
|
|
38
|
+
FORM_ERROR: (value: string) => this.handleFormError(value),
|
|
39
|
+
FORM_PAGECHANGED: (value: string) => this.handlePageChanged(value),
|
|
40
|
+
QUESTION_ANSWERED: () => this.handleQuestionAnswered(),
|
|
41
|
+
FORM_COMPLETED: () => this.handleFormCompleted(),
|
|
42
|
+
FORM_PARTIALCOMPLETED: () => this.handlePartialCompleted(),
|
|
43
|
+
FORM_RESIZE: (value: string) => this.handleResize(value),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const handler = eventHandlers[eventKey];
|
|
47
|
+
return await (handler?.(value) || { status: "error", message: "Unknown event" });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private async handleFormOpened(): Promise<WidgetResponse> {
|
|
51
|
+
const canDisplay = await this.validationService.shouldDisplayWidget(this.widgetOptions);
|
|
52
|
+
|
|
53
|
+
if (!canDisplay) {
|
|
54
|
+
return { status: "error", message: "Widget not allowed" };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.open();
|
|
58
|
+
this.setIsWidgetVisible(true);
|
|
59
|
+
return { status: "success" };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private handleFormClose(): WidgetResponse {
|
|
63
|
+
this.setIsWidgetVisible(false);
|
|
64
|
+
return { status: "success" };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private handleFormError(value: string): WidgetResponse {
|
|
68
|
+
this.setIsWidgetVisible(false);
|
|
69
|
+
return { status: "error", message: value };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private handlePageChanged(value: string): WidgetResponse {
|
|
73
|
+
console.log("Page changed:", value);
|
|
74
|
+
return { status: "success" };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private handleQuestionAnswered(): WidgetResponse {
|
|
78
|
+
console.log("Question answered");
|
|
79
|
+
return { status: "success" };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private handleFormCompleted(): WidgetResponse {
|
|
83
|
+
// TODO: Implement completion logic
|
|
84
|
+
return { status: "success" };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private handlePartialCompleted(): WidgetResponse {
|
|
88
|
+
// TODO: Implement partial completion logic
|
|
89
|
+
return { status: "success" };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private handleResize(value: string): WidgetResponse {
|
|
93
|
+
this.setIsWidgetVisible(true);
|
|
94
|
+
this.resize(value);
|
|
95
|
+
return { status: "success" };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private adaptSurveyKeyToWidgetKey(key: SurveyEventKey): EventKey {
|
|
99
|
+
const keyMapping = {
|
|
100
|
+
closeSoluCXWidget: "FORM_CLOSE",
|
|
101
|
+
dismissSoluCXWidget: "FORM_CLOSE",
|
|
102
|
+
completeSoluCXWidget: "FORM_COMPLETED",
|
|
103
|
+
partialSoluCXWidget: "FORM_PARTIALCOMPLETED",
|
|
104
|
+
resizeSoluCXWidget: "FORM_RESIZE",
|
|
105
|
+
openSoluCXWidget: "FORM_OPENED",
|
|
106
|
+
errorSoluCXWidget: "FORM_ERROR",
|
|
107
|
+
} as const;
|
|
108
|
+
|
|
109
|
+
return keyMapping[key] as EventKey;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import { WidgetOptions, WidgetSamplerLog } from '../interfaces';
|
|
2
|
-
import { StorageService } from './storage';
|
|
3
|
-
|
|
4
|
-
export class WidgetValidationService {
|
|
5
|
-
private storageService: StorageService;
|
|
6
|
-
|
|
7
|
-
constructor(userId: string) {
|
|
8
|
-
this.storageService = new StorageService(userId);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async shouldDisplayWidget(widgetOptions: WidgetOptions): Promise<boolean> {
|
|
12
|
-
const { retry, waitDelayAfterRating = 60 } = widgetOptions;
|
|
13
|
-
const { attempts = 5, interval = 1 } = retry || {};
|
|
14
|
-
const userLog = await this.getLog();
|
|
15
|
-
const now = Date.now();
|
|
16
|
-
const dayInMilliseconds = 86400000;
|
|
17
|
-
|
|
18
|
-
if (this.isWithinCollectInterval(userLog, waitDelayAfterRating, now, dayInMilliseconds)) return false;
|
|
19
|
-
if (this.isWithinCollectPartialInterval(userLog, waitDelayAfterRating, now, dayInMilliseconds)) return false;
|
|
20
|
-
if (this.isWithinRetryInterval(userLog, interval, attempts, now, dayInMilliseconds)) return false;
|
|
21
|
-
|
|
22
|
-
await this.resetAttemptsIfNeeded(userLog, attempts);
|
|
23
|
-
await this.setLog(userLog);
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private async getLog(): Promise<WidgetSamplerLog> {
|
|
28
|
-
try {
|
|
29
|
-
return await this.storageService.read();
|
|
30
|
-
} catch (error) {
|
|
31
|
-
console.error('Error reading widget log:', error);
|
|
32
|
-
return {
|
|
33
|
-
attempts: 0,
|
|
34
|
-
lastAttempt: 0,
|
|
35
|
-
lastRating: 0,
|
|
36
|
-
lastParcial: 0
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private async setLog(userLog: WidgetSamplerLog): Promise<void> {
|
|
42
|
-
try {
|
|
43
|
-
await this.storageService.write(userLog);
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.error('Error writing widget log:', error);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private isWithinCollectInterval(
|
|
50
|
-
userLog: WidgetSamplerLog,
|
|
51
|
-
waitDelayAfterRating: number,
|
|
52
|
-
now: number,
|
|
53
|
-
dayInMilliseconds: number
|
|
54
|
-
): boolean {
|
|
55
|
-
const timeSinceLastRating = now - userLog.lastRating;
|
|
56
|
-
return userLog.lastRating > 0 && timeSinceLastRating < waitDelayAfterRating * dayInMilliseconds;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private isWithinCollectPartialInterval(
|
|
60
|
-
userLog: WidgetSamplerLog,
|
|
61
|
-
waitDelayAfterRating: number,
|
|
62
|
-
now: number,
|
|
63
|
-
dayInMilliseconds: number
|
|
64
|
-
): boolean {
|
|
65
|
-
const timeSinceLastPartial = now - userLog.lastParcial;
|
|
66
|
-
return userLog.lastParcial > 0 && timeSinceLastPartial < waitDelayAfterRating * dayInMilliseconds;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private isWithinRetryInterval(
|
|
70
|
-
userLog: WidgetSamplerLog,
|
|
71
|
-
interval: number,
|
|
72
|
-
attempts: number,
|
|
73
|
-
now: number,
|
|
74
|
-
dayInMilliseconds: number
|
|
75
|
-
): boolean {
|
|
76
|
-
if (userLog.attempts < attempts) return false;
|
|
77
|
-
const timeSinceLastAttempt = now - userLog.lastAttempt;
|
|
78
|
-
return timeSinceLastAttempt < interval * dayInMilliseconds;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private async resetAttemptsIfNeeded(userLog: WidgetSamplerLog, maxAttempts: number): Promise<void> {
|
|
82
|
-
if (userLog.attempts >= maxAttempts) {
|
|
83
|
-
userLog.attempts = 0;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
1
|
+
import { WidgetOptions, WidgetSamplerLog } from '../interfaces';
|
|
2
|
+
import { StorageService } from './storage';
|
|
3
|
+
|
|
4
|
+
export class WidgetValidationService {
|
|
5
|
+
private storageService: StorageService;
|
|
6
|
+
|
|
7
|
+
constructor(userId: string) {
|
|
8
|
+
this.storageService = new StorageService(userId);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async shouldDisplayWidget(widgetOptions: WidgetOptions): Promise<boolean> {
|
|
12
|
+
const { retry, waitDelayAfterRating = 60 } = widgetOptions;
|
|
13
|
+
const { attempts = 5, interval = 1 } = retry || {};
|
|
14
|
+
const userLog = await this.getLog();
|
|
15
|
+
const now = Date.now();
|
|
16
|
+
const dayInMilliseconds = 86400000;
|
|
17
|
+
|
|
18
|
+
if (this.isWithinCollectInterval(userLog, waitDelayAfterRating, now, dayInMilliseconds)) return false;
|
|
19
|
+
if (this.isWithinCollectPartialInterval(userLog, waitDelayAfterRating, now, dayInMilliseconds)) return false;
|
|
20
|
+
if (this.isWithinRetryInterval(userLog, interval, attempts, now, dayInMilliseconds)) return false;
|
|
21
|
+
|
|
22
|
+
await this.resetAttemptsIfNeeded(userLog, attempts);
|
|
23
|
+
await this.setLog(userLog);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private async getLog(): Promise<WidgetSamplerLog> {
|
|
28
|
+
try {
|
|
29
|
+
return await this.storageService.read();
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error('Error reading widget log:', error);
|
|
32
|
+
return {
|
|
33
|
+
attempts: 0,
|
|
34
|
+
lastAttempt: 0,
|
|
35
|
+
lastRating: 0,
|
|
36
|
+
lastParcial: 0
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private async setLog(userLog: WidgetSamplerLog): Promise<void> {
|
|
42
|
+
try {
|
|
43
|
+
await this.storageService.write(userLog);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error('Error writing widget log:', error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private isWithinCollectInterval(
|
|
50
|
+
userLog: WidgetSamplerLog,
|
|
51
|
+
waitDelayAfterRating: number,
|
|
52
|
+
now: number,
|
|
53
|
+
dayInMilliseconds: number
|
|
54
|
+
): boolean {
|
|
55
|
+
const timeSinceLastRating = now - userLog.lastRating;
|
|
56
|
+
return userLog.lastRating > 0 && timeSinceLastRating < waitDelayAfterRating * dayInMilliseconds;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private isWithinCollectPartialInterval(
|
|
60
|
+
userLog: WidgetSamplerLog,
|
|
61
|
+
waitDelayAfterRating: number,
|
|
62
|
+
now: number,
|
|
63
|
+
dayInMilliseconds: number
|
|
64
|
+
): boolean {
|
|
65
|
+
const timeSinceLastPartial = now - userLog.lastParcial;
|
|
66
|
+
return userLog.lastParcial > 0 && timeSinceLastPartial < waitDelayAfterRating * dayInMilliseconds;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private isWithinRetryInterval(
|
|
70
|
+
userLog: WidgetSamplerLog,
|
|
71
|
+
interval: number,
|
|
72
|
+
attempts: number,
|
|
73
|
+
now: number,
|
|
74
|
+
dayInMilliseconds: number
|
|
75
|
+
): boolean {
|
|
76
|
+
if (userLog.attempts < attempts) return false;
|
|
77
|
+
const timeSinceLastAttempt = now - userLog.lastAttempt;
|
|
78
|
+
return timeSinceLastAttempt < interval * dayInMilliseconds;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private async resetAttemptsIfNeeded(userLog: WidgetSamplerLog, maxAttempts: number): Promise<void> {
|
|
82
|
+
if (userLog.attempts >= maxAttempts) {
|
|
83
|
+
userLog.attempts = 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -1,83 +1,58 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native';
|
|
2
|
-
import { WidgetType } from '../interfaces';
|
|
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
|
-
flex: 1,
|
|
32
|
-
justifyContent: 'center',
|
|
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
|
-
alignItems: 'center',
|
|
60
|
-
},
|
|
61
|
-
modalContent: {
|
|
62
|
-
backgroundColor: 'white',
|
|
63
|
-
borderRadius: 10,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
export const getWidgetVisibility = (visibility: boolean) => {
|
|
68
|
-
return {
|
|
69
|
-
opacity: visibility ? 1 : 0,
|
|
70
|
-
pointerEvents: visibility ? 'auto' as const : 'none' as const,
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export const getWidgetStyles = (type: WidgetType) => {
|
|
75
|
-
const styleMap = {
|
|
76
|
-
'bottom': { container: styles.wrapper, content: styles.bottom },
|
|
77
|
-
'top': { container: styles.wrapper, content: styles.top },
|
|
78
|
-
'inline': { container: styles.inlineWrapper, content: styles.inline },
|
|
79
|
-
'modal': { container: styles.wrapper, content: styles.inline }
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
return styleMap[type] || styleMap.bottom;
|
|
83
|
-
};
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { WidgetType } from '../interfaces';
|
|
3
|
+
|
|
4
|
+
export const styles = StyleSheet.create({
|
|
5
|
+
wrapper: {
|
|
6
|
+
flex: 1,
|
|
7
|
+
justifyContent: 'center',
|
|
8
|
+
alignItems: 'center',
|
|
9
|
+
},
|
|
10
|
+
inlineWrapper: {
|
|
11
|
+
justifyContent: 'center',
|
|
12
|
+
alignItems: 'center',
|
|
13
|
+
},
|
|
14
|
+
bottom: {
|
|
15
|
+
position: 'absolute',
|
|
16
|
+
bottom: 0,
|
|
17
|
+
justifyContent: 'center',
|
|
18
|
+
alignItems: 'center',
|
|
19
|
+
},
|
|
20
|
+
top: {
|
|
21
|
+
position: 'absolute',
|
|
22
|
+
top: 0,
|
|
23
|
+
justifyContent: 'center',
|
|
24
|
+
alignItems: 'center',
|
|
25
|
+
},
|
|
26
|
+
inline: {
|
|
27
|
+
justifyContent: 'center',
|
|
28
|
+
alignItems: 'center',
|
|
29
|
+
},
|
|
30
|
+
modalOverlay: {
|
|
31
|
+
flex: 1,
|
|
32
|
+
justifyContent: 'center',
|
|
33
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
},
|
|
36
|
+
modalContent: {
|
|
37
|
+
backgroundColor: 'white',
|
|
38
|
+
borderRadius: 10,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const getWidgetVisibility = (visibility: boolean) => {
|
|
43
|
+
return {
|
|
44
|
+
opacity: visibility ? 1 : 0,
|
|
45
|
+
pointerEvents: visibility ? 'auto' as const : 'none' as const,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const getWidgetStyles = (type: WidgetType) => {
|
|
50
|
+
const styleMap = {
|
|
51
|
+
'bottom': { container: styles.wrapper, content: styles.bottom },
|
|
52
|
+
'top': { container: styles.wrapper, content: styles.top },
|
|
53
|
+
'inline': { container: styles.inlineWrapper, content: styles.inline },
|
|
54
|
+
'modal': { container: styles.wrapper, content: styles.inline }
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return styleMap[type] || styleMap.bottom;
|
|
58
|
+
};
|
package/src/utils/urlUtils.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { BASE_URL } from '../constants/webViewConstants';
|
|
2
|
-
import { WidgetData, SoluCXKey } from '../interfaces';
|
|
3
|
-
|
|
4
|
-
export function buildWidgetURL(key: SoluCXKey, data: WidgetData): string {
|
|
5
|
-
const params = new URLSearchParams(data as Record<string, string>);
|
|
6
|
-
const baseURL = `${BASE_URL}/${key}/?mode=widget`;
|
|
7
|
-
|
|
8
|
-
if (data.transaction_id) {
|
|
9
|
-
return `${baseURL}&${params.toString()}`;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return `${baseURL}&transaction_id=&${params.toString()}`;
|
|
13
|
-
}
|
|
1
|
+
import { BASE_URL } from '../constants/webViewConstants';
|
|
2
|
+
import { WidgetData, SoluCXKey } from '../interfaces';
|
|
3
|
+
|
|
4
|
+
export function buildWidgetURL(key: SoluCXKey, data: WidgetData): string {
|
|
5
|
+
const params = new URLSearchParams(data as Record<string, string>);
|
|
6
|
+
const baseURL = `${BASE_URL}/${key}/?mode=widget`;
|
|
7
|
+
|
|
8
|
+
if (data.transaction_id) {
|
|
9
|
+
return `${baseURL}&${params.toString()}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return `${baseURL}&transaction_id=&${params.toString()}`;
|
|
13
|
+
}
|