@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,154 +0,0 @@
|
|
|
1
|
-
// src/modules/survey/Pages/Surveyanalytics/Surveyanalytics.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 { Icon } from '@/shared/components/ui/Icon/Icon';
|
|
6
|
-
import { useQuery } from '@tanstack/react-query';
|
|
7
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
8
|
-
import { useNavigate, useParams } from 'react-router-dom';
|
|
9
|
-
import { Card } from '@/modules/queue/components/ui';
|
|
10
|
-
import { surveysApi } from '../../services/api/surveys.api';
|
|
11
|
-
import type { SurveyAnalyticsRow } from '../../types/survey.types';
|
|
12
|
-
import styles from '../surveyPage.module.scss';
|
|
13
|
-
import {
|
|
14
|
-
analyticsColumns,
|
|
15
|
-
analyticsFilters,
|
|
16
|
-
analyticsSearchConfig,
|
|
17
|
-
analyticsSortConfig,
|
|
18
|
-
buildAnalyticsTabs,
|
|
19
|
-
filterByTab,
|
|
20
|
-
needsAttention,
|
|
21
|
-
} from './analyticsTable.config';
|
|
22
|
-
|
|
23
|
-
/** Renders the survey analytics component. */
|
|
24
|
-
export const SurveyAnalytics: React.FC = () => {
|
|
25
|
-
const navigate = useNavigate();
|
|
26
|
-
const { surveyId } = useParams<{ surveyId?: string }>();
|
|
27
|
-
|
|
28
|
-
const { data, isLoading } = useQuery({
|
|
29
|
-
queryKey: ['survey-analytics'],
|
|
30
|
-
queryFn: surveysApi.getAnalytics,
|
|
31
|
-
staleTime: 2 * 60 * 1000,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const rows: SurveyAnalyticsRow[] = useMemo(
|
|
35
|
-
() =>
|
|
36
|
-
(Array.isArray(data) ? data : [])
|
|
37
|
-
.filter((s) => Boolean(s?.surveyId))
|
|
38
|
-
.map((s) => ({ ...s, id: s.surveyId })),
|
|
39
|
-
[data]
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const [tab, setTab] = useState('all');
|
|
43
|
-
// arriving from a Responses row pre-selects that survey in the detail panel
|
|
44
|
-
const [activeId, setActiveId] = useState<string | null>(surveyId ?? null);
|
|
45
|
-
useEffect(() => setActiveId(surveyId ?? null), [surveyId]);
|
|
46
|
-
|
|
47
|
-
const tabs = useMemo(() => buildAnalyticsTabs(rows), [rows]);
|
|
48
|
-
const tabRows = useMemo(() => filterByTab(rows, tab), [rows, tab]);
|
|
49
|
-
const active = useMemo(() => rows.find((r) => r.id === activeId), [rows, activeId]);
|
|
50
|
-
|
|
51
|
-
/* ── stats ── */
|
|
52
|
-
const stats = useMemo(() => {
|
|
53
|
-
const totalResp = rows.reduce((a, r) => a + (r.totalResponses ?? 0), 0);
|
|
54
|
-
const avgCompletion = rows.length
|
|
55
|
-
? Math.round(rows.reduce((a, r) => a + (r.completionRate ?? 0), 0) / rows.length)
|
|
56
|
-
: null;
|
|
57
|
-
return { totalResp, avgCompletion, attention: rows.filter(needsAttention).length };
|
|
58
|
-
}, [rows]);
|
|
59
|
-
|
|
60
|
-
const dash = (v: string | number | null) => (isLoading || v === null ? '—' : String(v));
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<div className={styles.wrapper}>
|
|
64
|
-
{surveyId && (
|
|
65
|
-
<button
|
|
66
|
-
type="button"
|
|
67
|
-
onClick={() => navigate('/app/responses')}
|
|
68
|
-
className="flex w-fit cursor-pointer items-center gap-1.5 text-[13px] text-[color:var(--th-text-3)] transition-colors hover:text-[color:var(--th-text-2)]"
|
|
69
|
-
>
|
|
70
|
-
<Icon icon="ArrowLeft" size={15} /> Back to responses
|
|
71
|
-
</button>
|
|
72
|
-
)}
|
|
73
|
-
|
|
74
|
-
<Header title="Survey Analytics" subtitle="Aggregated survey insights and trends across your surveys." />
|
|
75
|
-
|
|
76
|
-
<div className={styles.statsgrid}>
|
|
77
|
-
<StatCard icon="BarChart3" label="Surveys" value={dash(rows.length)} trendDirection="neutral" color="#f59e0b" />
|
|
78
|
-
<StatCard icon="AlertTriangle" label="Need attention" value={dash(stats.attention)} trendDirection="neutral" color="#ef4444" />
|
|
79
|
-
<StatCard icon="MessageSquare" label="Total responses" value={dash(stats.totalResp.toLocaleString())} trendDirection="neutral" color="#6366f1" />
|
|
80
|
-
<StatCard icon="CheckCircle2" label="Avg completion" value={dash(stats.avgCompletion === null ? null : `${stats.avgCompletion}%`)} trendDirection="neutral" color="#10b981" />
|
|
81
|
-
</div>
|
|
82
|
-
|
|
83
|
-
<div className={styles.split}>
|
|
84
|
-
<div className={styles.main}>
|
|
85
|
-
<DataTable<SurveyAnalyticsRow>
|
|
86
|
-
currentPage="survey-analytics"
|
|
87
|
-
columns={analyticsColumns}
|
|
88
|
-
data={tabRows}
|
|
89
|
-
totalCount={tabRows.length}
|
|
90
|
-
isLoading={isLoading}
|
|
91
|
-
tabs={tabs}
|
|
92
|
-
activeTab={tab}
|
|
93
|
-
onTabChange={setTab}
|
|
94
|
-
searchConfig={analyticsSearchConfig}
|
|
95
|
-
filters={analyticsFilters}
|
|
96
|
-
sortConfig={analyticsSortConfig}
|
|
97
|
-
rowClickBehavior={{ type: 'callback', handler: (r) => setActiveId(r.id) }}
|
|
98
|
-
rowHeight={64}
|
|
99
|
-
stickyHeader
|
|
100
|
-
height="calc(100vh - 250px)"
|
|
101
|
-
emptyMessage={surveyId ? 'No analytics for this survey yet.' : 'No analytics data yet.'}
|
|
102
|
-
/>
|
|
103
|
-
</div>
|
|
104
|
-
|
|
105
|
-
{active && (
|
|
106
|
-
<aside className={styles.detail}>
|
|
107
|
-
<Card className="p-5">
|
|
108
|
-
<div className="flex items-start justify-between gap-3">
|
|
109
|
-
<h2 className="text-[15px] font-semibold text-white">{active.surveyName}</h2>
|
|
110
|
-
<button
|
|
111
|
-
type="button"
|
|
112
|
-
onClick={() => setActiveId(null)}
|
|
113
|
-
className="cursor-pointer text-[color:var(--th-text-3)] hover:text-[color:var(--th-text-1)]"
|
|
114
|
-
>
|
|
115
|
-
✕
|
|
116
|
-
</button>
|
|
117
|
-
</div>
|
|
118
|
-
|
|
119
|
-
<dl className="mt-4 space-y-2.5 text-[12.5px]">
|
|
120
|
-
{[
|
|
121
|
-
['Responses', (active.totalResponses ?? 0).toLocaleString()],
|
|
122
|
-
['Completion', `${active.completionRate ?? 0}%`],
|
|
123
|
-
['Avg time', active.avgCompletionTime ?? '—'],
|
|
124
|
-
['NPS', active.npsScore != null ? String(active.npsScore) : '—'],
|
|
125
|
-
['Avg rating', (active.averageRating ?? 0).toFixed(1)],
|
|
126
|
-
].map(([k, v]) => (
|
|
127
|
-
<div key={k} className="flex justify-between gap-3">
|
|
128
|
-
<dt className="text-[color:var(--th-text-3)]">{k}</dt>
|
|
129
|
-
<dd className="text-right font-mono text-[color:var(--th-text-2)]">{v}</dd>
|
|
130
|
-
</div>
|
|
131
|
-
))}
|
|
132
|
-
</dl>
|
|
133
|
-
|
|
134
|
-
<div className="mt-4 rounded-xl border border-[color:color-mix(in_srgb,var(--th-success)_10%,transparent)] bg-[color:color-mix(in_srgb,var(--th-success)_4%,transparent)] p-3.5">
|
|
135
|
-
<div className="mb-1.5 flex items-center gap-2">
|
|
136
|
-
<Icon icon="ThumbsUp" size={13} className="text-[color:var(--th-success)]" />
|
|
137
|
-
<span className="text-[11.5px] font-semibold text-[color:var(--th-success)]">Top Theme</span>
|
|
138
|
-
</div>
|
|
139
|
-
<p className="text-[13px] text-[color:var(--th-text-1)]">{active.topTheme ?? '—'}</p>
|
|
140
|
-
</div>
|
|
141
|
-
<div className="mt-3 rounded-xl border border-[color:color-mix(in_srgb,var(--th-danger-soft)_10%,transparent)] bg-[color:color-mix(in_srgb,var(--th-danger-soft)_4%,transparent)] p-3.5">
|
|
142
|
-
<div className="mb-1.5 flex items-center gap-2">
|
|
143
|
-
<Icon icon="ThumbsDown" size={13} className="text-[color:var(--th-danger-soft)]" />
|
|
144
|
-
<span className="text-[11.5px] font-semibold text-[color:var(--th-danger-soft)]">Needs Improvement</span>
|
|
145
|
-
</div>
|
|
146
|
-
<p className="text-[13px] text-[color:var(--th-text-1)]">{active.bottomTheme ?? '—'}</p>
|
|
147
|
-
</div>
|
|
148
|
-
</Card>
|
|
149
|
-
</aside>
|
|
150
|
-
)}
|
|
151
|
-
</div>
|
|
152
|
-
</div>
|
|
153
|
-
);
|
|
154
|
-
};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import type { ColumnDef, FilterConfig, SearchConfig, SortConfig } from '@/shared/components/DataTable/types';
|
|
2
|
-
import type { SurveyAnalyticsRow } from '../../types/survey.types';
|
|
3
|
-
|
|
4
|
-
/* Tabs / Search / Filter / Sort / Columns for the Survey Analytics table.
|
|
5
|
-
cellType values must match cells/SurveyCells.tsx registrations. */
|
|
6
|
-
|
|
7
|
-
/* ── health rule used by the tabs + "Need attention" stat ── */
|
|
8
|
-
/**
|
|
9
|
-
* Helper for needs attention.
|
|
10
|
-
*
|
|
11
|
-
* @param r - The r.
|
|
12
|
-
* @returns The result.
|
|
13
|
-
*/
|
|
14
|
-
export const needsAttention = (r: SurveyAnalyticsRow) =>
|
|
15
|
-
(r.npsScore ?? 0) < 50 || (r.completionRate ?? 0) < 70;
|
|
16
|
-
|
|
17
|
-
/** Allowed values for analytics tab key. */
|
|
18
|
-
export type AnalyticsTabKey = 'all' | 'healthy' | 'attention';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Builds the analytics tabs.
|
|
22
|
-
*
|
|
23
|
-
* @param rows - The rows.
|
|
24
|
-
* @returns The result.
|
|
25
|
-
*/
|
|
26
|
-
export const buildAnalyticsTabs = (rows: SurveyAnalyticsRow[]) => {
|
|
27
|
-
const attention = rows.filter(needsAttention).length;
|
|
28
|
-
return [
|
|
29
|
-
{ key: 'all', label: 'All', count: rows.length },
|
|
30
|
-
{ key: 'healthy', label: 'Healthy', count: rows.length - attention },
|
|
31
|
-
{ key: 'attention', label: 'Needs attention', count: attention },
|
|
32
|
-
];
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Filters by tab.
|
|
37
|
-
*
|
|
38
|
-
* @param rows - The rows.
|
|
39
|
-
* @param tab - The tab.
|
|
40
|
-
* @returns The result.
|
|
41
|
-
*/
|
|
42
|
-
export const filterByTab = (rows: SurveyAnalyticsRow[], tab: string) =>
|
|
43
|
-
tab === 'healthy' ? rows.filter((r) => !needsAttention(r))
|
|
44
|
-
: tab === 'attention' ? rows.filter(needsAttention)
|
|
45
|
-
: rows;
|
|
46
|
-
|
|
47
|
-
/* ── SEARCH ── */
|
|
48
|
-
export const analyticsSearchConfig: SearchConfig<SurveyAnalyticsRow> = {
|
|
49
|
-
placeholder: 'Search surveys, themes…',
|
|
50
|
-
keys: ['surveyName', 'topTheme', 'bottomTheme'],
|
|
51
|
-
debounceMs: 150,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/* ── SORT ── */
|
|
55
|
-
export const analyticsSortConfig: SortConfig<SurveyAnalyticsRow> = {
|
|
56
|
-
defaultId: 'responses',
|
|
57
|
-
options: [
|
|
58
|
-
{ id: 'responses', label: 'Most responses', comparator: (a, b) => (b.totalResponses ?? 0) - (a.totalResponses ?? 0) },
|
|
59
|
-
{ id: 'nps', label: 'NPS: High → Low', comparator: (a, b) => (b.npsScore ?? -1) - (a.npsScore ?? -1) },
|
|
60
|
-
{ id: 'completion', label: 'Completion: High → Low', comparator: (a, b) => (b.completionRate ?? 0) - (a.completionRate ?? 0) },
|
|
61
|
-
{ id: 'name', label: 'Name: A–Z', comparator: (a, b) => a.surveyName.localeCompare(b.surveyName) },
|
|
62
|
-
],
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/* ── FILTERS ── */
|
|
66
|
-
export const analyticsFilters: FilterConfig<SurveyAnalyticsRow>[] = [
|
|
67
|
-
{
|
|
68
|
-
id: 'nps',
|
|
69
|
-
label: 'NPS',
|
|
70
|
-
options: [
|
|
71
|
-
{ value: 'all', label: 'All' },
|
|
72
|
-
{ value: 'great', label: '70+' },
|
|
73
|
-
{ value: 'ok', label: '50–69' },
|
|
74
|
-
{ value: 'low', label: 'Below 50' },
|
|
75
|
-
],
|
|
76
|
-
defaultValue: 'all',
|
|
77
|
-
predicate: (r, v) => {
|
|
78
|
-
const n = r.npsScore ?? -1;
|
|
79
|
-
return v === 'great' ? n >= 70 : v === 'ok' ? n >= 50 && n < 70 : v === 'low' ? n < 50 : true;
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
id: 'completion',
|
|
84
|
-
label: 'Completion',
|
|
85
|
-
options: [
|
|
86
|
-
{ value: 'all', label: 'All' },
|
|
87
|
-
{ value: 'high', label: '80%+' },
|
|
88
|
-
{ value: 'low', label: 'Below 70%' },
|
|
89
|
-
],
|
|
90
|
-
defaultValue: 'all',
|
|
91
|
-
predicate: (r, v) => {
|
|
92
|
-
const c = r.completionRate ?? 0;
|
|
93
|
-
return v === 'high' ? c >= 80 : v === 'low' ? c < 70 : true;
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
];
|
|
97
|
-
|
|
98
|
-
/* ── COLUMNS ── */
|
|
99
|
-
export const analyticsColumns: ColumnDef<SurveyAnalyticsRow>[] = [
|
|
100
|
-
{
|
|
101
|
-
key: 'surveyName', label: 'Survey', cellType: 'analyticsSurvey', sortable: true, minWidth: 260,
|
|
102
|
-
sortFn: (a, b, d) => a.surveyName.localeCompare(b.surveyName) * (d === 'asc' ? 1 : -1),
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
key: 'totalResponses', label: 'Responses', sortable: true, width: 120,
|
|
106
|
-
sortFn: (a, b, d) => ((a.totalResponses ?? 0) - (b.totalResponses ?? 0)) * (d === 'asc' ? 1 : -1),
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
key: 'completionRate', label: 'Completion', cellType: 'analyticsCompletion', sortable: true, width: 150,
|
|
110
|
-
sortFn: (a, b, d) => ((a.completionRate ?? 0) - (b.completionRate ?? 0)) * (d === 'asc' ? 1 : -1),
|
|
111
|
-
},
|
|
112
|
-
{ key: 'avgCompletionTime', label: 'Avg time', width: 110 },
|
|
113
|
-
{
|
|
114
|
-
key: 'npsScore', label: 'NPS', cellType: 'npsScore', sortable: true, width: 90,
|
|
115
|
-
sortFn: (a, b, d) => ((a.npsScore ?? -1) - (b.npsScore ?? -1)) * (d === 'asc' ? 1 : -1),
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
key: 'averageRating', label: 'Rating', cellType: 'analyticsRating', sortable: true, width: 100,
|
|
119
|
-
sortFn: (a, b, d) => ((a.averageRating ?? 0) - (b.averageRating ?? 0)) * (d === 'asc' ? 1 : -1),
|
|
120
|
-
},
|
|
121
|
-
{ key: 'topTheme', label: 'Top theme', minWidth: 160 },
|
|
122
|
-
{ key: 'bottomTheme', label: 'Needs improvement', minWidth: 160 },
|
|
123
|
-
];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {SurveyAnalytics} from './Surveyanalytics'
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
// src/modules/survey/Pages/Surveydetails/Surveydetails.tsx
|
|
2
|
-
import { DataTable } from '@/shared/components/DataTable';
|
|
3
|
-
import StatCard from '@/modules/DashBoard/Component/StatCard/StatCard';
|
|
4
|
-
import { Header } from '@/shared/components/layout/Header';
|
|
5
|
-
import { Icon } from '@/shared/components/ui/Icon/Icon';
|
|
6
|
-
import { useQuery } from '@tanstack/react-query';
|
|
7
|
-
import React, { useMemo } from 'react';
|
|
8
|
-
import { useNavigate, useParams } from 'react-router-dom';
|
|
9
|
-
import { useSurveyResponses } from '../../hooks/useSurveyResponses';
|
|
10
|
-
import { surveysApi } from '../../services/api/surveys.api';
|
|
11
|
-
import type { SurveyResponseItem } from '../../types/survey.types';
|
|
12
|
-
import styles from '../surveyPage.module.scss';
|
|
13
|
-
import {
|
|
14
|
-
responsesColumns,
|
|
15
|
-
responsesSearchConfig,
|
|
16
|
-
responsesSortConfig,
|
|
17
|
-
} from '../Responses/responsesTable.config';
|
|
18
|
-
import { Card } from '@/modules/queue/components/ui';
|
|
19
|
-
|
|
20
|
-
// this survey's table: same columns as Responses, minus the redundant "Survey" column
|
|
21
|
-
const detailColumns = responsesColumns.filter((c) => c.key !== 'surveyName');
|
|
22
|
-
const detailSearch = { ...responsesSearchConfig, placeholder: 'Search by user, response…', keys: ['userId', 'responseText'] as (keyof SurveyResponseItem)[] };
|
|
23
|
-
|
|
24
|
-
const fmtDate = (v?: string | null) => {
|
|
25
|
-
if (!v) return '—';
|
|
26
|
-
const d = new Date(v);
|
|
27
|
-
return Number.isNaN(d.getTime())
|
|
28
|
-
? '—'
|
|
29
|
-
: d.toLocaleDateString(undefined, { day: '2-digit', month: 'short', year: 'numeric' });
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const STATUS_STYLE: Record<string, string> = {
|
|
33
|
-
active: 'text-[color:var(--th-success)]',
|
|
34
|
-
draft: 'text-[color:var(--th-warning-soft)]',
|
|
35
|
-
paused: 'text-[color:var(--th-warning-soft)]',
|
|
36
|
-
closed: 'text-[color:var(--th-text-3)]',
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/** Renders the survey details component. */
|
|
40
|
-
export const SurveyDetails: React.FC = () => {
|
|
41
|
-
const navigate = useNavigate();
|
|
42
|
-
const { surveyId } = useParams<{ surveyId: string }>();
|
|
43
|
-
|
|
44
|
-
const { data: survey, isLoading } = useQuery({
|
|
45
|
-
queryKey: ['survey', surveyId],
|
|
46
|
-
queryFn: () => surveysApi.getById(surveyId as string),
|
|
47
|
-
enabled: Boolean(surveyId),
|
|
48
|
-
staleTime: 2 * 60 * 1000,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// optional extra insight for this survey (same query the Analytics page uses → shared cache)
|
|
52
|
-
const { data: analytics } = useQuery({
|
|
53
|
-
queryKey: ['survey-analytics'],
|
|
54
|
-
queryFn: surveysApi.getAnalytics,
|
|
55
|
-
staleTime: 2 * 60 * 1000,
|
|
56
|
-
});
|
|
57
|
-
const insight = useMemo(
|
|
58
|
-
() => (Array.isArray(analytics) ? analytics : []).find((a) => a.surveyId === surveyId),
|
|
59
|
-
[analytics, surveyId]
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
// responses for THIS survey only
|
|
63
|
-
const resp = useSurveyResponses();
|
|
64
|
-
const surveyResponses = useMemo(
|
|
65
|
-
() => resp.items.filter((r) => r.surveyId === surveyId),
|
|
66
|
-
[resp.items, surveyId]
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const goBack = () => navigate('/app/all-surveys');
|
|
70
|
-
|
|
71
|
-
const backButton = (
|
|
72
|
-
<button
|
|
73
|
-
type="button"
|
|
74
|
-
onClick={goBack}
|
|
75
|
-
className="flex w-fit cursor-pointer items-center gap-1.5 text-[13px] text-[color:var(--th-text-3)] transition-colors hover:text-[color:var(--th-text-2)]"
|
|
76
|
-
>
|
|
77
|
-
<Icon icon="ArrowLeft" size={15} /> Back to surveys
|
|
78
|
-
</button>
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
if (isLoading) {
|
|
82
|
-
return (
|
|
83
|
-
<div className={styles.wrapper}>
|
|
84
|
-
{backButton}
|
|
85
|
-
<p className="text-[13px] text-[color:var(--th-text-3)]">Loading survey…</p>
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!survey) {
|
|
91
|
-
return (
|
|
92
|
-
<div className={styles.wrapper}>
|
|
93
|
-
{backButton}
|
|
94
|
-
<Card className="p-8 text-center text-[13px] text-[color:var(--th-text-3)]">
|
|
95
|
-
Survey not found.
|
|
96
|
-
</Card>
|
|
97
|
-
</div>
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const pct = survey.target > 0 ? Math.min(Math.round((survey.responses / survey.target) * 100), 100) : 0;
|
|
102
|
-
|
|
103
|
-
const info: [string, string][] = [
|
|
104
|
-
['Created by', survey.createdByName || '—'],
|
|
105
|
-
['Created', fmtDate(survey.createdAt)],
|
|
106
|
-
['Last updated', fmtDate(survey.updatedAt)],
|
|
107
|
-
['Ends', fmtDate(survey.endsAt)],
|
|
108
|
-
];
|
|
109
|
-
|
|
110
|
-
return (
|
|
111
|
-
<div className={styles.wrapper}>
|
|
112
|
-
{backButton}
|
|
113
|
-
|
|
114
|
-
<Header
|
|
115
|
-
title={survey.name}
|
|
116
|
-
subtitle={survey.description || 'Survey details'}
|
|
117
|
-
primaryText="View Analytics"
|
|
118
|
-
primaryIcon="BarChart3"
|
|
119
|
-
onPrimaryClick={() => navigate(`/app/survey-analytics/${survey.id}`)}
|
|
120
|
-
/>
|
|
121
|
-
|
|
122
|
-
<div className={styles.statsgrid}>
|
|
123
|
-
<StatCard icon="Activity" label="Status" value={survey.status.charAt(0).toUpperCase() + survey.status.slice(1)} trendDirection="neutral" color="#10b981" />
|
|
124
|
-
<StatCard icon="MessageSquare" label="Responses" value={survey.responses.toLocaleString()} trendDirection="neutral" color="#7c3aed" />
|
|
125
|
-
<StatCard icon="Star" label="NPS score" value={survey.npsScore ?? '—'} trendDirection="neutral" color="#f59e0b" />
|
|
126
|
-
<StatCard icon="HelpCircle" label="Questions" value={survey.questionCount.toLocaleString()} trendDirection="neutral" color="#6366f1" />
|
|
127
|
-
</div>
|
|
128
|
-
|
|
129
|
-
<div className={styles.cards}>
|
|
130
|
-
<Card className="p-5">
|
|
131
|
-
<h2 className="mb-4 text-[14px] font-semibold text-white">Overview</h2>
|
|
132
|
-
|
|
133
|
-
<div className="mb-1.5 flex items-center justify-between text-[12px]">
|
|
134
|
-
<span className="text-[color:var(--th-text-3)]">Response progress</span>
|
|
135
|
-
<span className="font-mono tabular-nums text-[color:var(--th-text-1)]">
|
|
136
|
-
{survey.responses.toLocaleString()} / {survey.target.toLocaleString()} ({pct}%)
|
|
137
|
-
</span>
|
|
138
|
-
</div>
|
|
139
|
-
<div className="mb-5 h-1.5 overflow-hidden rounded-full bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)]">
|
|
140
|
-
<div
|
|
141
|
-
className={`h-full rounded-full ${pct >= 80 ? 'bg-[#4edea3]' : 'bg-[#7c3aed]'}`}
|
|
142
|
-
style={{ width: `${pct}%` }}
|
|
143
|
-
/>
|
|
144
|
-
</div>
|
|
145
|
-
|
|
146
|
-
<dl className="space-y-2.5 text-[12.5px]">
|
|
147
|
-
<div className="flex justify-between gap-3">
|
|
148
|
-
<dt className="text-[color:var(--th-text-3)]">Status</dt>
|
|
149
|
-
<dd className={`capitalize ${STATUS_STYLE[survey.status] ?? ''}`}>{survey.status}</dd>
|
|
150
|
-
</div>
|
|
151
|
-
{info.map(([k, v]) => (
|
|
152
|
-
<div key={k} className="flex justify-between gap-3">
|
|
153
|
-
<dt className="text-[color:var(--th-text-3)]">{k}</dt>
|
|
154
|
-
<dd className="text-right text-[color:var(--th-text-2)]">{v}</dd>
|
|
155
|
-
</div>
|
|
156
|
-
))}
|
|
157
|
-
</dl>
|
|
158
|
-
</Card>
|
|
159
|
-
|
|
160
|
-
{insight && (
|
|
161
|
-
<Card className="p-5">
|
|
162
|
-
<h2 className="mb-4 text-[14px] font-semibold text-white">Insights</h2>
|
|
163
|
-
<dl className="space-y-2.5 text-[12.5px]">
|
|
164
|
-
{[
|
|
165
|
-
['Completion rate', `${insight.completionRate ?? 0}%`],
|
|
166
|
-
['Avg completion time', insight.avgCompletionTime ?? '—'],
|
|
167
|
-
['Avg rating', (insight.averageRating ?? 0).toFixed(1)],
|
|
168
|
-
['Top theme', insight.topTheme ?? '—'],
|
|
169
|
-
['Needs improvement', insight.bottomTheme ?? '—'],
|
|
170
|
-
].map(([k, v]) => (
|
|
171
|
-
<div key={k} className="flex justify-between gap-3">
|
|
172
|
-
<dt className="text-[color:var(--th-text-3)]">{k}</dt>
|
|
173
|
-
<dd className="text-right font-mono text-[color:var(--th-text-2)]">{v}</dd>
|
|
174
|
-
</div>
|
|
175
|
-
))}
|
|
176
|
-
</dl>
|
|
177
|
-
</Card>
|
|
178
|
-
)}
|
|
179
|
-
</div>
|
|
180
|
-
|
|
181
|
-
<h2 className="text-[14px] font-semibold text-white">
|
|
182
|
-
Responses ({surveyResponses.length.toLocaleString()})
|
|
183
|
-
</h2>
|
|
184
|
-
<DataTable<SurveyResponseItem>
|
|
185
|
-
currentPage="survey-details-responses"
|
|
186
|
-
columns={detailColumns}
|
|
187
|
-
data={surveyResponses}
|
|
188
|
-
totalCount={surveyResponses.length}
|
|
189
|
-
isLoading={resp.isLoading}
|
|
190
|
-
hasMore={resp.hasMore}
|
|
191
|
-
onLoadMore={resp.loadMore}
|
|
192
|
-
searchConfig={detailSearch}
|
|
193
|
-
sortConfig={responsesSortConfig}
|
|
194
|
-
rowHeight={64}
|
|
195
|
-
stickyHeader
|
|
196
|
-
emptyMessage="No responses for this survey yet."
|
|
197
|
-
/>
|
|
198
|
-
</div>
|
|
199
|
-
);
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
SurveyDetails.displayName = 'SurveyDetails';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { SurveyDetails } from './Surveydetails';
|