@shiva004/surveys 0.1.3 → 0.1.6

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 (37) hide show
  1. package/README.md +38 -38
  2. package/dist/assets/index-BPe2owrS.js +40 -0
  3. package/dist/assets/index-Chkvn1aI.css +1 -0
  4. package/dist/index.html +13 -0
  5. package/package.json +13 -36
  6. package/LICENSE +0 -9
  7. package/src/Pages/Allsurvey/Allsurvey.tsx +0 -157
  8. package/src/Pages/Allsurvey/SurveyGridCard.tsx +0 -125
  9. package/src/Pages/Allsurvey/index.ts +0 -1
  10. package/src/Pages/Allsurvey/surveysTable.config.ts +0 -15
  11. package/src/Pages/Createsurvey/Createsurvey.tsx +0 -318
  12. package/src/Pages/Createsurvey/index.ts +0 -1
  13. package/src/Pages/NPStracker/NPStracker.tsx +0 -78
  14. package/src/Pages/NPStracker/index.ts +0 -1
  15. package/src/Pages/Responses/Responses.tsx +0 -61
  16. package/src/Pages/Responses/index.ts +0 -1
  17. package/src/Pages/Responses/responsesTable.config.ts +0 -74
  18. package/src/Pages/Surveyanalytics/Surveyanalytics.tsx +0 -154
  19. package/src/Pages/Surveyanalytics/analyticsTable.config.ts +0 -123
  20. package/src/Pages/Surveyanalytics/index.ts +0 -1
  21. package/src/Pages/Surveydetails/Surveydetails.tsx +0 -202
  22. package/src/Pages/Surveydetails/index.ts +0 -1
  23. package/src/Pages/Surveytemplates/Surveytemplates.tsx +0 -299
  24. package/src/Pages/Surveytemplates/index.ts +0 -1
  25. package/src/Pages/surveyPage.module.scss +0 -49
  26. package/src/cells/SurveyCells.tsx +0 -370
  27. package/src/hooks/useSurveyResponses.ts +0 -37
  28. package/src/hooks/useTableConfig.ts +0 -77
  29. package/src/hooks/useTableData.ts +0 -184
  30. package/src/index.ts +0 -24
  31. package/src/nav.ts +0 -55
  32. package/src/routes.ts +0 -98
  33. package/src/services/api/TableConfigDto.ts +0 -36
  34. package/src/services/api/TableQueryParams.ts +0 -10
  35. package/src/services/api/surveys.api.ts +0 -144
  36. package/src/services/api/types.ts +0 -113
  37. package/src/types/survey.types.ts +0 -175
package/package.json CHANGED
@@ -1,47 +1,24 @@
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.6",
5
4
  "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
5
  "files": [
18
- "src",
19
- "README.md"
6
+ "dist"
20
7
  ],
21
8
  "scripts": {
22
- "dev": "tsc --noEmit --watch --preserveWatchOutput",
23
- "typecheck": "tsc --noEmit",
24
- "prepublishOnly": "npm run typecheck"
9
+ "dev": "vite",
10
+ "build": "tsc --noEmit && vite build",
11
+ "preview": "vite preview"
25
12
  },
26
- "peerDependencies": {
27
- "@tanstack/react-query": ">=5",
28
- "axios": ">=1",
29
- "react": ">=18",
30
- "react-dom": ">=18",
31
- "react-router-dom": ">=6"
13
+ "dependencies": {
14
+ "react": "^18.3.1",
15
+ "react-dom": "^18.3.1"
32
16
  },
33
17
  "devDependencies": {
34
- "@tanstack/react-query": "^5.59.0",
35
- "@types/react": "^18.3.0",
18
+ "@types/react": "^18.3.3",
36
19
  "@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"
20
+ "@vitejs/plugin-react": "^4.3.1",
21
+ "typescript": "^5.5.4",
22
+ "vite": "^5.4.2"
23
+ }
47
24
  }
package/LICENSE DELETED
@@ -1,9 +0,0 @@
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.
@@ -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
- ];