@shiva004/surveys 0.1.2 → 0.1.5
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.cjs +109 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +403 -0
- package/dist/index.js +8716 -0
- package/dist/index.js.map +1 -0
- package/dist/style.css +1 -0
- package/package.json +33 -27
- package/src/Pages/Allsurvey/Allsurvey.tsx +0 -157
- package/src/Pages/Allsurvey/SurveyGridCard.tsx +0 -124
- package/src/Pages/Allsurvey/index.ts +0 -1
- package/src/Pages/Allsurvey/surveysTable.config.ts +0 -15
- package/src/Pages/Createsurvey/Createsurvey.tsx +0 -318
- package/src/Pages/Createsurvey/index.ts +0 -1
- package/src/Pages/NPStracker/NPStracker.tsx +0 -78
- package/src/Pages/NPStracker/index.ts +0 -1
- package/src/Pages/Responses/Responses.tsx +0 -61
- package/src/Pages/Responses/index.ts +0 -1
- package/src/Pages/Responses/responsesTable.config.ts +0 -74
- package/src/Pages/Surveyanalytics/Surveyanalytics.tsx +0 -154
- package/src/Pages/Surveyanalytics/analyticsTable.config.ts +0 -123
- package/src/Pages/Surveyanalytics/index.ts +0 -1
- package/src/Pages/Surveydetails/Surveydetails.tsx +0 -202
- package/src/Pages/Surveydetails/index.ts +0 -1
- package/src/Pages/Surveytemplates/Surveytemplates.tsx +0 -299
- package/src/Pages/Surveytemplates/index.ts +0 -1
- package/src/Pages/surveyPage.module.scss +0 -49
- package/src/cells/SurveyCells.tsx +0 -370
- package/src/hooks/useSurveyResponses.ts +0 -37
- package/src/hooks/useTableConfig.ts +0 -77
- package/src/hooks/useTableData.ts +0 -184
- package/src/index.ts +0 -24
- package/src/nav.ts +0 -55
- package/src/routes.ts +0 -98
- package/src/services/api/TableConfigDto.ts +0 -36
- package/src/services/api/TableQueryParams.ts +0 -10
- package/src/services/api/surveys.api.ts +0 -144
- package/src/services/api/types.ts +0 -113
- package/src/types/survey.types.ts +0 -175
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
// src/features/surveys/pages/CreateSurvey.tsx
|
|
2
|
-
import { Header } from '@/shared/components/layout/Header';
|
|
3
|
-
import { Icon } from '@/shared/components/ui/Icon/Icon';
|
|
4
|
-
import React, { useCallback, useState } from 'react';
|
|
5
|
-
import { useNavigate } from 'react-router-dom';
|
|
6
|
-
import { Card } from '@/modules/queue/components/ui';
|
|
7
|
-
import { surveysApi } from '../../services/api/surveys.api';
|
|
8
|
-
|
|
9
|
-
type QType = 'nps' | 'rating' | 'multiple_choice' | 'open_text';
|
|
10
|
-
|
|
11
|
-
interface QDraft {
|
|
12
|
-
id: string;
|
|
13
|
-
type: QType;
|
|
14
|
-
text: string;
|
|
15
|
-
required: boolean;
|
|
16
|
-
options: string[];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const TC: Record<string, string> = {
|
|
20
|
-
nps: 'bg-[color:color-mix(in_srgb,var(--th-success)_10%,transparent)] text-[color:var(--th-success)]',
|
|
21
|
-
rating: 'bg-[#7c3aed]/10 text-[color:var(--th-accent-soft)]',
|
|
22
|
-
multiple_choice: 'bg-[color:color-mix(in_srgb,var(--th-warning-soft)_10%,transparent)] text-[color:var(--th-warning-soft)]',
|
|
23
|
-
open_text: 'bg-[color:color-mix(in_srgb,var(--th-info-soft)_10%,transparent)] text-[color:var(--th-info-soft)]',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/** Renders the create survey component. */
|
|
27
|
-
export const CreateSurvey: React.FC = () => {
|
|
28
|
-
const navigate = useNavigate();
|
|
29
|
-
const [name, setName] = useState('');
|
|
30
|
-
const [description, setDescription] = useState('');
|
|
31
|
-
const [target, setTarget] = useState(500);
|
|
32
|
-
const [questions, setQuestions] = useState<QDraft[]>([
|
|
33
|
-
{
|
|
34
|
-
id: 'q1',
|
|
35
|
-
type: 'nps',
|
|
36
|
-
text: 'How likely are you to recommend Zelisy?',
|
|
37
|
-
required: true,
|
|
38
|
-
options: [],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
id: 'q2',
|
|
42
|
-
type: 'rating',
|
|
43
|
-
text: 'How satisfied are you with the product?',
|
|
44
|
-
required: true,
|
|
45
|
-
options: [],
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
id: 'q3',
|
|
49
|
-
type: 'multiple_choice',
|
|
50
|
-
text: 'Which feature do you use most?',
|
|
51
|
-
required: false,
|
|
52
|
-
options: ['Feature Flags', 'Experiments', 'Segments', 'Audit Log'],
|
|
53
|
-
},
|
|
54
|
-
]);
|
|
55
|
-
const [submitting, setSubmitting] = useState(false);
|
|
56
|
-
const [created, setCreated] = useState(false);
|
|
57
|
-
const [errors, setErrors] = useState<Record<string, string>>({});
|
|
58
|
-
|
|
59
|
-
const addQ = (type: QType) =>
|
|
60
|
-
setQuestions((p) => [
|
|
61
|
-
...p,
|
|
62
|
-
{
|
|
63
|
-
id: `q${Date.now()}`,
|
|
64
|
-
type,
|
|
65
|
-
text: '',
|
|
66
|
-
required: false,
|
|
67
|
-
options: type === 'multiple_choice' ? ['Option 1', 'Option 2'] : [],
|
|
68
|
-
},
|
|
69
|
-
]);
|
|
70
|
-
|
|
71
|
-
const updateQ = (id: string, u: Partial<QDraft>) =>
|
|
72
|
-
setQuestions((p) => p.map((q) => (q.id === id ? { ...q, ...u } : q)));
|
|
73
|
-
|
|
74
|
-
const handleSubmit = useCallback(async () => {
|
|
75
|
-
const errs: Record<string, string> = {};
|
|
76
|
-
if (!name.trim()) errs.name = 'Required';
|
|
77
|
-
if (questions.length === 0) errs.questions = 'Add at least one question';
|
|
78
|
-
questions.forEach((q, i) => {
|
|
79
|
-
if (!q.text.trim()) errs[`q${i}`] = `Q${i + 1} text required`;
|
|
80
|
-
});
|
|
81
|
-
setErrors(errs);
|
|
82
|
-
if (Object.keys(errs).length) return;
|
|
83
|
-
|
|
84
|
-
setSubmitting(true);
|
|
85
|
-
try {
|
|
86
|
-
await surveysApi.create({
|
|
87
|
-
name: name.trim(),
|
|
88
|
-
description: description.trim() || undefined,
|
|
89
|
-
targetResponses: target,
|
|
90
|
-
questions: questions.map((q) => ({
|
|
91
|
-
type: q.type,
|
|
92
|
-
question: q.text.trim(),
|
|
93
|
-
required: q.required,
|
|
94
|
-
options: q.options.length ? q.options : undefined,
|
|
95
|
-
})),
|
|
96
|
-
});
|
|
97
|
-
setCreated(true);
|
|
98
|
-
} catch (e: any) {
|
|
99
|
-
if (e?.errors) setErrors(e.errors);
|
|
100
|
-
} finally {
|
|
101
|
-
setSubmitting(false);
|
|
102
|
-
}
|
|
103
|
-
}, [name, description, target, questions]);
|
|
104
|
-
|
|
105
|
-
if (created)
|
|
106
|
-
return (
|
|
107
|
-
<div className="p-6 lg:p-8 max-w-[900px] mx-auto">
|
|
108
|
-
<Card className="p-12 text-center">
|
|
109
|
-
<div className="w-16 h-16 rounded-2xl bg-[color:color-mix(in_srgb,var(--th-success)_15%,transparent)] flex items-center justify-center mx-auto mb-6 glow-success">
|
|
110
|
-
<Icon icon="Check" size={32} className="text-[color:var(--th-success)]" />
|
|
111
|
-
</div>
|
|
112
|
-
<h2 className="text-[24px] font-bold text-white mb-2">
|
|
113
|
-
Survey Created!
|
|
114
|
-
</h2>
|
|
115
|
-
<p className="text-[14px] text-[color:var(--th-text-3)] mb-6">
|
|
116
|
-
Your survey is now live and collecting responses.
|
|
117
|
-
</p>
|
|
118
|
-
<button
|
|
119
|
-
onClick={() => navigate('/app/surveys')}
|
|
120
|
-
className="px-5 py-2.5 rounded-lg bg-[#7c3aed] hover:bg-[#8b4df0] text-white text-[13px] font-medium transition-colors"
|
|
121
|
-
>
|
|
122
|
-
View All Surveys
|
|
123
|
-
</button>
|
|
124
|
-
</Card>
|
|
125
|
-
</div>
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
return (
|
|
129
|
-
<div className="p-6 lg:p-8 max-w-[900px]">
|
|
130
|
-
<button
|
|
131
|
-
onClick={() => navigate(-1)}
|
|
132
|
-
className="flex items-center gap-1.5 text-[13px] text-[color:var(--th-text-3)] hover:text-[color:var(--th-text-2)] transition-colors mb-6"
|
|
133
|
-
>
|
|
134
|
-
<Icon icon="ArrowLeft" size={15} /> Back
|
|
135
|
-
</button>
|
|
136
|
-
<Header title="Create Survey" subtitle="analytics · build a new survey" />
|
|
137
|
-
|
|
138
|
-
<div className="space-y-6">
|
|
139
|
-
<Card className="p-6 space-y-4">
|
|
140
|
-
<div>
|
|
141
|
-
<label className="block text-[12px] text-[color:var(--th-text-3)] mb-1.5">
|
|
142
|
-
Survey Name
|
|
143
|
-
</label>
|
|
144
|
-
<input
|
|
145
|
-
value={name}
|
|
146
|
-
onChange={(e) => setName(e.target.value)}
|
|
147
|
-
placeholder="e.g. Q1 Product Satisfaction"
|
|
148
|
-
className={`w-full px-3.5 py-2.5 rounded-lg bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] border text-[13px] text-[color:var(--th-text-1)] placeholder:text-[color:color-mix(in_srgb,var(--th-text-3)_60%,transparent)] focus:border-[#7c3aed] outline-none transition-colors ${errors.name ? 'border-[color:var(--th-danger-soft)]' : 'border-[color:color-mix(in_srgb,var(--th-ov-base)_8%,transparent)]'
|
|
149
|
-
}`}
|
|
150
|
-
/>
|
|
151
|
-
{errors.name && (
|
|
152
|
-
<p className="text-[11px] text-[color:var(--th-danger-soft)] mt-1">{errors.name}</p>
|
|
153
|
-
)}
|
|
154
|
-
</div>
|
|
155
|
-
<div>
|
|
156
|
-
<label className="block text-[12px] text-[color:var(--th-text-3)] mb-1.5">
|
|
157
|
-
Description
|
|
158
|
-
</label>
|
|
159
|
-
<textarea
|
|
160
|
-
value={description}
|
|
161
|
-
onChange={(e) => setDescription(e.target.value)}
|
|
162
|
-
placeholder="What is this survey about?"
|
|
163
|
-
rows={2}
|
|
164
|
-
className="w-full px-3.5 py-2.5 rounded-lg bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] border border-[color:color-mix(in_srgb,var(--th-ov-base)_8%,transparent)] text-[13px] text-[color:var(--th-text-1)] placeholder:text-[color:color-mix(in_srgb,var(--th-text-3)_60%,transparent)] focus:border-[#7c3aed] outline-none transition-colors resize-none"
|
|
165
|
-
/>
|
|
166
|
-
</div>
|
|
167
|
-
<div>
|
|
168
|
-
<label className="block text-[12px] text-[color:var(--th-text-3)] mb-1.5">
|
|
169
|
-
Target Responses
|
|
170
|
-
</label>
|
|
171
|
-
<input
|
|
172
|
-
type="number"
|
|
173
|
-
value={target}
|
|
174
|
-
onChange={(e) => setTarget(parseInt(e.target.value, 10) || 0)}
|
|
175
|
-
className="w-32 px-3.5 py-2.5 rounded-lg bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] border border-[color:color-mix(in_srgb,var(--th-ov-base)_8%,transparent)] text-[13px] text-[color:var(--th-text-1)] font-mono focus:border-[#7c3aed] outline-none transition-colors"
|
|
176
|
-
/>
|
|
177
|
-
</div>
|
|
178
|
-
</Card>
|
|
179
|
-
|
|
180
|
-
<Card className="p-6">
|
|
181
|
-
<h2 className="text-[15px] font-semibold text-white mb-4">
|
|
182
|
-
Questions ({questions.length})
|
|
183
|
-
</h2>
|
|
184
|
-
<div className="space-y-3">
|
|
185
|
-
{questions.map((q, i) => (
|
|
186
|
-
<div
|
|
187
|
-
key={q.id}
|
|
188
|
-
className="p-4 rounded-lg bg-[color:color-mix(in_srgb,var(--th-ov-base)_2%,transparent)] border border-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] group"
|
|
189
|
-
>
|
|
190
|
-
<div className="flex items-center gap-3 mb-3">
|
|
191
|
-
<Icon
|
|
192
|
-
icon="GripVertical"
|
|
193
|
-
size={14}
|
|
194
|
-
className="text-[color:color-mix(in_srgb,var(--th-text-3)_30%,transparent)] cursor-grab"
|
|
195
|
-
/>
|
|
196
|
-
<span className="text-[12px] font-semibold text-[color:var(--th-text-3)]">
|
|
197
|
-
Q{i + 1}
|
|
198
|
-
</span>
|
|
199
|
-
<span
|
|
200
|
-
className={`text-[10px] px-2 py-0.5 rounded font-medium ${TC[q.type]
|
|
201
|
-
}`}
|
|
202
|
-
>
|
|
203
|
-
{q.type.replace('_', ' ')}
|
|
204
|
-
</span>
|
|
205
|
-
{q.required && (
|
|
206
|
-
<span className="text-[10px] text-[color:var(--th-warning-soft)]">required</span>
|
|
207
|
-
)}
|
|
208
|
-
<div className="flex-1" />
|
|
209
|
-
<button
|
|
210
|
-
onClick={() =>
|
|
211
|
-
updateQ(q.id, { required: !q.required })
|
|
212
|
-
}
|
|
213
|
-
className={`text-[10px] px-2 py-0.5 rounded transition-colors ${q.required
|
|
214
|
-
? 'bg-[color:color-mix(in_srgb,var(--th-warning-soft)_10%,transparent)] text-[color:var(--th-warning-soft)]'
|
|
215
|
-
: 'bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] text-[color:var(--th-text-3)]'
|
|
216
|
-
}`}
|
|
217
|
-
>
|
|
218
|
-
{q.required ? 'Required' : 'Optional'}
|
|
219
|
-
</button>
|
|
220
|
-
<button
|
|
221
|
-
onClick={() =>
|
|
222
|
-
setQuestions((p) => p.filter((x) => x.id !== q.id))
|
|
223
|
-
}
|
|
224
|
-
className="text-[color:var(--th-text-3)] hover:text-[color:var(--th-danger-soft)] transition-colors"
|
|
225
|
-
>
|
|
226
|
-
<Icon icon="Trash2" size={13} />
|
|
227
|
-
</button>
|
|
228
|
-
</div>
|
|
229
|
-
<input
|
|
230
|
-
value={q.text}
|
|
231
|
-
onChange={(e) =>
|
|
232
|
-
updateQ(q.id, { text: e.target.value })
|
|
233
|
-
}
|
|
234
|
-
placeholder="Enter your question..."
|
|
235
|
-
className={`w-full px-3 py-2 rounded-lg bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] border text-[13px] text-[color:var(--th-text-1)] placeholder:text-[color:color-mix(in_srgb,var(--th-text-3)_60%,transparent)] focus:border-[#7c3aed] outline-none transition-colors ${errors[`q${i}`] ? 'border-[color:var(--th-danger-soft)]' : 'border-[color:color-mix(in_srgb,var(--th-ov-base)_8%,transparent)]'
|
|
236
|
-
}`}
|
|
237
|
-
/>
|
|
238
|
-
{q.options.length > 0 && (
|
|
239
|
-
<div className="mt-2 space-y-1.5">
|
|
240
|
-
{q.options.map((opt, oi) => (
|
|
241
|
-
<div key={oi} className="flex items-center gap-2">
|
|
242
|
-
<span className="text-[10px] text-[color:var(--th-text-3)]">•</span>
|
|
243
|
-
<input
|
|
244
|
-
value={opt}
|
|
245
|
-
onChange={(e) => {
|
|
246
|
-
const opts = [...q.options];
|
|
247
|
-
opts[oi] = e.target.value;
|
|
248
|
-
updateQ(q.id, { options: opts });
|
|
249
|
-
}}
|
|
250
|
-
className="flex-1 px-2 py-1 rounded bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] border border-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] text-[12px] text-[color:var(--th-text-2)] focus:border-[#7c3aed] outline-none"
|
|
251
|
-
/>
|
|
252
|
-
</div>
|
|
253
|
-
))}
|
|
254
|
-
<button
|
|
255
|
-
onClick={() =>
|
|
256
|
-
updateQ(q.id, {
|
|
257
|
-
options: [
|
|
258
|
-
...q.options,
|
|
259
|
-
`Option ${q.options.length + 1}`,
|
|
260
|
-
],
|
|
261
|
-
})
|
|
262
|
-
}
|
|
263
|
-
className="text-[10px] text-[#7c3aed] hover:text-[#8b4df0] mt-1"
|
|
264
|
-
>
|
|
265
|
-
+ Add option
|
|
266
|
-
</button>
|
|
267
|
-
</div>
|
|
268
|
-
)}
|
|
269
|
-
</div>
|
|
270
|
-
))}
|
|
271
|
-
</div>
|
|
272
|
-
<div className="mt-4 flex items-center gap-2">
|
|
273
|
-
{(
|
|
274
|
-
[
|
|
275
|
-
'nps',
|
|
276
|
-
'rating',
|
|
277
|
-
'multiple_choice',
|
|
278
|
-
'open_text',
|
|
279
|
-
] as QType[]
|
|
280
|
-
).map((t) => (
|
|
281
|
-
<button
|
|
282
|
-
key={t}
|
|
283
|
-
onClick={() => addQ(t)}
|
|
284
|
-
className="px-3 py-1.5 rounded-lg bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] hover:bg-[color:color-mix(in_srgb,var(--th-ov-base)_8%,transparent)] text-[11px] text-[color:var(--th-text-3)] transition-colors"
|
|
285
|
-
>
|
|
286
|
-
+{' '}
|
|
287
|
-
{t
|
|
288
|
-
.replace('_', ' ')
|
|
289
|
-
.replace(/\b\w/g, (c) => c.toUpperCase())}
|
|
290
|
-
</button>
|
|
291
|
-
))}
|
|
292
|
-
</div>
|
|
293
|
-
</Card>
|
|
294
|
-
|
|
295
|
-
<div className="flex items-center justify-end gap-3">
|
|
296
|
-
<button
|
|
297
|
-
onClick={() => navigate(-1)}
|
|
298
|
-
className="px-5 py-2.5 rounded-lg bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] hover:bg-[color:color-mix(in_srgb,var(--th-ov-base)_8%,transparent)] text-[color:var(--th-text-3)] text-[13px] font-medium transition-colors"
|
|
299
|
-
>
|
|
300
|
-
Cancel
|
|
301
|
-
</button>
|
|
302
|
-
<button
|
|
303
|
-
onClick={handleSubmit}
|
|
304
|
-
disabled={submitting || !name.trim()}
|
|
305
|
-
className="px-6 py-2.5 rounded-lg bg-[#7c3aed] hover:bg-[#8b4df0] disabled:opacity-40 text-white text-[13px] font-medium transition-colors flex items-center gap-2"
|
|
306
|
-
>
|
|
307
|
-
{submitting && (
|
|
308
|
-
<Icon icon="Loader2" size={13} className="animate-spin" />
|
|
309
|
-
)}
|
|
310
|
-
Create Survey
|
|
311
|
-
</button>
|
|
312
|
-
</div>
|
|
313
|
-
</div>
|
|
314
|
-
</div>
|
|
315
|
-
);
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
CreateSurvey.displayName = 'CreateSurvey';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {CreateSurvey} from './Createsurvey'
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// src/modules/survey/Pages/NPStracker/NPStracker.tsx
|
|
2
|
-
import StatCard from '@/modules/DashBoard/Component/StatCard/StatCard';
|
|
3
|
-
import { Header } from '@/shared/components/layout/Header';
|
|
4
|
-
import { useQuery } from '@tanstack/react-query';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { Card } from '@/modules/queue/components/ui';
|
|
7
|
-
import { surveysApi } from '../../services/api/surveys.api';
|
|
8
|
-
import type { NpsTrendPoint } from '../../types/survey.types';
|
|
9
|
-
import styles from '../surveyPage.module.scss';
|
|
10
|
-
|
|
11
|
-
const barColor = (score: number) => (score >= 70 ? '#4edea3' : score >= 50 ? '#7c3aed' : '#ffb4ab');
|
|
12
|
-
|
|
13
|
-
/** Renders the NPS tracker component. */
|
|
14
|
-
export const NPSTracker: React.FC = () => {
|
|
15
|
-
const { data, isLoading } = useQuery({
|
|
16
|
-
queryKey: ['nps-summary'],
|
|
17
|
-
queryFn: () => surveysApi.getNps(12),
|
|
18
|
-
staleTime: 5 * 60 * 1000,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const delta = data?.scoreDelta ?? 0;
|
|
22
|
-
const trend: NpsTrendPoint[] = Array.isArray(data?.trend) ? data!.trend : [];
|
|
23
|
-
const pct = (v?: number) => (data ? `${v ?? 0}%` : '—');
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<div className={styles.wrapper}>
|
|
27
|
-
<Header title="NPS Tracker" subtitle="Analytics · Net Promoter Score over time." />
|
|
28
|
-
|
|
29
|
-
<div className={styles.statsgrid}>
|
|
30
|
-
<StatCard
|
|
31
|
-
icon="Gauge"
|
|
32
|
-
label="Current NPS"
|
|
33
|
-
value={data ? String(data.currentScore ?? 0) : '—'}
|
|
34
|
-
trendDirection={delta > 0 ? 'up' : delta < 0 ? 'down' : 'neutral'}
|
|
35
|
-
color="#adc6ff"
|
|
36
|
-
/>
|
|
37
|
-
<StatCard icon="ThumbsUp" label="Promoters" value={pct(data?.promotersPercent)} trendDirection="neutral" color="#4edea3" />
|
|
38
|
-
<StatCard icon="Activity" label="Passives" value={pct(data?.passivesPercent)} trendDirection="neutral" color="#ffcc6b" />
|
|
39
|
-
<StatCard icon="ThumbsDown" label="Detractors" value={pct(data?.detractorsPercent)} trendDirection="neutral" color="#ffb4ab" />
|
|
40
|
-
</div>
|
|
41
|
-
|
|
42
|
-
<Card className="p-6">
|
|
43
|
-
<h2 className="mb-6 text-[16px] font-semibold text-white">
|
|
44
|
-
NPS Trend
|
|
45
|
-
{data && (
|
|
46
|
-
<span className="ml-3 text-[11px] font-normal text-[color:var(--th-text-3)]">
|
|
47
|
-
{delta >= 0 ? '+' : ''}
|
|
48
|
-
{delta} from prior period
|
|
49
|
-
</span>
|
|
50
|
-
)}
|
|
51
|
-
</h2>
|
|
52
|
-
|
|
53
|
-
{isLoading ? (
|
|
54
|
-
<div className="h-48 animate-pulse rounded-lg bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)]" />
|
|
55
|
-
) : (
|
|
56
|
-
<div className="flex h-48 items-end gap-3">
|
|
57
|
-
{trend.map((d, i) => (
|
|
58
|
-
<div key={d?.period ?? i} className="flex flex-1 flex-col items-center gap-1">
|
|
59
|
-
<span className="text-[10px] tabular-nums text-[color:var(--th-text-3)]">{d?.score ?? 0}</span>
|
|
60
|
-
<div className="relative w-full" style={{ height: 140 }}>
|
|
61
|
-
<div
|
|
62
|
-
className="absolute bottom-0 w-full rounded-t-sm"
|
|
63
|
-
style={{
|
|
64
|
-
height: `${Math.max(d?.score ?? 0, 5)}%`,
|
|
65
|
-
backgroundColor: barColor(d?.score ?? 0),
|
|
66
|
-
opacity: 0.4 + (i / Math.max(trend.length, 1)) * 0.6,
|
|
67
|
-
}}
|
|
68
|
-
/>
|
|
69
|
-
</div>
|
|
70
|
-
<span className="text-[9px] text-[color:var(--th-text-3)]">{d?.period?.split(' ')[1] ?? ''}</span>
|
|
71
|
-
</div>
|
|
72
|
-
))}
|
|
73
|
-
</div>
|
|
74
|
-
)}
|
|
75
|
-
</Card>
|
|
76
|
-
</div>
|
|
77
|
-
);
|
|
78
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {NPSTracker} from './NPStracker'
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// src/modules/survey/Pages/Responses/Responses.tsx
|
|
2
|
-
import StatCard from '@/modules/DashBoard/Component/StatCard/StatCard';
|
|
3
|
-
import { DataTable } from '@/shared/components/DataTable';
|
|
4
|
-
import { Header } from '@/shared/components/layout/Header';
|
|
5
|
-
import React, { useMemo } from 'react';
|
|
6
|
-
import { useSurveyResponses } from '../../hooks/useSurveyResponses';
|
|
7
|
-
import type { SurveyResponseItem } from '../../types/survey.types';
|
|
8
|
-
import styles from '../surveyPage.module.scss';
|
|
9
|
-
import {
|
|
10
|
-
buildResponsesFilters,
|
|
11
|
-
responsesColumns,
|
|
12
|
-
responsesSearchConfig,
|
|
13
|
-
responsesSortConfig,
|
|
14
|
-
} from './responsesTable.config';
|
|
15
|
-
|
|
16
|
-
/** Renders the responses component. */
|
|
17
|
-
export const Responses: React.FC = () => {
|
|
18
|
-
const { items, totalCount, isLoading, hasMore, loadMore } = useSurveyResponses();
|
|
19
|
-
|
|
20
|
-
const surveyNames = useMemo(() => Array.from(new Set(items.map((r) => r.surveyName))).sort(), [items]);
|
|
21
|
-
const filters = useMemo(() => buildResponsesFilters(surveyNames), [surveyNames]);
|
|
22
|
-
|
|
23
|
-
const stats = useMemo(() => {
|
|
24
|
-
const count = (c: SurveyResponseItem['npsCategory']) => items.filter((r) => r.npsCategory === c).length;
|
|
25
|
-
return { promoters: count('promoter'), passives: count('passive'), detractors: count('detractor') };
|
|
26
|
-
}, [items]);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<div className={styles.wrapper}>
|
|
30
|
-
<Header title="Responses" subtitle="Analytics · individual survey responses" />
|
|
31
|
-
|
|
32
|
-
<div className={styles.statsgrid}>
|
|
33
|
-
<StatCard icon="MessageSquare" label="Total responses" value={totalCount.toLocaleString()} trendDirection="neutral" color="#7c3aed" />
|
|
34
|
-
<StatCard icon="ThumbsUp" label="Promoters" value={stats.promoters.toLocaleString()} trendDirection="neutral" color="#4edea3" />
|
|
35
|
-
<StatCard icon="Minus" label="Passives" value={stats.passives.toLocaleString()} trendDirection="neutral" color="#ffcc6b" />
|
|
36
|
-
<StatCard icon="ThumbsDown" label="Detractors" value={stats.detractors.toLocaleString()} trendDirection="neutral" color="#ffb4ab" />
|
|
37
|
-
</div>
|
|
38
|
-
|
|
39
|
-
<DataTable<SurveyResponseItem>
|
|
40
|
-
currentPage="survey-responses"
|
|
41
|
-
columns={responsesColumns}
|
|
42
|
-
data={items}
|
|
43
|
-
totalCount={totalCount}
|
|
44
|
-
isLoading={isLoading}
|
|
45
|
-
hasMore={hasMore}
|
|
46
|
-
onLoadMore={loadMore}
|
|
47
|
-
searchConfig={responsesSearchConfig}
|
|
48
|
-
filters={filters}
|
|
49
|
-
sortConfig={responsesSortConfig}
|
|
50
|
-
/* ROW CLICK → Survey Analytics page for that survey */
|
|
51
|
-
rowClickBehavior={{ type: 'navigate', path: (r) => `/app/survey-analytics/${r.surveyId}` }}
|
|
52
|
-
rowHeight={64}
|
|
53
|
-
stickyHeader
|
|
54
|
-
height="clac(100vh - 250px)"
|
|
55
|
-
emptyMessage="No responses yet."
|
|
56
|
-
/>
|
|
57
|
-
</div>
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export default Responses;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {Responses} from './Responses';
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { ColumnDef, FilterConfig, SearchConfig, SortConfig } from '@/shared/components/DataTable/types';
|
|
2
|
-
import type { SurveyResponseItem } from '../../types/survey.types';
|
|
3
|
-
|
|
4
|
-
/* Search / Filter / Sort / Columns for the Responses table
|
|
5
|
-
(same structure as queue's pendingTable.config.ts).
|
|
6
|
-
cellType values must match cells/SurveyCells.tsx registrations. */
|
|
7
|
-
|
|
8
|
-
const at = (r: SurveyResponseItem) => Date.parse(r.createdAt) || 0;
|
|
9
|
-
const dir = (d: 'asc' | 'desc') => (d === 'asc' ? 1 : -1);
|
|
10
|
-
|
|
11
|
-
export const NPS_CATEGORIES = ['promoter', 'passive', 'detractor'] as const;
|
|
12
|
-
|
|
13
|
-
export const responsesSearchConfig: SearchConfig<SurveyResponseItem> = {
|
|
14
|
-
placeholder: 'Search by user, survey, response…',
|
|
15
|
-
keys: ['userId', 'surveyName', 'responseText'],
|
|
16
|
-
debounceMs: 150,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const responsesSortConfig: SortConfig<SurveyResponseItem> = {
|
|
20
|
-
defaultId: 'newest',
|
|
21
|
-
options: [
|
|
22
|
-
{ id: 'newest', label: 'Date: Newest first', comparator: (a, b) => at(b) - at(a) },
|
|
23
|
-
{ id: 'oldest', label: 'Date: Oldest first', comparator: (a, b) => at(a) - at(b) },
|
|
24
|
-
{ id: 'nps-high', label: 'NPS: High → Low', comparator: (a, b) => (b.npsScore ?? -1) - (a.npsScore ?? -1) },
|
|
25
|
-
{ id: 'nps-low', label: 'NPS: Low → High', comparator: (a, b) => (a.npsScore ?? 99) - (b.npsScore ?? 99) },
|
|
26
|
-
],
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Builds the responses filters.
|
|
31
|
-
*
|
|
32
|
-
* @param surveyNames - The survey names.
|
|
33
|
-
* @returns The `FilterConfig<SurveyResponseItem>[]` result.
|
|
34
|
-
*/
|
|
35
|
-
export const buildResponsesFilters = (surveyNames: string[]): FilterConfig<SurveyResponseItem>[] => [
|
|
36
|
-
{
|
|
37
|
-
id: 'survey',
|
|
38
|
-
label: 'Survey',
|
|
39
|
-
options: [{ value: 'all', label: 'All surveys' }, ...surveyNames.map((n) => ({ value: n, label: n }))],
|
|
40
|
-
defaultValue: 'all',
|
|
41
|
-
predicate: (row, v) => row.surveyName === v,
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
id: 'category',
|
|
45
|
-
label: 'NPS category',
|
|
46
|
-
options: [{ value: 'all', label: 'All categories' }, ...NPS_CATEGORIES.map((c) => ({ value: c, label: c }))],
|
|
47
|
-
defaultValue: 'all',
|
|
48
|
-
predicate: (row, v) => row.npsCategory === v,
|
|
49
|
-
},
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
export const responsesColumns: ColumnDef<SurveyResponseItem>[] = [
|
|
53
|
-
{ key: 'userId', label: 'User', cellType: 'responseUser', sortable: true, minWidth: 200 },
|
|
54
|
-
{ key: 'surveyName', label: 'Survey', sortable: true, minWidth: 200 },
|
|
55
|
-
{
|
|
56
|
-
key: 'npsScore',
|
|
57
|
-
label: 'NPS',
|
|
58
|
-
cellType: 'npsScore',
|
|
59
|
-
sortable: true,
|
|
60
|
-
width: 90,
|
|
61
|
-
sortFn: (a, b, d) => ((a.npsScore ?? -1) - (b.npsScore ?? -1)) * dir(d),
|
|
62
|
-
},
|
|
63
|
-
{ key: 'npsCategory', label: 'Category', cellType: 'responseNpsCategory', sortable: true, width: 130 },
|
|
64
|
-
{ key: 'rating', label: 'Rating', cellType: 'responseRating', sortable: true, width: 120 },
|
|
65
|
-
{ key: 'responseText', label: 'Response', cellType: 'responseText', minWidth: 260 },
|
|
66
|
-
{
|
|
67
|
-
key: 'createdAt',
|
|
68
|
-
label: 'Date',
|
|
69
|
-
sortable: true,
|
|
70
|
-
align: 'right',
|
|
71
|
-
width: 130,
|
|
72
|
-
sortFn: (a, b, d) => (at(a) - at(b)) * dir(d),
|
|
73
|
-
},
|
|
74
|
-
];
|