feat(feedback): optionales E-Mail-Kontaktfeld im Formular
Nutzer können optional eine E-Mail hinterlassen; Validierung client-/serverseitig, Weitergabe in Ntfy-Benachrichtigungen. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -457,6 +457,7 @@ html.scheme-dark .themed-select-option.is-selected {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.feedback-form__field select,
|
.feedback-form__field select,
|
||||||
|
.feedback-form__field input,
|
||||||
.feedback-form__field textarea {
|
.feedback-form__field textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 10px 12px;
|
padding: 10px 12px;
|
||||||
@@ -469,6 +470,7 @@ html.scheme-dark .themed-select-option.is-selected {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.feedback-form__field select:focus,
|
.feedback-form__field select:focus,
|
||||||
|
.feedback-form__field input:focus,
|
||||||
.feedback-form__field textarea:focus {
|
.feedback-form__field textarea:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
border-color: var(--app-accent, #38bdf8);
|
border-color: var(--app-accent, #38bdf8);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export default function FeedbackModal({
|
|||||||
}: FeedbackModalProps) {
|
}: FeedbackModalProps) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [category, setCategory] = useState<FeedbackCategory>('general')
|
const [category, setCategory] = useState<FeedbackCategory>('general')
|
||||||
|
const [contactEmail, setContactEmail] = useState('')
|
||||||
const [message, setMessage] = useState('')
|
const [message, setMessage] = useState('')
|
||||||
const [submitState, setSubmitState] = useState<SubmitState>('idle')
|
const [submitState, setSubmitState] = useState<SubmitState>('idle')
|
||||||
const [statusMessage, setStatusMessage] = useState<string | null>(null)
|
const [statusMessage, setStatusMessage] = useState<string | null>(null)
|
||||||
@@ -53,6 +54,7 @@ export default function FeedbackModal({
|
|||||||
if (!open) {
|
if (!open) {
|
||||||
clearCloseTimer()
|
clearCloseTimer()
|
||||||
setCategory('general')
|
setCategory('general')
|
||||||
|
setContactEmail('')
|
||||||
setMessage('')
|
setMessage('')
|
||||||
setSubmitState('idle')
|
setSubmitState('idle')
|
||||||
setStatusMessage(null)
|
setStatusMessage(null)
|
||||||
@@ -70,6 +72,7 @@ export default function FeedbackModal({
|
|||||||
await sendFeedback({
|
await sendFeedback({
|
||||||
category,
|
category,
|
||||||
message: message.trim(),
|
message: message.trim(),
|
||||||
|
contactEmail: contactEmail.trim() || undefined,
|
||||||
logbookId,
|
logbookId,
|
||||||
logbookTitle
|
logbookTitle
|
||||||
})
|
})
|
||||||
@@ -84,7 +87,9 @@ export default function FeedbackModal({
|
|||||||
setStatusMessage(
|
setStatusMessage(
|
||||||
error instanceof FeedbackApiError && error.code === 'NOT_CONFIGURED'
|
error instanceof FeedbackApiError && error.code === 'NOT_CONFIGURED'
|
||||||
? t('feedback.error_not_configured')
|
? t('feedback.error_not_configured')
|
||||||
: t('feedback.error_send')
|
: error instanceof FeedbackApiError && error.code === 'INVALID_EMAIL'
|
||||||
|
? t('feedback.error_invalid_email')
|
||||||
|
: t('feedback.error_send')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,6 +144,25 @@ export default function FeedbackModal({
|
|||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<label className="feedback-form__field">
|
||||||
|
<span>{t('feedback.contact_label')}</span>
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
value={contactEmail}
|
||||||
|
onChange={(event) => {
|
||||||
|
setContactEmail(event.target.value)
|
||||||
|
if (submitState === 'error') {
|
||||||
|
setSubmitState('idle')
|
||||||
|
setStatusMessage(null)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
placeholder={t('feedback.contact_placeholder')}
|
||||||
|
autoComplete="email"
|
||||||
|
maxLength={254}
|
||||||
|
disabled={submitState === 'submitting'}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
<label className="feedback-form__field">
|
<label className="feedback-form__field">
|
||||||
<span>{t('feedback.message_label')}</span>
|
<span>{t('feedback.message_label')}</span>
|
||||||
<textarea
|
<textarea
|
||||||
|
|||||||
@@ -406,6 +406,8 @@
|
|||||||
"category_general": "Allgemein",
|
"category_general": "Allgemein",
|
||||||
"category_bug": "Fehler melden",
|
"category_bug": "Fehler melden",
|
||||||
"category_feature": "Feature-Wunsch",
|
"category_feature": "Feature-Wunsch",
|
||||||
|
"contact_label": "E-Mail (optional)",
|
||||||
|
"contact_placeholder": "ihre@email.beispiel",
|
||||||
"message_label": "Nachricht",
|
"message_label": "Nachricht",
|
||||||
"message_placeholder": "Beschreiben Sie Ihr Feedback…",
|
"message_placeholder": "Beschreiben Sie Ihr Feedback…",
|
||||||
"send": "Senden",
|
"send": "Senden",
|
||||||
@@ -413,6 +415,7 @@
|
|||||||
"cancel": "Abbrechen",
|
"cancel": "Abbrechen",
|
||||||
"success": "Vielen Dank! Ihr Feedback wurde gesendet.",
|
"success": "Vielen Dank! Ihr Feedback wurde gesendet.",
|
||||||
"error_send": "Feedback konnte nicht gesendet werden. Bitte versuchen Sie es später erneut.",
|
"error_send": "Feedback konnte nicht gesendet werden. Bitte versuchen Sie es später erneut.",
|
||||||
|
"error_invalid_email": "Bitte geben Sie eine gültige E-Mail-Adresse ein.",
|
||||||
"error_not_configured": "Feedback ist auf diesem Server nicht verfügbar."
|
"error_not_configured": "Feedback ist auf diesem Server nicht verfügbar."
|
||||||
},
|
},
|
||||||
"demo": {
|
"demo": {
|
||||||
|
|||||||
@@ -406,6 +406,8 @@
|
|||||||
"category_general": "General",
|
"category_general": "General",
|
||||||
"category_bug": "Bug report",
|
"category_bug": "Bug report",
|
||||||
"category_feature": "Feature request",
|
"category_feature": "Feature request",
|
||||||
|
"contact_label": "Email (optional)",
|
||||||
|
"contact_placeholder": "your@email.example",
|
||||||
"message_label": "Message",
|
"message_label": "Message",
|
||||||
"message_placeholder": "Describe your feedback…",
|
"message_placeholder": "Describe your feedback…",
|
||||||
"send": "Send",
|
"send": "Send",
|
||||||
@@ -413,6 +415,7 @@
|
|||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
"success": "Thank you! Your feedback has been sent.",
|
"success": "Thank you! Your feedback has been sent.",
|
||||||
"error_send": "Could not send feedback. Please try again later.",
|
"error_send": "Could not send feedback. Please try again later.",
|
||||||
|
"error_invalid_email": "Please enter a valid email address.",
|
||||||
"error_not_configured": "Feedback is not available on this server."
|
"error_not_configured": "Feedback is not available on this server."
|
||||||
},
|
},
|
||||||
"demo": {
|
"demo": {
|
||||||
|
|||||||
@@ -1,15 +1,24 @@
|
|||||||
export type FeedbackCategory = 'bug' | 'feature' | 'general'
|
export type FeedbackCategory = 'bug' | 'feature' | 'general'
|
||||||
|
|
||||||
export class FeedbackApiError extends Error {
|
export class FeedbackApiError extends Error {
|
||||||
code: 'NOT_CONFIGURED' | 'REQUEST_FAILED'
|
code: 'NOT_CONFIGURED' | 'REQUEST_FAILED' | 'INVALID_EMAIL'
|
||||||
|
|
||||||
constructor(message: string, code: 'NOT_CONFIGURED' | 'REQUEST_FAILED' = 'REQUEST_FAILED') {
|
constructor(
|
||||||
|
message: string,
|
||||||
|
code: 'NOT_CONFIGURED' | 'REQUEST_FAILED' | 'INVALID_EMAIL' = 'REQUEST_FAILED'
|
||||||
|
) {
|
||||||
super(message)
|
super(message)
|
||||||
this.name = 'FeedbackApiError'
|
this.name = 'FeedbackApiError'
|
||||||
this.code = code
|
this.code = code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||||
|
|
||||||
|
export function isValidFeedbackEmail(email: string): boolean {
|
||||||
|
return EMAIL_PATTERN.test(email.trim())
|
||||||
|
}
|
||||||
|
|
||||||
function buildFeedbackHeaders(): Record<string, string> {
|
function buildFeedbackHeaders(): Record<string, string> {
|
||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@@ -22,15 +31,22 @@ function buildFeedbackHeaders(): Record<string, string> {
|
|||||||
export async function sendFeedback(payload: {
|
export async function sendFeedback(payload: {
|
||||||
category: FeedbackCategory
|
category: FeedbackCategory
|
||||||
message: string
|
message: string
|
||||||
|
contactEmail?: string | null
|
||||||
logbookId?: string | null
|
logbookId?: string | null
|
||||||
logbookTitle?: string | null
|
logbookTitle?: string | null
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
|
const contactEmail = payload.contactEmail?.trim()
|
||||||
|
if (contactEmail && !isValidFeedbackEmail(contactEmail)) {
|
||||||
|
throw new FeedbackApiError('Invalid email address', 'INVALID_EMAIL')
|
||||||
|
}
|
||||||
|
|
||||||
const res = await fetch('/api/feedback', {
|
const res = await fetch('/api/feedback', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: buildFeedbackHeaders(),
|
headers: buildFeedbackHeaders(),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
category: payload.category,
|
category: payload.category,
|
||||||
message: payload.message,
|
message: payload.message,
|
||||||
|
contactEmail: contactEmail || undefined,
|
||||||
username: localStorage.getItem('active_username') || undefined,
|
username: localStorage.getItem('active_username') || undefined,
|
||||||
logbookId: payload.logbookId || undefined,
|
logbookId: payload.logbookId || undefined,
|
||||||
logbookTitle: payload.logbookTitle || undefined,
|
logbookTitle: payload.logbookTitle || undefined,
|
||||||
|
|||||||
@@ -5,6 +5,20 @@ const router = Router()
|
|||||||
|
|
||||||
const VALID_CATEGORIES = new Set(['bug', 'feature', 'general'])
|
const VALID_CATEGORIES = new Set(['bug', 'feature', 'general'])
|
||||||
const MAX_MESSAGE_LENGTH = 2000
|
const MAX_MESSAGE_LENGTH = 2000
|
||||||
|
const MAX_EMAIL_LENGTH = 254
|
||||||
|
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||||
|
|
||||||
|
function parseOptionalEmail(value: unknown): string | undefined {
|
||||||
|
if (value === undefined || value === null || value === '') return undefined
|
||||||
|
if (typeof value !== 'string') return undefined
|
||||||
|
|
||||||
|
const trimmed = value.trim()
|
||||||
|
if (!trimmed) return undefined
|
||||||
|
if (trimmed.length > MAX_EMAIL_LENGTH) return undefined
|
||||||
|
if (!EMAIL_PATTERN.test(trimmed)) return undefined
|
||||||
|
|
||||||
|
return trimmed
|
||||||
|
}
|
||||||
|
|
||||||
const requireUser = (req: any, res: any, next: any) => {
|
const requireUser = (req: any, res: any, next: any) => {
|
||||||
const userId = req.headers['x-user-id']
|
const userId = req.headers['x-user-id']
|
||||||
@@ -25,7 +39,8 @@ router.post('/', requireUser, async (req: any, res) => {
|
|||||||
return res.status(503).json({ error: 'Feedback is not configured on this server' })
|
return res.status(503).json({ error: 'Feedback is not configured on this server' })
|
||||||
}
|
}
|
||||||
|
|
||||||
const { category, message, username, logbookId, logbookTitle, appVersion, pageUrl } = req.body ?? {}
|
const { category, message, username, contactEmail, logbookId, logbookTitle, appVersion, pageUrl } =
|
||||||
|
req.body ?? {}
|
||||||
|
|
||||||
if (typeof category !== 'string' || !VALID_CATEGORIES.has(category)) {
|
if (typeof category !== 'string' || !VALID_CATEGORIES.has(category)) {
|
||||||
return res.status(400).json({ error: 'Invalid category' })
|
return res.status(400).json({ error: 'Invalid category' })
|
||||||
@@ -40,10 +55,19 @@ router.post('/', requireUser, async (req: any, res) => {
|
|||||||
return res.status(400).json({ error: `Message must be at most ${MAX_MESSAGE_LENGTH} characters` })
|
return res.status(400).json({ error: `Message must be at most ${MAX_MESSAGE_LENGTH} characters` })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let parsedContactEmail: string | undefined
|
||||||
|
if (contactEmail !== undefined && contactEmail !== null && String(contactEmail).trim()) {
|
||||||
|
parsedContactEmail = parseOptionalEmail(contactEmail)
|
||||||
|
if (!parsedContactEmail) {
|
||||||
|
return res.status(400).json({ error: 'Invalid email address' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await sendFeedbackViaNtfy({
|
await sendFeedbackViaNtfy({
|
||||||
category,
|
category,
|
||||||
message: trimmedMessage,
|
message: trimmedMessage,
|
||||||
username: typeof username === 'string' ? username.trim() : undefined,
|
username: typeof username === 'string' ? username.trim() : undefined,
|
||||||
|
contactEmail: parsedContactEmail,
|
||||||
userId: req.userId,
|
userId: req.userId,
|
||||||
logbookId: typeof logbookId === 'string' ? logbookId.trim() : undefined,
|
logbookId: typeof logbookId === 'string' ? logbookId.trim() : undefined,
|
||||||
logbookTitle: typeof logbookTitle === 'string' ? logbookTitle.trim() : undefined,
|
logbookTitle: typeof logbookTitle === 'string' ? logbookTitle.trim() : undefined,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export interface FeedbackPayload {
|
|||||||
category: string
|
category: string
|
||||||
message: string
|
message: string
|
||||||
username?: string
|
username?: string
|
||||||
|
contactEmail?: string
|
||||||
userId: string
|
userId: string
|
||||||
logbookId?: string
|
logbookId?: string
|
||||||
logbookTitle?: string
|
logbookTitle?: string
|
||||||
@@ -40,6 +41,10 @@ export async function sendFeedbackViaNtfy(payload: FeedbackPayload): Promise<voi
|
|||||||
`User ID: ${payload.userId}`
|
`User ID: ${payload.userId}`
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if (payload.contactEmail) {
|
||||||
|
lines.push(`Contact: ${payload.contactEmail}`)
|
||||||
|
}
|
||||||
|
|
||||||
if (payload.logbookTitle || payload.logbookId) {
|
if (payload.logbookTitle || payload.logbookId) {
|
||||||
lines.push(`Logbook: ${payload.logbookTitle || payload.logbookId}`)
|
lines.push(`Logbook: ${payload.logbookTitle || payload.logbookId}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user