@shiva004/surveys 0.1.3 → 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.
Files changed (38) hide show
  1. package/dist/index.cjs +109 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.ts +403 -0
  4. package/dist/index.js +8716 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/style.css +1 -0
  7. package/package.json +33 -27
  8. package/src/Pages/Allsurvey/Allsurvey.tsx +0 -157
  9. package/src/Pages/Allsurvey/SurveyGridCard.tsx +0 -125
  10. package/src/Pages/Allsurvey/index.ts +0 -1
  11. package/src/Pages/Allsurvey/surveysTable.config.ts +0 -15
  12. package/src/Pages/Createsurvey/Createsurvey.tsx +0 -318
  13. package/src/Pages/Createsurvey/index.ts +0 -1
  14. package/src/Pages/NPStracker/NPStracker.tsx +0 -78
  15. package/src/Pages/NPStracker/index.ts +0 -1
  16. package/src/Pages/Responses/Responses.tsx +0 -61
  17. package/src/Pages/Responses/index.ts +0 -1
  18. package/src/Pages/Responses/responsesTable.config.ts +0 -74
  19. package/src/Pages/Surveyanalytics/Surveyanalytics.tsx +0 -154
  20. package/src/Pages/Surveyanalytics/analyticsTable.config.ts +0 -123
  21. package/src/Pages/Surveyanalytics/index.ts +0 -1
  22. package/src/Pages/Surveydetails/Surveydetails.tsx +0 -202
  23. package/src/Pages/Surveydetails/index.ts +0 -1
  24. package/src/Pages/Surveytemplates/Surveytemplates.tsx +0 -299
  25. package/src/Pages/Surveytemplates/index.ts +0 -1
  26. package/src/Pages/surveyPage.module.scss +0 -49
  27. package/src/cells/SurveyCells.tsx +0 -370
  28. package/src/hooks/useSurveyResponses.ts +0 -37
  29. package/src/hooks/useTableConfig.ts +0 -77
  30. package/src/hooks/useTableData.ts +0 -184
  31. package/src/index.ts +0 -24
  32. package/src/nav.ts +0 -55
  33. package/src/routes.ts +0 -98
  34. package/src/services/api/TableConfigDto.ts +0 -36
  35. package/src/services/api/TableQueryParams.ts +0 -10
  36. package/src/services/api/surveys.api.ts +0 -144
  37. package/src/services/api/types.ts +0 -113
  38. package/src/types/survey.types.ts +0 -175
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ ._wrapper_80t4i_2{display:flex;flex-direction:column;gap:16px;padding:20px;min-width:0}._statsgrid_80t4i_2{display:grid;gap:16px;grid-template-columns:repeat(auto-fit,minmax(210px,1fr))}._cards_80t4i_18{display:grid;gap:16px;grid-template-columns:repeat(auto-fill,minmax(320px,1fr))}._stack_80t4i_24{display:flex;flex-direction:column;gap:16px}._split_80t4i_31{display:flex;align-items:flex-start;gap:20px}._main_80t4i_37{flex:1;min-width:0}._detail_80t4i_42{display:none;width:320px;flex-shrink:0;align-self:flex-start}@media(min-width:1280px){._detail_80t4i_42{display:block}}
package/package.json CHANGED
@@ -1,47 +1,53 @@
1
1
  {
2
2
  "name": "@shiva004/surveys",
3
- "version": "0.1.3",
4
- "description": "Survey module: all surveys, templates, create, details, responses, NPS tracker and analytics pages, with routes, nav, hooks and API client.",
3
+ "version": "0.1.5",
5
4
  "type": "module",
6
- "main": "./src/index.ts",
7
- "types": "./src/index.ts",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "sideEffects": [
12
+ "**/*.css"
13
+ ],
8
14
  "exports": {
9
- ".": "./src/index.ts",
10
- "./routes": "./src/routes.ts",
11
- "./nav": "./src/nav.ts",
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.cjs"
19
+ },
20
+ "./style.css": "./dist/style.css",
12
21
  "./package.json": "./package.json"
13
22
  },
14
- "sideEffects": [
15
- "**/*.scss"
16
- ],
17
- "files": [
18
- "src",
19
- "README.md"
20
- ],
21
23
  "scripts": {
22
- "dev": "tsc --noEmit --watch --preserveWatchOutput",
24
+ "dev": "vite build --watch",
23
25
  "typecheck": "tsc --noEmit",
24
- "prepublishOnly": "npm run typecheck"
26
+ "build": "vite build",
27
+ "prepublishOnly": "npm run typecheck && npm run build"
25
28
  },
26
29
  "peerDependencies": {
27
30
  "@tanstack/react-query": ">=5",
28
31
  "axios": ">=1",
32
+ "lucide-react": ">=0.300",
29
33
  "react": ">=18",
30
34
  "react-dom": ">=18",
31
35
  "react-router-dom": ">=6"
32
36
  },
33
37
  "devDependencies": {
34
- "@tanstack/react-query": "^5.59.0",
35
- "@types/react": "^18.3.0",
36
- "@types/react-dom": "^18.3.0",
37
- "axios": "^1.7.0",
38
+ "@tanstack/react-query": "^5.106.1",
39
+ "@types/node": "^22.20.5",
40
+ "@types/react": "^18.3.31",
41
+ "@types/react-dom": "^18.3.7",
42
+ "@vitejs/plugin-react": "^4.7.0",
43
+ "axios": "^1.21.0",
44
+ "lucide-react": "^1.70.0",
38
45
  "react": "^18.3.1",
39
46
  "react-dom": "^18.3.1",
40
- "react-router-dom": "^7.18.5",
41
- "typescript": "^5.4.0"
42
- },
43
- "publishConfig": {
44
- "access": "public"
45
- },
46
- "license": "MIT"
47
+ "react-router-dom": "^6.30.6",
48
+ "sass": "^1.108.0",
49
+ "typescript": "^5.9.3",
50
+ "vite": "^6.4.5",
51
+ "vite-plugin-dts": "^4.5.4"
52
+ }
47
53
  }
@@ -1,157 +0,0 @@
1
- // src/modules/survey/Pages/Allsurvey/Allsurvey.tsx
2
- import StatCard from '@/modules/DashBoard/Component/StatCard/StatCard';
3
- import { DataTable } from '@/shared/components/DataTable';
4
- import type { ColumnDef, RowId } from '@/shared/components/DataTable/types';
5
- import { ConfirmModal } from '@/shared/components/feedback/ConfirmModal';
6
- import { Header } from '@/shared/components/layout/Header';
7
- import React, { useCallback, useMemo, useState } from 'react';
8
- import { useNavigate } from 'react-router-dom';
9
- import { useTableConfig } from '../../hooks/useTableConfig';
10
- import { useTableData } from '../../hooks/useTableData';
11
- import { surveysApi } from '../../services/api/surveys.api';
12
- import type { SurveyRow } from '../../types/survey.types';
13
- import styles from '../surveyPage.module.scss';
14
- import { SurveyGridCard } from './SurveyGridCard';
15
- import { surveysColumns } from './surveysTable.config';
16
-
17
- /** Renders the all surveys component. */
18
- export const AllSurveys: React.FC = () => {
19
- const navigate = useNavigate();
20
- const tableConfig = useTableConfig<SurveyRow>('surveys');
21
-
22
- const {
23
- items: rawItems,
24
- totalCount,
25
- hasMore,
26
- isLoading,
27
- loadMore,
28
- handleSort,
29
- handleTabChange,
30
- sortBy,
31
- sortOrder,
32
- activeTab,
33
- optimisticRemove,
34
- } = useTableData<SurveyRow>({
35
- resource: '/surveys',
36
- queryKey: ['surveys'],
37
- fetchFn: (params) => surveysApi.list(params),
38
- pageSize: tableConfig.defaultPageSize,
39
- defaultSortBy: tableConfig.defaultSortBy,
40
- defaultSortOrder: tableConfig.defaultSortOrder,
41
- });
42
-
43
- // guard against undefined rows / missing id
44
- const rows = useMemo(() => (rawItems ?? []).filter((i): i is SurveyRow => Boolean(i?.id)), [rawItems]);
45
-
46
- const [selectedIds, setSelectedIds] = useState<Set<RowId>>(new Set());
47
- const [deleteTarget, setDeleteTarget] = useState<SurveyRow | null>(null);
48
- const [isDeleting, setIsDeleting] = useState(false);
49
-
50
- const handleDelete = useCallback(async () => {
51
- if (!deleteTarget) return;
52
- setIsDeleting(true);
53
- try {
54
- await surveysApi.delete(deleteTarget.id);
55
- optimisticRemove(deleteTarget.id);
56
- setDeleteTarget(null);
57
- } finally {
58
- setIsDeleting(false);
59
- }
60
- }, [deleteTarget, optimisticRemove]);
61
-
62
- const goCreate = useCallback(() => navigate('/app/all-surveys/create-survey'), [navigate]);
63
-
64
- const controls = useMemo(
65
- () =>
66
- (tableConfig.controls ?? []).map((c) => ({
67
- ...c,
68
- onClick: () => {
69
- if (c.action === 'create') goCreate();
70
- },
71
- })),
72
- [tableConfig.controls, goCreate]
73
- );
74
-
75
- // server config wins; typed fallback until it loads
76
- const columns = (
77
- tableConfig.columns?.length ? tableConfig.columns : surveysColumns
78
- ) as ColumnDef<SurveyRow>[];
79
-
80
- /* ── stats (derived from loaded rows) ── */
81
- const stats = useMemo(() => {
82
- const active = rows.filter((r) => r.status === 'active').length;
83
- const totalResp = rows.reduce((a, r) => a + (r.responses ?? 0), 0);
84
- const scored = rows.filter((r) => r.npsScore !== null && r.npsScore !== undefined);
85
- const avgNps = scored.length
86
- ? Math.round(scored.reduce((a, r) => a + (r.npsScore ?? 0), 0) / scored.length)
87
- : null;
88
- return { active, totalResp, avgNps };
89
- }, [rows]);
90
-
91
- return (
92
- <div className={styles.wrapper}>
93
- <Header
94
- title="Surveys"
95
- subtitle="Analytics · manage and track user surveys."
96
- primaryText="Create Survey"
97
- primaryIcon="Plus"
98
- onPrimaryClick={goCreate}
99
- />
100
-
101
- <div className={styles.statsgrid}>
102
- <StatCard icon="ClipboardList" label="Total surveys" value={totalCount.toLocaleString()} trendDirection="neutral" color="#6366f1" />
103
- <StatCard icon="Activity" label="Active" value={stats.active.toLocaleString()} trendDirection="neutral" color="#10b981" />
104
- <StatCard icon="MessageSquare" label="Total responses" value={stats.totalResp.toLocaleString()} trendDirection="neutral" color="#7c3aed" />
105
- <StatCard icon="Star" label="Avg NPS" value={stats.avgNps ?? '—'} trendDirection="neutral" color="#f59e0b" />
106
- </div>
107
-
108
- <DataTable<SurveyRow>
109
- currentPage="surveys"
110
- columns={columns}
111
- data={rows}
112
- totalCount={totalCount}
113
- isLoading={tableConfig.isLoading || isLoading}
114
- hasMore={hasMore}
115
- onLoadMore={loadMore}
116
- availableViews={['table', 'grid']}
117
- renderCard={(props) => <SurveyGridCard {...props} />}
118
- gridCols={{ sm: 1, md: 2, lg: 3 }}
119
- tabs={tableConfig.tabs}
120
- activeTab={activeTab}
121
- onTabChange={handleTabChange}
122
- controls={controls}
123
- selectable
124
- selectedIds={selectedIds}
125
- onSelectionChange={setSelectedIds}
126
- sortBy={sortBy}
127
- sortOrder={sortOrder}
128
- onSort={handleSort}
129
- onEditRow={(row) => navigate(`/app/surveys/${row.id}/edit`)}
130
- onActionClick={(row) => setDeleteTarget(row)}
131
- rowClickBehavior={{ type: 'navigate', path: (r) => `/app/surveys/${r.id}` }}
132
- height="calc(100vh - 250px)"
133
- emptyMessage="No surveys found."
134
- stickyHeader
135
- />
136
-
137
- <ConfirmModal
138
- open={Boolean(deleteTarget)}
139
- onClose={() => setDeleteTarget(null)}
140
- onConfirm={handleDelete}
141
- isLoading={isDeleting}
142
- title="Delete Survey"
143
- description={
144
- <>
145
- Delete <strong className="text-white">{deleteTarget?.name}</strong> and all{' '}
146
- {deleteTarget?.responses ?? 0} responses?
147
- </>
148
- }
149
- confirmLabel="Delete Survey"
150
- confirmTone="danger"
151
- requireConfirmText={deleteTarget?.name}
152
- />
153
- </div>
154
- );
155
- };
156
-
157
- AllSurveys.displayName = 'AllSurveys';
@@ -1,125 +0,0 @@
1
- // src/modules/survey/Pages/Allsurvey/SurveyGridCard.tsx
2
- import type { RowId } from '@/shared/components/DataTable/types';
3
- import { Icon } from '@/shared/components/ui/Icon/Icon';
4
- import React from 'react';
5
-
6
- import { Card } from '@/modules/queue/components/ui';
7
- import type { SurveyListItem } from '../../types/survey.types';
8
-
9
- /** Props for the card render component. */
10
- export interface CardRenderProps<T> {
11
- row: T;
12
- isSelected?: boolean;
13
- onSelect?: (id: RowId) => void;
14
- onRowClick?: (row: T) => void;
15
- rowIndex?: number;
16
- }
17
-
18
- const SC: Record<string, { dot: string; bg: string; text: string }> = {
19
- active: { dot: 'bg-[#4edea3] animate-pulse', bg: 'bg-[color:color-mix(in_srgb,var(--th-success)_10%,transparent)]', text: 'text-[color:var(--th-success)]' },
20
- draft: { dot: 'bg-[#ffcc6b]', bg: 'bg-[color:color-mix(in_srgb,var(--th-warning-soft)_10%,transparent)]', text: 'text-[color:var(--th-warning-soft)]' },
21
- closed: { dot: 'bg-[#958da1]', bg: 'bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)]', text: 'text-[color:var(--th-text-3)]' },
22
- };
23
-
24
- /**
25
- * Renders the survey grid card component.
26
- *
27
- * @param props - The component props.
28
- * @param props.row - The row.
29
- * @param props.isSelected - The is selected.
30
- * @param props.onSelect - The on select.
31
- * @param props.onRowClick - The on row click.
32
- */
33
- export const SurveyGridCard: React.FC<CardRenderProps<SurveyListItem>> = ({
34
- row,
35
- isSelected,
36
- onSelect,
37
- onRowClick,
38
- }) => {
39
- const pct = row.target > 0 ? Math.min((row.responses / row.target) * 100, 100) : 0;
40
- const sc = SC[row.status] ?? SC.draft;
41
-
42
- return (
43
- <div
44
- role="button"
45
- tabIndex={0}
46
- className="h-full cursor-pointer"
47
- onClick={() => onRowClick?.(row)}
48
- onKeyDown={(e) => e.key === 'Enter' && onRowClick?.(row)}
49
- >
50
- <Card
51
- className={`group relative p-5 transition-all hover:border-[#7c3aed]/20 ${isSelected ? 'border-[#7c3aed]/40 ring-1 ring-[#7c3aed]/20' : ''
52
- }`}
53
- >
54
- {onSelect && (
55
- <button
56
- onClick={(e) => {
57
- e.stopPropagation();
58
- onSelect(row.id);
59
- }}
60
- className={`absolute top-3 right-3 w-5 h-5 rounded border flex items-center justify-center transition-all ${isSelected
61
- ? 'bg-[#7c3aed] border-[#7c3aed]'
62
- : 'border-[color:color-mix(in_srgb,var(--th-ov-base)_10%,transparent)] opacity-0 group-hover:opacity-100'
63
- }`}
64
- >
65
- {isSelected && <Icon icon="Check" size={11} className="text-white" />}
66
- </button>
67
- )}
68
-
69
- <div className="flex items-center gap-2 mb-3">
70
- <span className={`w-2 h-2 rounded-full ${sc.dot}`} />
71
- <span
72
- className={`text-[9px] px-1.5 py-0.5 rounded font-medium capitalize ${sc.bg} ${sc.text}`}
73
- >
74
- {row.status}
75
- </span>
76
- {row.npsScore !== null && row.npsScore !== undefined && (
77
- <span
78
- className={`text-[9px] px-1.5 py-0.5 rounded font-bold ${row.npsScore >= 70
79
- ? 'bg-[color:color-mix(in_srgb,var(--th-success)_10%,transparent)] text-[color:var(--th-success)]'
80
- : 'bg-[color:color-mix(in_srgb,var(--th-warning-soft)_10%,transparent)] text-[color:var(--th-warning-soft)]'
81
- }`}
82
- >
83
- NPS {row.npsScore}
84
- </span>
85
- )}
86
- </div>
87
-
88
- <h3 className="text-[14px] font-semibold text-white mb-1 truncate pr-6">
89
- {row.name}
90
- </h3>
91
-
92
- {row.description && (
93
- <p className="text-[11px] text-[color:var(--th-text-3)] line-clamp-2 mb-3">
94
- {row.description}
95
- </p>
96
- )}
97
-
98
- <div className="mt-auto pt-3 border-t border-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)]">
99
- <div className="flex items-center justify-between text-[11px] mb-1.5">
100
- <span className="text-[color:var(--th-text-3)]">Responses</span>
101
- <span className="text-[color:var(--th-text-1)] font-mono tabular-nums">
102
- {row.responses.toLocaleString()} / {row.target.toLocaleString()}
103
- </span>
104
- </div>
105
- <div className="h-1.5 rounded-full bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] overflow-hidden">
106
- <div
107
- className={`h-full rounded-full ${pct >= 80 ? 'bg-[#4edea3]' : 'bg-[#7c3aed]'
108
- }`}
109
- style={{ width: `${pct}%` }}
110
- />
111
- </div>
112
- </div>
113
-
114
- <div className="flex items-center justify-between mt-3 text-[10px] text-[color:var(--th-text-3)]">
115
- <span className="flex items-center gap-1">
116
- <Icon icon="HelpCircle" size={10} /> {row.questionCount} questions
117
- </span>
118
- <span>{row.createdByName}</span>
119
- </div>
120
- </Card>
121
- </div>
122
- );
123
- };
124
-
125
- SurveyGridCard.displayName = 'SurveyGridCard';
@@ -1 +0,0 @@
1
- export {AllSurveys} from './Allsurvey'
@@ -1,15 +0,0 @@
1
- import type { ColumnDef } from '@/shared/components/DataTable/types';
2
- import type { SurveyRow } from '../../types/survey.types';
3
-
4
- /* Fallback columns, used until GET /tables/surveys/config responds.
5
- (Same idea as queue's pendingTable.config.ts — columns live in a config file, not in the page.)
6
- `cellType` values must match the types registered in cells/SurveyCells.tsx. */
7
- export const surveysColumns: ColumnDef<SurveyRow>[] = [
8
- { key: 'name', label: 'Survey', cellType: 'surveyName', sortable: true, minWidth: 260 },
9
- { key: 'status', label: 'Status', cellType: 'surveyStatus', sortable: true, width: 90, align: 'center' },
10
- { key: 'responses', label: 'Responses', cellType: 'responseProgress', sortable: true, width: 160 },
11
- { key: 'npsScore', label: 'NPS Score', cellType: 'npsScore', sortable: true, width: 110 },
12
- { key: 'questionCount', label: 'Questions', sortable: false, width: 100 },
13
- { key: 'createdByName', label: 'Created By', sortable: false, width: 160 },
14
- { key: 'updatedAt', label: 'Updated', sortable: true, width: 130 },
15
- ];