@matija2209/payload-plugin-admin-feedback 1.0.0
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/README.md +159 -0
- package/package.json +29 -0
- package/public/payload-admin-plugin-header.png +0 -0
- package/src/client/AdminFeedbackWidget.tsx +63 -0
- package/src/client/FeedbackWidget.tsx +1438 -0
- package/src/client/FrontendFeedbackWidget.tsx +100 -0
- package/src/client/index.ts +4 -0
- package/src/client/routeMatcher.ts +18 -0
- package/src/collections/AdminFeedback.ts +325 -0
- package/src/index.ts +108 -0
- package/src/server/sendFeedbackEmail.ts +141 -0
- package/src/types.ts +73 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +19 -0
- package/tsup.config.ts +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# payload-plugin-admin-feedback
|
|
4
|
+
|
|
5
|
+
Floating feedback/chat widget plugin for Payload CMS admin and selected Next.js frontend routes.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Adds `admin-feedback` collection to Payload
|
|
10
|
+
- Floating client widget with:
|
|
11
|
+
- message input
|
|
12
|
+
- current page path capture
|
|
13
|
+
- optional CSS selector capture
|
|
14
|
+
- current-tab-first screenshot capture, full-screen annotation, clipboard paste, and file upload
|
|
15
|
+
- native HTML5 tools for pen, rectangle, arrow, text, undo, redo, clear, and revert
|
|
16
|
+
- Email notification on feedback creation through configured Payload email adapter
|
|
17
|
+
- Frontend allowlist route matching helper
|
|
18
|
+
- Strict media collection validation with fail-fast startup errors
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add payload-plugin-admin-feedback
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Requirements
|
|
27
|
+
|
|
28
|
+
- `payload` `^3.84.1` (native advanced plugin API with `definePlugin`)
|
|
29
|
+
- `react` ^19
|
|
30
|
+
|
|
31
|
+
## Version Compatibility
|
|
32
|
+
|
|
33
|
+
| Plugin Version | Payload Version |
|
|
34
|
+
| -------------- | --------------- |
|
|
35
|
+
| 1.x.x | ^3.84.1 |
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { buildConfig } from 'payload'
|
|
41
|
+
import { adminFeedbackPlugin } from 'payload-plugin-admin-feedback'
|
|
42
|
+
|
|
43
|
+
export default buildConfig({
|
|
44
|
+
// ...
|
|
45
|
+
plugins: [
|
|
46
|
+
adminFeedbackPlugin({
|
|
47
|
+
emailTo: 'it@example.com',
|
|
48
|
+
fromLabel: 'Store Admin Feedback',
|
|
49
|
+
allowScreenshotUpload: true,
|
|
50
|
+
mediaCollectionSlug: 'media',
|
|
51
|
+
strictMediaCollection: true,
|
|
52
|
+
screenshot: {
|
|
53
|
+
maxFileSizeBytes: 5 * 1024 * 1024,
|
|
54
|
+
allowedMimeTypes: ['image/png', 'image/jpeg', 'image/webp'],
|
|
55
|
+
capturePolicy: 'current-tab-first',
|
|
56
|
+
},
|
|
57
|
+
maxMessageLength: 3000,
|
|
58
|
+
frontend: {
|
|
59
|
+
enabled: true,
|
|
60
|
+
include: ['/marketplace*', '/profile*'],
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
],
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Plugin Options
|
|
68
|
+
|
|
69
|
+
- `enabled?: boolean` default `true`
|
|
70
|
+
- `emailTo: string | string[]` required
|
|
71
|
+
- `fromLabel?: string`
|
|
72
|
+
- `allowScreenshotUpload?: boolean` default `true`
|
|
73
|
+
- `mediaCollectionSlug?: string` default `'media'`
|
|
74
|
+
- `strictMediaCollection?: boolean` default `true`
|
|
75
|
+
- `screenshot?: { enabled?: boolean; maxFileSizeBytes?: number; allowedMimeTypes?: string[]; capturePolicy?: 'current-tab-first' | 'strict-current-tab' | 'any-surface' }`
|
|
76
|
+
- `maxMessageLength?: number` default `3000`
|
|
77
|
+
- `frontend?: { enabled?: boolean; include?: string[] }`
|
|
78
|
+
- `frontendRouteMatcher?: (pathname: string) => boolean`
|
|
79
|
+
|
|
80
|
+
## Screenshot Capture Behavior
|
|
81
|
+
|
|
82
|
+
- `current-tab-first` is the default. The widget prefers the active browser tab and still accepts window or screen capture if the browser returns a broader surface.
|
|
83
|
+
- `strict-current-tab` requires the captured surface to resolve as a browser tab and fails otherwise.
|
|
84
|
+
- `any-surface` allows the browser to offer any supported surface without tab-first constraints.
|
|
85
|
+
- Captured, pasted, and uploaded images all open in the same full-screen HTML5 annotation editor and are exported as a flattened PNG before upload.
|
|
86
|
+
|
|
87
|
+
## Storage Adapter Compatibility
|
|
88
|
+
|
|
89
|
+
The plugin uploads images through the resolved Payload upload collection, not directly to a specific storage adapter.
|
|
90
|
+
|
|
91
|
+
- If your upload collection is configured with `@payloadcms/storage-*`, uploads are automatically stored there.
|
|
92
|
+
- If the configured collection slug is missing or not upload-enabled, plugin initialization fails with a clear error.
|
|
93
|
+
- In strict mode (default), there are no fallback guesses to other collections.
|
|
94
|
+
|
|
95
|
+
## Client Components
|
|
96
|
+
|
|
97
|
+
The plugin exports React client components for embedding the feedback widget on frontend routes and in the admin panel.
|
|
98
|
+
|
|
99
|
+
### Frontend Widget
|
|
100
|
+
|
|
101
|
+
Add the `FrontendFeedbackWidget` to any layout or page that should show the floating feedback button. It uses `usePathname` from `next/navigation` to detect the current route and show/hide the widget based on the `include` patterns.
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import { FrontendFeedbackWidget } from 'payload-plugin-admin-feedback/client';
|
|
105
|
+
|
|
106
|
+
export default function MyLayout({ children }: { children: React.ReactNode }) {
|
|
107
|
+
return (
|
|
108
|
+
<>
|
|
109
|
+
{children}
|
|
110
|
+
<FrontendFeedbackWidget
|
|
111
|
+
include={['/dashboard', '/dashboard/*', '/settings']}
|
|
112
|
+
/>
|
|
113
|
+
</>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Props**
|
|
119
|
+
|
|
120
|
+
| Prop | Type | Default | Description |
|
|
121
|
+
| ---- | ---- | ------- | ----------- |
|
|
122
|
+
| `include` | `string[]` | required | Glob patterns for routes where the widget is visible |
|
|
123
|
+
| `position` | `{ bottom?: number; right?: number }` | `{ bottom: 20, right: 20 }` | Pixel offset from the viewport edge |
|
|
124
|
+
| `buttonLabel` | `string` | `'Feedback'` | Text shown on the floating button |
|
|
125
|
+
| `dialogTitle` | `string` | `'Send Feedback'` | Title shown in the dialog header |
|
|
126
|
+
|
|
127
|
+
**Glob patterns** support `*` (single segment) and `**` (recursive):
|
|
128
|
+
`/admin/*` matches `/admin/users` but not `/admin/settings/roles`.
|
|
129
|
+
`/admin/**` matches `/admin`, `/admin/users`, `/admin/settings/roles`, etc.
|
|
130
|
+
|
|
131
|
+
### Admin Widget
|
|
132
|
+
|
|
133
|
+
For rendering the widget inside the Payload admin panel:
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import { AdminFeedbackWidget } from 'payload-plugin-admin-feedback/client';
|
|
137
|
+
|
|
138
|
+
<AdminFeedbackWidget />
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Route Matcher
|
|
142
|
+
|
|
143
|
+
A utility for programmatic path matching, exported for reuse:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { pathMatchesAllowlist } from 'payload-plugin-admin-feedback/client';
|
|
147
|
+
|
|
148
|
+
const visible = pathMatchesAllowlist('/dashboard/users', ['/dashboard', '/dashboard/*']);
|
|
149
|
+
// => true
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Migration Notes
|
|
153
|
+
|
|
154
|
+
- The plugin uses native Payload advanced plugin metadata (`slug`, `order`, `options`) via `definePlugin`.
|
|
155
|
+
- Existing usage with `adminFeedbackPlugin({ ...options })` remains unchanged.
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@matija2209/payload-plugin-admin-feedback",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Floating admin feedback widget plugin for Payload CMS.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./client": {
|
|
16
|
+
"types": "./dist/client/index.d.ts",
|
|
17
|
+
"import": "./dist/client/index.js",
|
|
18
|
+
"require": "./dist/client/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts src/client/index.ts --format cjs,esm --dts --clean --minify",
|
|
23
|
+
"dev": "tsup src/index.ts src/client/index.ts --format cjs,esm --dts --watch"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"payload": "^3.84.1",
|
|
27
|
+
"react": "^19.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
import { FeedbackWidget } from './FeedbackWidget';
|
|
6
|
+
|
|
7
|
+
export function AdminFeedbackWidget() {
|
|
8
|
+
return (
|
|
9
|
+
<FeedbackWidget
|
|
10
|
+
title="Admin feedback"
|
|
11
|
+
submitLabel="Send"
|
|
12
|
+
uploadLabel="Upload image"
|
|
13
|
+
allowScreenshotUpload
|
|
14
|
+
onSubmit={async (payload) => {
|
|
15
|
+
const response = await fetch('/api/admin-feedback/submit', {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
credentials: 'include',
|
|
18
|
+
headers: { 'content-type': 'application/json' },
|
|
19
|
+
body: JSON.stringify(payload),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const result = (await response.json()) as { success: boolean; error?: string };
|
|
23
|
+
if (!result.success) {
|
|
24
|
+
return { success: false as const, error: result.error || 'Submit failed.' };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return { success: true as const };
|
|
28
|
+
}}
|
|
29
|
+
onUpload={async (formData) => {
|
|
30
|
+
const response = await fetch('/api/admin-feedback/upload', {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
credentials: 'include',
|
|
33
|
+
body: formData,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const result = (await response.json()) as {
|
|
37
|
+
success: boolean;
|
|
38
|
+
error?: string;
|
|
39
|
+
mediaId?: number;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (!result.success || typeof result.mediaId !== 'number') {
|
|
43
|
+
return { success: false as const, error: result.error || 'Upload failed.' };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { success: true as const, mediaId: result.mediaId };
|
|
47
|
+
}}
|
|
48
|
+
onDeleteScreenshot={async (mediaId) => {
|
|
49
|
+
const response = await fetch(`/api/admin-feedback/upload/${mediaId}`, {
|
|
50
|
+
method: 'DELETE',
|
|
51
|
+
credentials: 'include',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const result = (await response.json()) as { success: boolean; error?: string };
|
|
55
|
+
if (!result.success) {
|
|
56
|
+
return { success: false as const, error: result.error || 'Delete failed.' };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { success: true as const };
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
}
|