@learningpool/ui 2.4.0 → 2.4.1
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.
|
@@ -49,11 +49,6 @@ interface FeedbackRatingProps {
|
|
|
49
49
|
* Example: org-12345
|
|
50
50
|
*/
|
|
51
51
|
customerId?: string;
|
|
52
|
-
/**
|
|
53
|
-
* If true, show the post-rating "more feedback" link by default. Disable to hide it.
|
|
54
|
-
* Default: true
|
|
55
|
-
*/
|
|
56
|
-
enableMoreFeedbackLink?: boolean;
|
|
57
52
|
/**
|
|
58
53
|
* Optional expiry for showing the component.
|
|
59
54
|
* When the current time is beyond this timestamp, the component will render null and not show.
|
|
@@ -80,5 +75,5 @@ interface FeedbackRatingProps {
|
|
|
80
75
|
* - Calls `submitRating` on star click (or a placeholder POST)
|
|
81
76
|
* - After rating, shows a link to provide more feedback (opens in new tab)
|
|
82
77
|
*/
|
|
83
|
-
export default function FeedbackRating({ featureId, productId, apiKey, token, submitRating, message, email, feedbackFormUrl, hubBaseUrl, customerId,
|
|
78
|
+
export default function FeedbackRating({ featureId, productId, apiKey, token, submitRating, message, email, feedbackFormUrl, hubBaseUrl, customerId, expiresAt, pageUrl, testIdPrefix, metadata }: FeedbackRatingProps): JSX.Element | null;
|
|
84
79
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
|
-
import
|
|
3
|
+
import CloseIcon from '@mui/icons-material/Close';
|
|
4
|
+
import { Alert, Box, Button, Collapse, Link, Rating, Stack, Typography, useTheme } from '@mui/material';
|
|
4
5
|
import { Constants } from '../../stream/AppSwitcher/constants';
|
|
5
6
|
import { defaultMessages } from '../../../lang/en-us';
|
|
6
7
|
const LOCAL_STORAGE_PREFIX = 'admin-feedback';
|
|
@@ -25,7 +26,7 @@ const defaultMessageNode = (_jsxs(_Fragment, { children: [_jsx("strong", { child
|
|
|
25
26
|
* - Calls `submitRating` on star click (or a placeholder POST)
|
|
26
27
|
* - After rating, shows a link to provide more feedback (opens in new tab)
|
|
27
28
|
*/
|
|
28
|
-
export default function FeedbackRating({ featureId, productId, apiKey, token, submitRating, message, email, feedbackFormUrl, hubBaseUrl, customerId,
|
|
29
|
+
export default function FeedbackRating({ featureId, productId, apiKey, token, submitRating, message, email, feedbackFormUrl, hubBaseUrl, customerId, expiresAt, pageUrl, testIdPrefix, metadata }) {
|
|
29
30
|
const theme = useTheme();
|
|
30
31
|
const localStorageKeys = useMemo(() => ({
|
|
31
32
|
rating: `${LOCAL_STORAGE_PREFIX}-rating-${featureId}`,
|
|
@@ -34,24 +35,24 @@ export default function FeedbackRating({ featureId, productId, apiKey, token, su
|
|
|
34
35
|
const [open, setOpen] = useState(true);
|
|
35
36
|
const [isDismissed, setIsDismissed] = useState(false);
|
|
36
37
|
const [rating, setRating] = useState(null);
|
|
37
|
-
const [showMoreFeedback, setShowMoreFeedback] = useState(false);
|
|
38
38
|
const hubFeedbackUrl = hubBaseUrl || Constants.BaseUrl;
|
|
39
39
|
const userMessage = message ?? defaultMessageNode;
|
|
40
40
|
const resolvedPageUrl = pageUrl ?? (typeof window !== 'undefined' ? window.location.href : '');
|
|
41
41
|
const testIdPrefixValue = testIdPrefix ?? 'feedback-rating';
|
|
42
|
-
const enableMoreFeedbackLinkValue = enableMoreFeedbackLink ?? true;
|
|
43
42
|
const buildDefaultFeedbackUrl = useCallback((value) => {
|
|
44
43
|
const baseFormUrl = feedbackFormUrl || DEFAULT_FEEDBACK_FORM_URL;
|
|
45
44
|
// Use Google Form entry IDs for prefill
|
|
46
45
|
const params = new URLSearchParams({
|
|
47
46
|
[GOOGLE_FORM_CONFIG.PARAMS.usp]: 'pp_url',
|
|
48
|
-
[GOOGLE_FORM_CONFIG.PARAMS.rating]: value.toString(),
|
|
49
47
|
[GOOGLE_FORM_CONFIG.PARAMS.email]: email || '',
|
|
50
48
|
[GOOGLE_FORM_CONFIG.PARAMS.featureId]: featureId,
|
|
51
49
|
[GOOGLE_FORM_CONFIG.PARAMS.orgAlias]: customerId || '',
|
|
52
50
|
[GOOGLE_FORM_CONFIG.PARAMS.productId]: productId,
|
|
53
51
|
[GOOGLE_FORM_CONFIG.PARAMS.pageUrl]: resolvedPageUrl
|
|
54
52
|
});
|
|
53
|
+
if (value != null && value >= 1 && value <= 5) {
|
|
54
|
+
params.append(GOOGLE_FORM_CONFIG.PARAMS.rating, value.toString());
|
|
55
|
+
}
|
|
55
56
|
return `${baseFormUrl}?${params.toString()}`;
|
|
56
57
|
}, [feedbackFormUrl, featureId, customerId, productId, resolvedPageUrl, email]);
|
|
57
58
|
const expiryTimestamp = useMemo(() => {
|
|
@@ -78,14 +79,13 @@ export default function FeedbackRating({ featureId, productId, apiKey, token, su
|
|
|
78
79
|
const parsed = Number(storedRating);
|
|
79
80
|
if (!Number.isNaN(parsed) && parsed >= 1 && parsed <= 5) {
|
|
80
81
|
setRating(parsed);
|
|
81
|
-
setShowMoreFeedback(enableMoreFeedbackLinkValue);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
catch {
|
|
86
86
|
// ignore localStorage errors
|
|
87
87
|
}
|
|
88
|
-
}, [localStorageKeys.dismissed, localStorageKeys.rating
|
|
88
|
+
}, [localStorageKeys.dismissed, localStorageKeys.rating]);
|
|
89
89
|
const saveRating = useCallback((value) => {
|
|
90
90
|
try {
|
|
91
91
|
const ls = typeof window !== 'undefined' ? window.localStorage : undefined;
|
|
@@ -152,10 +152,7 @@ export default function FeedbackRating({ featureId, productId, apiKey, token, su
|
|
|
152
152
|
setRating(value);
|
|
153
153
|
saveRating(value);
|
|
154
154
|
await (submitRating ? submitRating(value, featureId) : defaultSubmit(value));
|
|
155
|
-
|
|
156
|
-
setShowMoreFeedback(true);
|
|
157
|
-
}
|
|
158
|
-
}, [saveRating, submitRating, defaultSubmit, enableMoreFeedbackLinkValue, featureId]);
|
|
155
|
+
}, [saveRating, submitRating, defaultSubmit, featureId]);
|
|
159
156
|
const handleDismiss = useCallback(() => {
|
|
160
157
|
setOpen(false);
|
|
161
158
|
setTimeout(() => {
|
|
@@ -165,42 +162,40 @@ export default function FeedbackRating({ featureId, productId, apiKey, token, su
|
|
|
165
162
|
if (isDismissed || isExpired) {
|
|
166
163
|
return null;
|
|
167
164
|
}
|
|
168
|
-
const feedbackUrl =
|
|
169
|
-
return (_jsx(Box, { sx: { marginBottom: theme.spacing(2) }, children: _jsx(Collapse, { in: open, children: _jsx(Alert, { severity:
|
|
165
|
+
const feedbackUrl = buildDefaultFeedbackUrl(rating);
|
|
166
|
+
return (_jsx(Box, { sx: { marginBottom: theme.spacing(2) }, children: _jsx(Collapse, { in: open, children: _jsx(Alert, { severity: 'info', icon: false, sx: {
|
|
170
167
|
display: 'flex',
|
|
171
168
|
alignItems: 'center',
|
|
172
169
|
overflowX: 'hidden',
|
|
173
170
|
'& .MuiAlert-message': {
|
|
174
|
-
display: 'flex',
|
|
175
|
-
alignItems: 'center',
|
|
176
|
-
justifyContent: 'space-between',
|
|
177
171
|
width: '100%',
|
|
178
172
|
minWidth: 0,
|
|
179
|
-
overflow: 'hidden'
|
|
173
|
+
overflow: 'hidden',
|
|
174
|
+
display: 'block'
|
|
180
175
|
}
|
|
181
|
-
}, "data-testid": `${testIdPrefixValue}-alert-${featureId}`, action: _jsx(Button, { color:
|
|
176
|
+
}, "data-testid": `${testIdPrefixValue}-alert-${featureId}`, action: _jsx(Button, { color: 'inherit', size: 'small', onClick: handleDismiss, "data-testid": `${testIdPrefixValue}-dismiss-${featureId}`, sx: { alignSelf: 'center', minWidth: 0, padding: 0 }, "aria-label": defaultMessages.dismiss, children: _jsx(CloseIcon, { fontSize: 'small' }) }), children: _jsxs(Box, { sx: {
|
|
182
177
|
display: 'flex',
|
|
183
178
|
alignItems: 'center',
|
|
184
179
|
justifyContent: 'space-between',
|
|
185
180
|
width: '100%',
|
|
186
181
|
gap: 2,
|
|
187
182
|
minWidth: 0
|
|
188
|
-
}, children: [_jsx(Typography, { variant:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
183
|
+
}, children: [_jsxs(Stack, { children: [_jsx(Typography, { variant: 'subtitle2', sx: {
|
|
184
|
+
flex: 1,
|
|
185
|
+
minWidth: 0,
|
|
186
|
+
whiteSpace: 'normal',
|
|
187
|
+
overflowWrap: 'anywhere',
|
|
188
|
+
wordBreak: 'break-word'
|
|
189
|
+
}, children: userMessage }), _jsx(Link, { href: feedbackUrl, target: '_blank', rel: 'noopener noreferrer', underline: 'hover', variant: 'body2', "data-testid": `${testIdPrefixValue}-more-${featureId}`, children: defaultMessages['feedback-message-more-text'] })] }), _jsx(Rating, { name: `feedback-rating-${featureId}`, value: rating, onChange: (_event, newValue) => {
|
|
190
|
+
if (newValue) {
|
|
191
|
+
handleStarClick(newValue);
|
|
192
|
+
}
|
|
193
|
+
}, sx: {
|
|
194
|
+
display: 'flex',
|
|
195
|
+
alignSelf: 'center',
|
|
196
|
+
alignItems: 'center',
|
|
197
|
+
'& .MuiRating-iconFilled': { color: theme.palette.info.main },
|
|
198
|
+
'& .MuiRating-iconHover': { color: theme.palette.info.light },
|
|
199
|
+
cursor: 'pointer'
|
|
200
|
+
}, "data-testid": `${testIdPrefixValue}-stars-${featureId}` })] }) }) }) }));
|
|
206
201
|
}
|
package/lang/en-us.js
CHANGED
|
@@ -34,6 +34,6 @@ export const defaultMessages = {
|
|
|
34
34
|
// Feedback Rating
|
|
35
35
|
'feedback-message-prefix': "We've made some changes.",
|
|
36
36
|
'feedback-message-suffix': 'Share your feedback with a star rating.',
|
|
37
|
-
'feedback-message-more-text': '
|
|
37
|
+
'feedback-message-more-text': 'Give Further Feedback',
|
|
38
38
|
dismiss: 'Dismiss'
|
|
39
39
|
};
|