Add feedback button that creates GitHub issues

Users can submit bugs, suggestions, and questions directly from the app
via a dialog form. Submissions create issues in robbertj85/modelruimte
with appropriate labels. Button added to all three layouts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
robbertjanssen85
2026-02-18 18:43:06 +01:00
co-authored by Claude Opus 4.6
parent 93dd334e54
commit 24c17cafeb
9 changed files with 509 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
# GitHub personal access token for creating feedback issues
# Required scope: `public_repo` (for public repos) or `repo` (for private repos)
# Create one at: https://github.com/settings/tokens
GITHUB_TOKEN=
+1
View File
@@ -32,6 +32,7 @@ yarn-error.log*
# env files (can opt-in for committing if needed)
.env*
!.env.example
# vercel
.vercel
+79
View File
@@ -0,0 +1,79 @@
import { NextResponse } from 'next/server';
const FEEDBACK_TYPES = ['bug', 'suggestie', 'vraag'] as const;
type FeedbackType = (typeof FEEDBACK_TYPES)[number];
const LABEL_MAP: Record<FeedbackType, string> = {
bug: 'bug',
suggestie: 'enhancement',
vraag: 'question',
};
export async function POST(request: Request) {
try {
const body = await request.json();
const { title, description, type } = body;
// Validate required fields
if (!title || typeof title !== 'string' || title.trim().length === 0) {
return NextResponse.json({ error: 'Titel is verplicht.' }, { status: 400 });
}
if (title.length > 256) {
return NextResponse.json({ error: 'Titel mag maximaal 256 tekens zijn.' }, { status: 400 });
}
if (!description || typeof description !== 'string' || description.trim().length === 0) {
return NextResponse.json({ error: 'Beschrijving is verplicht.' }, { status: 400 });
}
if (description.length > 5000) {
return NextResponse.json({ error: 'Beschrijving mag maximaal 5000 tekens zijn.' }, { status: 400 });
}
if (!FEEDBACK_TYPES.includes(type)) {
return NextResponse.json({ error: 'Ongeldig feedbacktype.' }, { status: 400 });
}
const token = process.env.GITHUB_TOKEN;
if (!token) {
console.error('GITHUB_TOKEN is not configured');
return NextResponse.json({ error: 'Feedback service is niet geconfigureerd.' }, { status: 500 });
}
const label = LABEL_MAP[type as FeedbackType];
const typeLabel = type === 'bug' ? 'Bug' : type === 'suggestie' ? 'Suggestie' : 'Vraag';
const issueBody = `**Type:** ${typeLabel}\n\n${description.trim()}\n\n---\n_Ingediend via de Ruimtemodel webapp_`;
const response = await fetch('https://api.github.com/repos/robbertj85/modelruimte/issues', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
Accept: 'application/vnd.github+json',
'Content-Type': 'application/json',
'X-GitHub-Api-Version': '2022-11-28',
},
body: JSON.stringify({
title: title.trim(),
body: issueBody,
labels: [label],
}),
});
if (!response.ok) {
const errorData = await response.json().catch(() => null);
console.error('GitHub API error:', response.status, errorData);
return NextResponse.json(
{ error: 'Kon issue niet aanmaken op GitHub.' },
{ status: 502 }
);
}
const issue = await response.json();
return NextResponse.json({
success: true,
issueUrl: issue.html_url,
issueNumber: issue.number,
});
} catch {
console.error('Feedback route error');
return NextResponse.json({ error: 'Er ging iets mis.' }, { status: 500 });
}
}
+259
View File
@@ -0,0 +1,259 @@
'use client';
import { useState } from 'react';
import { MessageSquarePlus, Loader2, CheckCircle2, AlertCircle } from 'lucide-react';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
type FeedbackType = 'bug' | 'suggestie' | 'vraag';
type FormState = 'idle' | 'submitting' | 'success' | 'error';
interface FeedbackButtonProps {
variant: 'webapp' | 'dmi' | 'rebel';
}
export default function FeedbackButton({ variant }: FeedbackButtonProps) {
const [open, setOpen] = useState(false);
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [type, setType] = useState<FeedbackType>('bug');
const [formState, setFormState] = useState<FormState>('idle');
const [errorMessage, setErrorMessage] = useState('');
const [issueUrl, setIssueUrl] = useState('');
function resetForm() {
setTitle('');
setDescription('');
setType('bug');
setFormState('idle');
setErrorMessage('');
setIssueUrl('');
}
function handleOpenChange(nextOpen: boolean) {
setOpen(nextOpen);
if (!nextOpen) resetForm();
}
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
if (!title.trim() || !description.trim()) {
setFormState('error');
setErrorMessage('Vul alle velden in.');
return;
}
setFormState('submitting');
setErrorMessage('');
try {
const res = await fetch('/api/feedback', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title: title.trim(), description: description.trim(), type }),
});
const data = await res.json();
if (!res.ok) {
setFormState('error');
setErrorMessage(data.error || 'Er ging iets mis.');
return;
}
setFormState('success');
setIssueUrl(data.issueUrl);
} catch {
setFormState('error');
setErrorMessage('Kon geen verbinding maken met de server.');
}
}
// Variant-specific trigger button styles
const triggerButton = (() => {
switch (variant) {
case 'webapp':
return (
<Button variant="outline" size="sm">
<MessageSquarePlus size={16} />
Feedback
</Button>
);
case 'dmi':
return (
<button
style={{
display: 'flex',
alignItems: 'center',
gap: '6px',
padding: '6px 14px',
borderRadius: '6px',
border: '1px solid rgba(255,255,255,0.3)',
backgroundColor: 'transparent',
color: '#ffffff',
fontFamily: 'var(--font-ibm-plex-sans-condensed), sans-serif',
fontWeight: 600,
fontSize: '0.75rem',
cursor: 'pointer',
transition: 'all 0.2s ease',
}}
onMouseEnter={(e) => {
(e.currentTarget as HTMLButtonElement).style.backgroundColor = 'rgba(255,255,255,0.1)';
}}
onMouseLeave={(e) => {
(e.currentTarget as HTMLButtonElement).style.backgroundColor = 'transparent';
}}
>
<MessageSquarePlus size={14} />
Feedback
</button>
);
case 'rebel':
return (
<button
style={{
display: 'flex',
alignItems: 'center',
gap: '4px',
padding: '0 14px',
height: '100%',
backgroundColor: 'transparent',
color: '#cccccc',
border: 'none',
borderRight: '1px solid #666666',
fontSize: '0.7rem',
fontFamily: 'Calibri, Arial, sans-serif',
fontWeight: 400,
cursor: 'pointer',
transition: 'all 0.15s ease',
}}
onMouseEnter={(e) => {
(e.currentTarget as HTMLButtonElement).style.backgroundColor = 'rgba(255,255,255,0.05)';
}}
onMouseLeave={(e) => {
(e.currentTarget as HTMLButtonElement).style.backgroundColor = 'transparent';
}}
>
<MessageSquarePlus size={12} />
Feedback
</button>
);
}
})();
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogTrigger asChild>
{triggerButton}
</DialogTrigger>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>Feedback Geven</DialogTitle>
<DialogDescription>
Meld een bug, doe een suggestie, of stel een vraag.
</DialogDescription>
</DialogHeader>
{formState === 'success' ? (
<div className="flex flex-col items-center gap-3 py-4">
<CheckCircle2 className="size-10 text-green-600" />
<p className="text-sm font-medium">Bedankt voor je feedback!</p>
{issueUrl && (
<a
href={issueUrl}
target="_blank"
rel="noopener noreferrer"
className="text-sm text-primary underline underline-offset-4"
>
Bekijk issue op GitHub
</a>
)}
<Button variant="outline" size="sm" onClick={() => handleOpenChange(false)} className="mt-2">
Sluiten
</Button>
</div>
) : (
<form onSubmit={handleSubmit} className="grid gap-4">
<div className="grid gap-2">
<Label htmlFor="feedback-type">Type</Label>
<Select value={type} onValueChange={(v) => setType(v as FeedbackType)}>
<SelectTrigger id="feedback-type">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="bug">Bug</SelectItem>
<SelectItem value="suggestie">Suggestie</SelectItem>
<SelectItem value="vraag">Vraag</SelectItem>
</SelectContent>
</Select>
</div>
<div className="grid gap-2">
<Label htmlFor="feedback-title">Titel</Label>
<Input
id="feedback-title"
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="Korte omschrijving"
maxLength={256}
disabled={formState === 'submitting'}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="feedback-description">Beschrijving</Label>
<Textarea
id="feedback-description"
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="Geef zoveel mogelijk detail..."
maxLength={5000}
rows={4}
disabled={formState === 'submitting'}
/>
</div>
{formState === 'error' && errorMessage && (
<div className="flex items-center gap-2 rounded-md border border-destructive/50 bg-destructive/10 px-3 py-2 text-sm text-destructive">
<AlertCircle className="size-4 shrink-0" />
{errorMessage}
</div>
)}
<DialogFooter>
<Button type="submit" disabled={formState === 'submitting'}>
{formState === 'submitting' ? (
<>
<Loader2 className="animate-spin" />
Verzenden...
</>
) : (
'Verzenden'
)}
</Button>
</DialogFooter>
</form>
)}
</DialogContent>
</Dialog>
);
}
@@ -22,6 +22,7 @@ import { COVER, HANDLEIDING_SECTIONS, PARTNER_SECTIONS, CONTACT, CASUS_GERARD_DO
import { HandleidingDiagram } from '@/components/HandleidingDiagrams';
import { HandleidingTableRenderer } from '@/components/HandleidingTable';
import LayoutSwitcher from '@/components/LayoutSwitcher';
import FeedbackButton from '@/components/FeedbackButton';
import { AlgemeenEditor, DeliveryProfileEditor } from '@/components/ParameterEditor';
import {
DMI,
@@ -350,6 +351,7 @@ export default function DmiCockpitLayout({
{!isMobile && (
<div style={{ display: 'flex', alignItems: 'center', gap: '16px' }}>
<FeedbackButton variant="dmi" />
<LayoutSwitcher current={layout} onChange={onLayoutChange} />
<Image
src="/dmi-logo-diap.png"
@@ -8,6 +8,7 @@ import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as RechartsTooltip,
import { Loader2, Play } from 'lucide-react';
import { Slider } from '@/components/ui/slider';
import LayoutSwitcher from '@/components/LayoutSwitcher';
import FeedbackButton from '@/components/FeedbackButton';
import { useIsMobile } from '@/lib/useIsMobile';
import { COVER, HANDLEIDING_SECTIONS, PARTNER_SECTIONS, CONTACT, CASUS_GERARD_DOUSTRAAT, renderBold } from '@/lib/content';
import { HandleidingDiagram } from '@/components/HandleidingDiagrams';
@@ -2155,6 +2156,8 @@ export default function RebelExcelLayout({
})}
{/* Filler space after tabs */}
<div style={{ flex: 1 }} />
{/* Feedback button */}
<FeedbackButton variant="rebel" />
{/* Rebel branding in tab bar */}
<div
style={{
+2
View File
@@ -9,6 +9,7 @@ import { Loader2, Play, LayoutDashboard, ClipboardList, Network, BarChart3, Chev
import { Slider } from '@/components/ui/slider';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import LayoutSwitcher from '@/components/LayoutSwitcher';
import FeedbackButton from '@/components/FeedbackButton';
import { useIsMobile } from '@/lib/useIsMobile';
import { COVER, HANDLEIDING_SECTIONS, PARTNER_SECTIONS, CONTACT, CASUS_GERARD_DOUSTRAAT, renderBold } from '@/lib/content';
import { HandleidingDiagram } from '@/components/HandleidingDiagrams';
@@ -302,6 +303,7 @@ export default function WebappLayout({
{state.isRunning ? <Loader2 size={16} className="animate-spin" /> : <Play size={16} />}
{state.isRunning ? 'Bezig...' : 'Run Simulaties'}
</button>
<FeedbackButton variant="webapp" />
<LayoutSwitcher current={layout} onChange={onLayoutChange} />
</div>
)}
+141
View File
@@ -0,0 +1,141 @@
"use client"
import * as React from "react"
import { Dialog as DialogPrimitive } from "radix-ui"
import { XIcon } from "lucide-react"
import { cn } from "@/lib/utils"
function Dialog({
...props
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />
}
function DialogTrigger({
...props
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
}
function DialogPortal({
...props
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
}
function DialogClose({
...props
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
}
function DialogOverlay({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
return (
<DialogPrimitive.Overlay
data-slot="dialog-overlay"
className={cn(
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
className
)}
{...props}
/>
)
}
function DialogContent({
className,
children,
...props
}: React.ComponentProps<typeof DialogPrimitive.Content>) {
return (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
data-slot="dialog-content"
className={cn(
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4">
<XIcon />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
)
}
function DialogHeader({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-header"
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
{...props}
/>
)
}
function DialogFooter({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-footer"
className={cn(
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
className
)}
{...props}
/>
)
}
function DialogTitle({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
return (
<DialogPrimitive.Title
data-slot="dialog-title"
className={cn("text-lg leading-none font-semibold", className)}
{...props}
/>
)
}
function DialogDescription({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
return (
<DialogPrimitive.Description
data-slot="dialog-description"
className={cn("text-muted-foreground text-sm", className)}
{...props}
/>
)
}
export {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
}
+18
View File
@@ -0,0 +1,18 @@
import * as React from "react"
import { cn } from "@/lib/utils"
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
return (
<textarea
data-slot="textarea"
className={cn(
"border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
className
)}
{...props}
/>
)
}
export { Textarea }