Validation error

This commit is contained in:
Timo Knuth
2026-04-17 09:16:07 +02:00
parent c3efe8ceb9
commit 1bb782467b
4 changed files with 35 additions and 16 deletions

View File

@@ -173,7 +173,7 @@ export default function CreatePage() {
case 'FEEDBACK': case 'FEEDBACK':
return content.feedbackUrl || 'https://example.com/feedback'; return content.feedbackUrl || 'https://example.com/feedback';
case 'BARCODE': case 'BARCODE':
return content.value || '123456789'; return content.value || '';
default: default:
return 'https://example.com'; return 'https://example.com';
} }
@@ -1062,6 +1062,7 @@ export default function CreatePage() {
qrContent ? ( qrContent ? (
<div className="p-2 bg-white"> <div className="p-2 bg-white">
<Barcode <Barcode
key={`${qrContent}-${content.format}-${foregroundColor}`}
value={qrContent} value={qrContent}
format={content.format || 'CODE128'} format={content.format || 'CODE128'}
lineColor={foregroundColor} lineColor={foregroundColor}

View File

@@ -190,6 +190,9 @@ END:VCARD`;
case 'FEEDBACK': case 'FEEDBACK':
qrContent = body.content.feedbackUrl || 'https://example.com/feedback'; qrContent = body.content.feedbackUrl || 'https://example.com/feedback';
break; break;
case 'BARCODE':
qrContent = body.content.value || '123456789';
break;
default: default:
qrContent = body.content.url || 'https://example.com'; qrContent = body.content.url || 'https://example.com';
} }

View File

@@ -2,6 +2,7 @@
import React from 'react'; import React from 'react';
import { QRCodeSVG } from 'qrcode.react'; import { QRCodeSVG } from 'qrcode.react';
import Barcode from 'react-barcode';
import { Card, CardContent } from '@/components/ui/Card'; import { Card, CardContent } from '@/components/ui/Card';
import { Badge } from '@/components/ui/Badge'; import { Badge } from '@/components/ui/Badge';
import { Dropdown, DropdownItem } from '@/components/ui/Dropdown'; import { Dropdown, DropdownItem } from '@/components/ui/Dropdown';
@@ -208,19 +209,33 @@ END:VCARD`;
</div> </div>
)} )}
<div id={`qr-svg-${qr.id}`} className={qr.style?.cornerStyle === 'rounded' ? 'rounded-lg overflow-hidden' : ''}> <div id={`qr-svg-${qr.id}`} className={qr.style?.cornerStyle === 'rounded' ? 'rounded-lg overflow-hidden' : ''}>
<QRCodeSVG {qr.contentType === 'BARCODE' && qr.type === 'STATIC' ? (
value={qrUrl} <Barcode
size={96} key={`${qr.content?.value}-${qr.content?.format}`}
fgColor={qr.style?.foregroundColor || '#000000'} value={qr.content?.value || '123456789'}
bgColor={qr.style?.backgroundColor || '#FFFFFF'} format={(qr.content?.format as any) || 'CODE128'}
level="H" lineColor={qr.style?.foregroundColor || '#000000'}
imageSettings={qr.style?.imageSettings ? { background={qr.style?.backgroundColor || '#FFFFFF'}
src: qr.style.imageSettings.src, width={1.5}
height: qr.style.imageSettings.height * (96 / 200), // Scale logo for smaller QR height={60}
width: qr.style.imageSettings.width * (96 / 200), displayValue={true}
excavate: qr.style.imageSettings.excavate, fontSize={10}
} : undefined} />
/> ) : (
<QRCodeSVG
value={qrUrl}
size={96}
fgColor={qr.style?.foregroundColor || '#000000'}
bgColor={qr.style?.backgroundColor || '#FFFFFF'}
level="H"
imageSettings={qr.style?.imageSettings ? {
src: qr.style.imageSettings.src,
height: qr.style.imageSettings.height * (96 / 200),
width: qr.style.imageSettings.width * (96 / 200),
excavate: qr.style.imageSettings.excavate,
} : undefined}
/>
)}
</div> </div>
</div> </div>
</div> </div>

View File

@@ -25,7 +25,7 @@ export const createQRSchema = z.object({
isStatic: z.boolean().optional(), isStatic: z.boolean().optional(),
contentType: z.enum(['URL', 'VCARD', 'GEO', 'PHONE', 'SMS', 'WHATSAPP', 'TEXT', 'PDF', 'APP', 'COUPON', 'FEEDBACK'], { contentType: z.enum(['URL', 'VCARD', 'GEO', 'PHONE', 'SMS', 'WHATSAPP', 'TEXT', 'PDF', 'APP', 'COUPON', 'FEEDBACK', 'BARCODE'], {
errorMap: () => ({ message: 'Invalid content type' }) errorMap: () => ({ message: 'Invalid content type' })
}), }),
@@ -60,7 +60,7 @@ export const bulkQRSchema = z.object({
z.object({ z.object({
title: z.string().min(1).max(100), title: z.string().min(1).max(100),
content: z.string().min(1).max(5000), content: z.string().min(1).max(5000),
contentType: z.enum(['URL', 'VCARD', 'GEO', 'PHONE', 'SMS', 'WHATSAPP', 'TEXT', 'PDF', 'APP', 'COUPON', 'FEEDBACK']), contentType: z.enum(['URL', 'VCARD', 'GEO', 'PHONE', 'SMS', 'WHATSAPP', 'TEXT', 'PDF', 'APP', 'COUPON', 'FEEDBACK', 'BARCODE']),
}) })
).min(1, 'At least one QR code is required') ).min(1, 'At least one QR code is required')
.max(100, 'Maximum 100 QR codes per bulk creation'), .max(100, 'Maximum 100 QR codes per bulk creation'),