@redneckz/wildless-cms-uni-blocks 0.14.1022 → 0.14.1023
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/bundle/api/sendUserSurvey.d.ts +1 -0
- package/bundle/blocks.schema.json +1 -1
- package/bundle/bundle.umd.js +781 -746
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/components/ApplicationForm/handlers.d.ts +4 -3
- package/bundle/model/AspectsProps.d.ts +7 -1
- package/bundle/ui-kit/UserSurveyDialog/UserSurveyDialogContent.d.ts +4 -2
- package/bundle/ui-kit/UserSurveyDialog/useUserSurveyDialog.d.ts +1 -1
- package/dist/api/sendUserSurvey.d.ts +1 -0
- package/dist/api/sendUserSurvey.js.map +1 -1
- package/dist/components/ApplicationForm/ApplicationForm.js +3 -0
- package/dist/components/ApplicationForm/ApplicationForm.js.map +1 -1
- package/dist/components/ApplicationForm/handlers.d.ts +4 -3
- package/dist/components/ApplicationForm/handlers.js +9 -3
- package/dist/components/ApplicationForm/handlers.js.map +1 -1
- package/dist/model/AspectsProps.d.ts +7 -1
- package/dist/ui-kit/UserSurveyDialog/FirstStep.js +2 -2
- package/dist/ui-kit/UserSurveyDialog/FirstStep.js.map +1 -1
- package/dist/ui-kit/UserSurveyDialog/UserSurveyDialog.js +17 -2
- package/dist/ui-kit/UserSurveyDialog/UserSurveyDialog.js.map +1 -1
- package/dist/ui-kit/UserSurveyDialog/UserSurveyDialogContent.d.ts +4 -2
- package/dist/ui-kit/UserSurveyDialog/useUserSurveyDialog.d.ts +1 -1
- package/dist/ui-kit/UserSurveyDialog/useUserSurveyDialog.js +23 -11
- package/dist/ui-kit/UserSurveyDialog/useUserSurveyDialog.js.map +1 -1
- package/lib/api/sendUserSurvey.d.ts +1 -0
- package/lib/api/sendUserSurvey.js.map +1 -1
- package/lib/components/ApplicationForm/ApplicationForm.js +3 -0
- package/lib/components/ApplicationForm/ApplicationForm.js.map +1 -1
- package/lib/components/ApplicationForm/handlers.d.ts +4 -3
- package/lib/components/ApplicationForm/handlers.js +9 -3
- package/lib/components/ApplicationForm/handlers.js.map +1 -1
- package/lib/model/AspectsProps.d.ts +7 -1
- package/lib/ui-kit/UserSurveyDialog/FirstStep.js +2 -2
- package/lib/ui-kit/UserSurveyDialog/FirstStep.js.map +1 -1
- package/lib/ui-kit/UserSurveyDialog/UserSurveyDialog.js +17 -2
- package/lib/ui-kit/UserSurveyDialog/UserSurveyDialog.js.map +1 -1
- package/lib/ui-kit/UserSurveyDialog/UserSurveyDialogContent.d.ts +4 -2
- package/lib/ui-kit/UserSurveyDialog/useUserSurveyDialog.d.ts +1 -1
- package/lib/ui-kit/UserSurveyDialog/useUserSurveyDialog.js +24 -12
- package/lib/ui-kit/UserSurveyDialog/useUserSurveyDialog.js.map +1 -1
- package/mobile/bundle/api/sendUserSurvey.d.ts +1 -0
- package/mobile/bundle/bundle.umd.js +781 -746
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/components/ApplicationForm/handlers.d.ts +4 -3
- package/mobile/bundle/model/AspectsProps.d.ts +7 -1
- package/mobile/bundle/ui-kit/UserSurveyDialog/UserSurveyDialogContent.d.ts +4 -2
- package/mobile/bundle/ui-kit/UserSurveyDialog/useUserSurveyDialog.d.ts +1 -1
- package/mobile/dist/api/sendUserSurvey.d.ts +1 -0
- package/mobile/dist/api/sendUserSurvey.js.map +1 -1
- package/mobile/dist/components/ApplicationForm/ApplicationForm.js +3 -0
- package/mobile/dist/components/ApplicationForm/ApplicationForm.js.map +1 -1
- package/mobile/dist/components/ApplicationForm/handlers.d.ts +4 -3
- package/mobile/dist/components/ApplicationForm/handlers.js +9 -3
- package/mobile/dist/components/ApplicationForm/handlers.js.map +1 -1
- package/mobile/dist/model/AspectsProps.d.ts +7 -1
- package/mobile/dist/ui-kit/UserSurveyDialog/FirstStep.js +2 -2
- package/mobile/dist/ui-kit/UserSurveyDialog/FirstStep.js.map +1 -1
- package/mobile/dist/ui-kit/UserSurveyDialog/UserSurveyDialog.js +17 -2
- package/mobile/dist/ui-kit/UserSurveyDialog/UserSurveyDialog.js.map +1 -1
- package/mobile/dist/ui-kit/UserSurveyDialog/UserSurveyDialogContent.d.ts +4 -2
- package/mobile/dist/ui-kit/UserSurveyDialog/useUserSurveyDialog.d.ts +1 -1
- package/mobile/dist/ui-kit/UserSurveyDialog/useUserSurveyDialog.js +23 -11
- package/mobile/dist/ui-kit/UserSurveyDialog/useUserSurveyDialog.js.map +1 -1
- package/mobile/lib/api/sendUserSurvey.d.ts +1 -0
- package/mobile/lib/api/sendUserSurvey.js.map +1 -1
- package/mobile/lib/components/ApplicationForm/ApplicationForm.js +3 -0
- package/mobile/lib/components/ApplicationForm/ApplicationForm.js.map +1 -1
- package/mobile/lib/components/ApplicationForm/handlers.d.ts +4 -3
- package/mobile/lib/components/ApplicationForm/handlers.js +9 -3
- package/mobile/lib/components/ApplicationForm/handlers.js.map +1 -1
- package/mobile/lib/model/AspectsProps.d.ts +7 -1
- package/mobile/lib/ui-kit/UserSurveyDialog/FirstStep.js +2 -2
- package/mobile/lib/ui-kit/UserSurveyDialog/FirstStep.js.map +1 -1
- package/mobile/lib/ui-kit/UserSurveyDialog/UserSurveyDialog.js +17 -2
- package/mobile/lib/ui-kit/UserSurveyDialog/UserSurveyDialog.js.map +1 -1
- package/mobile/lib/ui-kit/UserSurveyDialog/UserSurveyDialogContent.d.ts +4 -2
- package/mobile/lib/ui-kit/UserSurveyDialog/useUserSurveyDialog.d.ts +1 -1
- package/mobile/lib/ui-kit/UserSurveyDialog/useUserSurveyDialog.js +24 -12
- package/mobile/lib/ui-kit/UserSurveyDialog/useUserSurveyDialog.js.map +1 -1
- package/mobile/src/api/sendUserSurvey.ts +1 -0
- package/mobile/src/components/ApplicationForm/ApplicationForm.tsx +3 -0
- package/mobile/src/components/ApplicationForm/handlers.ts +11 -0
- package/mobile/src/model/AspectsProps.ts +9 -1
- package/mobile/src/ui-kit/UserSurveyDialog/FirstStep.tsx +6 -2
- package/mobile/src/ui-kit/UserSurveyDialog/UserSurveyDialog.tsx +21 -2
- package/mobile/src/ui-kit/UserSurveyDialog/UserSurveyDialogContent.ts +5 -2
- package/mobile/src/ui-kit/UserSurveyDialog/useUserSurveyDialog.ts +30 -13
- package/package.json +1 -1
- package/src/api/sendUserSurvey.ts +1 -0
- package/src/components/ApplicationForm/ApplicationForm.tsx +3 -0
- package/src/components/ApplicationForm/handlers.ts +11 -0
- package/src/model/AspectsProps.ts +9 -1
- package/src/ui-kit/UserSurveyDialog/FirstStep.tsx +6 -2
- package/src/ui-kit/UserSurveyDialog/UserSurveyDialog.tsx +21 -2
- package/src/ui-kit/UserSurveyDialog/UserSurveyDialogContent.ts +5 -2
- package/src/ui-kit/UserSurveyDialog/useUserSurveyDialog.ts +30 -13
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type Reason,
|
|
13
13
|
type UserSurveyDialogContent,
|
|
14
14
|
type UserSurveyStoreSlice,
|
|
15
|
+
type UserSurveyType,
|
|
15
16
|
} from './UserSurveyDialogContent';
|
|
16
17
|
|
|
17
18
|
export type UserSurveyDialogProps = UserSurveyDialogContent;
|
|
@@ -20,13 +21,13 @@ const STEPS = [FirstStep, SecondStep, FinalStep];
|
|
|
20
21
|
const LAST_STEP_INDEX = 2;
|
|
21
22
|
|
|
22
23
|
export const UserSurveyDialog = UniBlock<UserSurveyDialogProps>(
|
|
23
|
-
({ onClose = noop, reasonsSource = {} }) => {
|
|
24
|
+
({ onClose = noop, isAfterTargetAction = false, reasonsSource = {} }) => {
|
|
24
25
|
const [isSending, { setTrue: startSending, setFalse: endSending }] = useBool(false);
|
|
25
26
|
const [currentRating, setCurrentRating] = useState<number>(0);
|
|
26
27
|
const [currentReason, setCurrentReason] = useState<Reason>();
|
|
27
28
|
const [step, setStep] = useState<number>(0);
|
|
28
29
|
const userSurveyStore = useLocalStore<UserSurveyStoreSlice>();
|
|
29
|
-
const surveyType = userSurveyStore.userSurvey?.lastShownType
|
|
30
|
+
const surveyType = getUserSurveyType(userSurveyStore.userSurvey?.lastShownType);
|
|
30
31
|
|
|
31
32
|
const { reasons } = reasonsSource as { reasons: Reason[] };
|
|
32
33
|
|
|
@@ -46,8 +47,13 @@ export const UserSurveyDialog = UniBlock<UserSurveyDialogProps>(
|
|
|
46
47
|
message: getMessage(currentReason, message),
|
|
47
48
|
url: globalThis.location.href,
|
|
48
49
|
type: surveyType,
|
|
50
|
+
ip: isAfterTargetAction ? 'after_target_action' : 'time_on_site',
|
|
49
51
|
});
|
|
50
52
|
endSending();
|
|
53
|
+
userSurveyStore.userSurvey = {
|
|
54
|
+
lastShownType: surveyType,
|
|
55
|
+
nextDueAt: getTimeAfter30days(),
|
|
56
|
+
};
|
|
51
57
|
setStep(LAST_STEP_INDEX);
|
|
52
58
|
},
|
|
53
59
|
[currentRating, currentReason],
|
|
@@ -78,3 +84,16 @@ const getMessage = (currentReason?: Reason, message?: string) => {
|
|
|
78
84
|
|
|
79
85
|
return message?.length ? message : 'Другое. Клиент не оставил комментариев';
|
|
80
86
|
};
|
|
87
|
+
|
|
88
|
+
// Отсчитываем месяц с текущей даты
|
|
89
|
+
const getTimeAfter30days = () => Date.now() + 30 * 24 * 60 * 60 * 1000;
|
|
90
|
+
|
|
91
|
+
// Если пользователь проходил опрос то показываем другой, иначе показываем случайный тип опроса
|
|
92
|
+
const getUserSurveyType = (lastShownType?: UserSurveyType) => {
|
|
93
|
+
console.log('Расчитал');
|
|
94
|
+
if (lastShownType) {
|
|
95
|
+
return lastShownType === 'NPS' ? 'CSI' : 'NPS';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return ['NPS', 'CSI'][Date.now() % 2] as UserSurveyType;
|
|
99
|
+
};
|
|
@@ -2,9 +2,11 @@ import { type JSONRefObject } from '../../data/JSONRefObject';
|
|
|
2
2
|
import { type OnCloseProps } from '../../model/OnCloseProps';
|
|
3
3
|
import { type UniBlockContent } from '../../UniBlock/UniBlockProps';
|
|
4
4
|
|
|
5
|
+
export type UserSurveyType = 'NPS' | 'CSI';
|
|
6
|
+
|
|
5
7
|
export type UserSurveyStoreSlice = {
|
|
6
8
|
userSurvey: {
|
|
7
|
-
lastShownType:
|
|
9
|
+
lastShownType: UserSurveyType;
|
|
8
10
|
nextDueAt: number;
|
|
9
11
|
};
|
|
10
12
|
};
|
|
@@ -18,7 +20,7 @@ export type StepProps = {
|
|
|
18
20
|
currentRating?: number;
|
|
19
21
|
currentReason?: Reason;
|
|
20
22
|
reasons?: Reason[];
|
|
21
|
-
surveyType:
|
|
23
|
+
surveyType: UserSurveyType;
|
|
22
24
|
isSending: boolean;
|
|
23
25
|
setCurrentReason: (value: Reason) => void;
|
|
24
26
|
setCurrentRating: (value: number) => void;
|
|
@@ -28,4 +30,5 @@ export type StepProps = {
|
|
|
28
30
|
|
|
29
31
|
export interface UserSurveyDialogContent extends OnCloseProps, UniBlockContent {
|
|
30
32
|
reasonsSource?: { reasons: Reason[] } | JSONRefObject;
|
|
33
|
+
isAfterTargetAction?: boolean;
|
|
31
34
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect } from '@redneckz/uni-jsx/lib/hooks';
|
|
1
|
+
import { useCallback, useEffect } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
2
|
import { useLocalStore } from '@redneckz/uni-jsx/lib/Store/useLocalStore';
|
|
3
3
|
import { useSessionStore } from '@redneckz/uni-jsx/lib/Store/useSessionStore';
|
|
4
4
|
import { noop } from '../../utils/noop';
|
|
@@ -10,47 +10,64 @@ const DELAY = 5 * 60 * 1000;
|
|
|
10
10
|
|
|
11
11
|
type SurveyTimerStore = {
|
|
12
12
|
surveyTimerStart: string;
|
|
13
|
+
surveyTimerId: NodeJS.Timeout;
|
|
14
|
+
isSurveySkipped: boolean;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
// Хук отвечает за показ пользователю опроса
|
|
16
|
-
export const useUserSurveyDialog = () => {
|
|
18
|
+
export const useUserSurveyDialog = (withoutTimer?: boolean) => {
|
|
17
19
|
const userSurveyDialog = useDialog(UserSurveyDialog);
|
|
18
20
|
const userSurveyStore = useLocalStore<UserSurveyStoreSlice>();
|
|
19
21
|
const sessionStore = useSessionStore<SurveyTimerStore>();
|
|
22
|
+
const surveyTimer = sessionStore.surveyTimerId;
|
|
23
|
+
const isSurveySkipped = sessionStore.isSurveySkipped;
|
|
20
24
|
const elapsedTime = sessionStore.surveyTimerStart
|
|
21
25
|
? Date.now() - Number.parseInt(sessionStore.surveyTimerStart)
|
|
22
26
|
: 0;
|
|
27
|
+
const isShowSurvey =
|
|
28
|
+
!isSurveySkipped &&
|
|
29
|
+
(!userSurveyStore.userSurvey || userSurveyStore.userSurvey?.nextDueAt <= Date.now());
|
|
23
30
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
const handleCloseSurvey = useCallback(() => {
|
|
32
|
+
sessionStore.isSurveySkipped = true;
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
35
|
+
const openUserSurveyDialog = useCallback((isAfterTargetAction?: boolean) => {
|
|
29
36
|
userSurveyDialog.open({
|
|
30
37
|
reasonsSource: {
|
|
31
38
|
$ref: '/wcms-resources/user-survey-reasons.json',
|
|
32
39
|
},
|
|
40
|
+
isAfterTargetAction,
|
|
41
|
+
onClose: handleCloseSurvey,
|
|
33
42
|
});
|
|
34
|
-
};
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
const handleOpenSurveyAction = useCallback(() => {
|
|
46
|
+
if (isShowSurvey) {
|
|
47
|
+
surveyTimer && clearTimeout(surveyTimer);
|
|
48
|
+
openUserSurveyDialog(true);
|
|
49
|
+
}
|
|
50
|
+
}, [surveyTimer, isShowSurvey]);
|
|
35
51
|
|
|
36
52
|
useEffect(() => {
|
|
37
53
|
// Опрос показывается только если ранее пользоваютелю не показывался опрос или с того момента прошел месяц
|
|
38
|
-
if (!
|
|
54
|
+
if (!withoutTimer && isShowSurvey) {
|
|
39
55
|
// начинаем отсчитывать время от первого захода на сайт
|
|
40
56
|
if (!sessionStore.surveyTimerStart) {
|
|
41
57
|
sessionStore.surveyTimerStart = Date.now().toString();
|
|
42
58
|
}
|
|
43
59
|
// Опрос показывается спустя 5 минут нахождения на сайте
|
|
44
60
|
const timeout = setTimeout(openUserSurveyDialog, DELAY - elapsedTime);
|
|
61
|
+
sessionStore.surveyTimerId = timeout;
|
|
45
62
|
|
|
46
63
|
return () => {
|
|
47
64
|
clearTimeout(timeout);
|
|
65
|
+
sessionStore.surveyTimerId = null;
|
|
48
66
|
};
|
|
49
67
|
}
|
|
50
68
|
|
|
51
69
|
return noop;
|
|
52
|
-
}, []);
|
|
53
|
-
};
|
|
70
|
+
}, [isShowSurvey]);
|
|
54
71
|
|
|
55
|
-
|
|
56
|
-
|
|
72
|
+
return handleOpenSurveyAction;
|
|
73
|
+
};
|