@shiva004/surveys 0.0.0-stage → 0.1.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.
Files changed (35) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +52 -2
  3. package/package.json +45 -4
  4. package/src/Pages/Allsurvey/Allsurvey.tsx +157 -0
  5. package/src/Pages/Allsurvey/SurveyGridCard.tsx +124 -0
  6. package/src/Pages/Allsurvey/index.ts +1 -0
  7. package/src/Pages/Allsurvey/surveysTable.config.ts +15 -0
  8. package/src/Pages/Createsurvey/Createsurvey.tsx +318 -0
  9. package/src/Pages/Createsurvey/index.ts +1 -0
  10. package/src/Pages/NPStracker/NPStracker.tsx +78 -0
  11. package/src/Pages/NPStracker/index.ts +1 -0
  12. package/src/Pages/Responses/Responses.tsx +61 -0
  13. package/src/Pages/Responses/index.ts +1 -0
  14. package/src/Pages/Responses/responsesTable.config.ts +74 -0
  15. package/src/Pages/Surveyanalytics/Surveyanalytics.tsx +154 -0
  16. package/src/Pages/Surveyanalytics/analyticsTable.config.ts +123 -0
  17. package/src/Pages/Surveyanalytics/index.ts +1 -0
  18. package/src/Pages/Surveydetails/Surveydetails.tsx +202 -0
  19. package/src/Pages/Surveydetails/index.ts +1 -0
  20. package/src/Pages/Surveytemplates/Surveytemplates.tsx +299 -0
  21. package/src/Pages/Surveytemplates/index.ts +1 -0
  22. package/src/Pages/surveyPage.module.scss +49 -0
  23. package/src/cells/SurveyCells.tsx +370 -0
  24. package/src/components/ui.ts +3 -0
  25. package/src/hooks/useSurveyResponses.ts +37 -0
  26. package/src/hooks/useTableConfig.ts +77 -0
  27. package/src/hooks/useTableData.ts +184 -0
  28. package/src/index.ts +24 -0
  29. package/src/nav.ts +55 -0
  30. package/src/routes.ts +98 -0
  31. package/src/services/api/TableConfigDto.ts +36 -0
  32. package/src/services/api/TableQueryParams.ts +10 -0
  33. package/src/services/api/surveys.api.ts +144 -0
  34. package/src/services/api/types.ts +113 -0
  35. package/src/types/survey.types.ts +175 -0
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,53 @@
1
- # Temporary Holding Version
1
+ # @your-npm-username/surveys
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Survey module: All Surveys, Create, Details, Templates, Responses, NPS Tracker and Analytics pages, plus routes, nav items, hooks and the API client.
4
+
5
+ ## Try it locally
6
+
7
+ ```bash
8
+ unzip surveys-package.zip
9
+ cd surveys
10
+ npm i
11
+ npm run typecheck # one-off check
12
+ npm run dev # re-checks types on every save
13
+ ```
14
+
15
+ This is a library, not an app, so there is no dev server. Run the pages inside your main app.
16
+
17
+ ## Before publishing
18
+
19
+ 1. Replace `your-npm-username` in `package.json` with your npm username or org (the `@scope/` must exist on npm).
20
+ 2. `npm login`
21
+ 3. `npm publish` (runs the typecheck first; `publishConfig.access` is already `public`)
22
+
23
+ ## Using it in your app
24
+
25
+ ```bash
26
+ npm i @your-npm-username/surveys
27
+ ```
28
+
29
+ ```ts
30
+ import { surveyRoutes, surveyNav, AllSurveys } from '@your-npm-username/surveys';
31
+ ```
32
+
33
+ This package ships **TypeScript source**, not a compiled build, and it is written for your existing app. Your app must provide:
34
+
35
+ - The `@/` alias, with these modules present: `@/shared/components/{DataTable,layout/Header,ui/Icon/Icon,feedback/ConfirmModal}`, `@/modules/DashBoard/Component/StatCard/StatCard`, `@/modules/queue/components/ui`, `@/app/{router,navigation,cells}/types`.
36
+ - A bundler that transpiles TS from `node_modules` and handles `*.module.scss` (Vite does; add `sass`).
37
+ - `import.meta.env` (Vite).
38
+ - Peer dependencies: react, react-dom, react-router-dom, @tanstack/react-query (v5), axios.
39
+
40
+ `types/host.d.ts` holds stand-in typings used only so `npm run typecheck` works here; it is not published.
41
+
42
+ ## Exports
43
+
44
+ | Export | What |
45
+ | --- | --- |
46
+ | `surveyRoutes`, `surveyNav` | Route configs and nav items |
47
+ | `AllSurveys`, `CreateSurvey`, `SurveyDetails`, `SurveyTemplates`, `Responses`, `NPSTracker`, `SurveyAnalytics` | Pages |
48
+ | `surveysApi` | API client |
49
+ | `useSurveyResponses`, `useTableConfig`, `useTableData` | Hooks |
50
+ | `registerSurveyCells` | Cell registration for the shared DataTable |
51
+ | survey types | Everything from `types/survey.types` |
52
+
53
+ Sub-path imports also work: `@your-npm-username/surveys/routes`, `@your-npm-username/surveys/nav`.
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@shiva004/surveys",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Survey module: all surveys, templates, create, details, responses, NPS tracker and analytics pages, with routes, nav, hooks and API client.",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "types": "./src/index.ts",
8
+ "exports": {
9
+ ".": "./src/index.ts",
10
+ "./routes": "./src/routes.ts",
11
+ "./nav": "./src/nav.ts",
12
+ "./package.json": "./package.json"
13
+ },
14
+ "sideEffects": [
15
+ "**/*.scss"
16
+ ],
17
+ "files": [
18
+ "src",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "dev": "tsc --noEmit --watch --preserveWatchOutput",
23
+ "typecheck": "tsc --noEmit",
24
+ "prepublishOnly": "npm run typecheck"
25
+ },
26
+ "peerDependencies": {
27
+ "@tanstack/react-query": ">=5",
28
+ "axios": ">=1",
29
+ "react": ">=18",
30
+ "react-dom": ">=18",
31
+ "react-router-dom": ">=6"
32
+ },
33
+ "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
+ "react": "^18.3.1",
39
+ "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
+ }
@@ -0,0 +1,157 @@
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';
@@ -0,0 +1,124 @@
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
+ import { Card } from '../../components/ui';
6
+ import type { SurveyListItem } from '../../types/survey.types';
7
+
8
+ /** Props for the card render component. */
9
+ export interface CardRenderProps<T> {
10
+ row: T;
11
+ isSelected?: boolean;
12
+ onSelect?: (id: RowId) => void;
13
+ onRowClick?: (row: T) => void;
14
+ rowIndex?: number;
15
+ }
16
+
17
+ const SC: Record<string, { dot: string; bg: string; text: string }> = {
18
+ active: { dot: 'bg-[#4edea3] animate-pulse', bg: 'bg-[color:color-mix(in_srgb,var(--th-success)_10%,transparent)]', text: 'text-[color:var(--th-success)]' },
19
+ draft: { dot: 'bg-[#ffcc6b]', bg: 'bg-[color:color-mix(in_srgb,var(--th-warning-soft)_10%,transparent)]', text: 'text-[color:var(--th-warning-soft)]' },
20
+ closed: { dot: 'bg-[#958da1]', bg: 'bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)]', text: 'text-[color:var(--th-text-3)]' },
21
+ };
22
+
23
+ /**
24
+ * Renders the survey grid card component.
25
+ *
26
+ * @param props - The component props.
27
+ * @param props.row - The row.
28
+ * @param props.isSelected - The is selected.
29
+ * @param props.onSelect - The on select.
30
+ * @param props.onRowClick - The on row click.
31
+ */
32
+ export const SurveyGridCard: React.FC<CardRenderProps<SurveyListItem>> = ({
33
+ row,
34
+ isSelected,
35
+ onSelect,
36
+ onRowClick,
37
+ }) => {
38
+ const pct = row.target > 0 ? Math.min((row.responses / row.target) * 100, 100) : 0;
39
+ const sc = SC[row.status] ?? SC.draft;
40
+
41
+ return (
42
+ <div
43
+ role="button"
44
+ tabIndex={0}
45
+ className="h-full cursor-pointer"
46
+ onClick={() => onRowClick?.(row)}
47
+ onKeyDown={(e) => e.key === 'Enter' && onRowClick?.(row)}
48
+ >
49
+ <Card
50
+ className={`group relative p-5 transition-all hover:border-[#7c3aed]/20 ${isSelected ? 'border-[#7c3aed]/40 ring-1 ring-[#7c3aed]/20' : ''
51
+ }`}
52
+ >
53
+ {onSelect && (
54
+ <button
55
+ onClick={(e) => {
56
+ e.stopPropagation();
57
+ onSelect(row.id);
58
+ }}
59
+ className={`absolute top-3 right-3 w-5 h-5 rounded border flex items-center justify-center transition-all ${isSelected
60
+ ? 'bg-[#7c3aed] border-[#7c3aed]'
61
+ : 'border-[color:color-mix(in_srgb,var(--th-ov-base)_10%,transparent)] opacity-0 group-hover:opacity-100'
62
+ }`}
63
+ >
64
+ {isSelected && <Icon icon="Check" size={11} className="text-white" />}
65
+ </button>
66
+ )}
67
+
68
+ <div className="flex items-center gap-2 mb-3">
69
+ <span className={`w-2 h-2 rounded-full ${sc.dot}`} />
70
+ <span
71
+ className={`text-[9px] px-1.5 py-0.5 rounded font-medium capitalize ${sc.bg} ${sc.text}`}
72
+ >
73
+ {row.status}
74
+ </span>
75
+ {row.npsScore !== null && row.npsScore !== undefined && (
76
+ <span
77
+ className={`text-[9px] px-1.5 py-0.5 rounded font-bold ${row.npsScore >= 70
78
+ ? 'bg-[color:color-mix(in_srgb,var(--th-success)_10%,transparent)] text-[color:var(--th-success)]'
79
+ : 'bg-[color:color-mix(in_srgb,var(--th-warning-soft)_10%,transparent)] text-[color:var(--th-warning-soft)]'
80
+ }`}
81
+ >
82
+ NPS {row.npsScore}
83
+ </span>
84
+ )}
85
+ </div>
86
+
87
+ <h3 className="text-[14px] font-semibold text-white mb-1 truncate pr-6">
88
+ {row.name}
89
+ </h3>
90
+
91
+ {row.description && (
92
+ <p className="text-[11px] text-[color:var(--th-text-3)] line-clamp-2 mb-3">
93
+ {row.description}
94
+ </p>
95
+ )}
96
+
97
+ <div className="mt-auto pt-3 border-t border-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)]">
98
+ <div className="flex items-center justify-between text-[11px] mb-1.5">
99
+ <span className="text-[color:var(--th-text-3)]">Responses</span>
100
+ <span className="text-[color:var(--th-text-1)] font-mono tabular-nums">
101
+ {row.responses.toLocaleString()} / {row.target.toLocaleString()}
102
+ </span>
103
+ </div>
104
+ <div className="h-1.5 rounded-full bg-[color:color-mix(in_srgb,var(--th-ov-base)_5%,transparent)] overflow-hidden">
105
+ <div
106
+ className={`h-full rounded-full ${pct >= 80 ? 'bg-[#4edea3]' : 'bg-[#7c3aed]'
107
+ }`}
108
+ style={{ width: `${pct}%` }}
109
+ />
110
+ </div>
111
+ </div>
112
+
113
+ <div className="flex items-center justify-between mt-3 text-[10px] text-[color:var(--th-text-3)]">
114
+ <span className="flex items-center gap-1">
115
+ <Icon icon="HelpCircle" size={10} /> {row.questionCount} questions
116
+ </span>
117
+ <span>{row.createdByName}</span>
118
+ </div>
119
+ </Card>
120
+ </div>
121
+ );
122
+ };
123
+
124
+ SurveyGridCard.displayName = 'SurveyGridCard';
@@ -0,0 +1 @@
1
+ export {AllSurveys} from './Allsurvey'
@@ -0,0 +1,15 @@
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
+ ];