From 36c726f7134759dff7255ce5fbc902a9ba1b2248 Mon Sep 17 00:00:00 2001 From: Mohan Ki Date: Mon, 27 Jul 2026 17:17:36 +0530 Subject: [PATCH] feat: add static vs dynamic QR code toggle to the create page --- client/src/app/dashboard/create/page.tsx | 87 ++++++++++++++++++------ 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/client/src/app/dashboard/create/page.tsx b/client/src/app/dashboard/create/page.tsx index 5c253b3..d0759ee 100644 --- a/client/src/app/dashboard/create/page.tsx +++ b/client/src/app/dashboard/create/page.tsx @@ -11,6 +11,7 @@ export default function CreateQRPage() { const router = useRouter(); const [destinationUrl, setDestinationUrl] = useState('https://ck-qr.com'); const [qrName, setQrName] = useState(''); + const [qrType, setQrType] = useState<'dynamic' | 'static'>('dynamic'); const [customSlug, setCustomSlug] = useState(''); const [randomSlug, setRandomSlug] = useState(''); const [isGenerating, setIsGenerating] = useState(false); @@ -49,9 +50,22 @@ export default function CreateQRPage() { React.useEffect(() => { const generated = Math.random().toString(36).substring(2, 8); setRandomSlug(generated); - setQrOptions(prev => ({ ...prev, data: `${baseUrl}/l/${generated}` })); + if (qrType === 'dynamic') { + setQrOptions(prev => ({ ...prev, data: `${baseUrl}/l/${generated}` })); + } else { + setQrOptions(prev => ({ ...prev, data: destinationUrl })); + } }, [baseUrl]); + // Keep QR data in sync with type and destinationUrl + React.useEffect(() => { + if (qrType === 'static') { + setQrOptions(prev => ({ ...prev, data: destinationUrl })); + } else { + setQrOptions(prev => ({ ...prev, data: `${baseUrl}/l/${customSlug || randomSlug}` })); + } + }, [qrType, destinationUrl]); + // Keep QR data in sync with custom slug const handleSlugChange = (e: React.ChangeEvent) => { const val = e.target.value.replace(/[^a-zA-Z0-9-_]/g, ''); @@ -65,8 +79,8 @@ export default function CreateQRPage() { // Generate Dynamic QR via API const response = await api.post('/qr/generate', { name: qrName, - customSlug: customSlug || randomSlug, // Pass the previewed slug so the backend uses it! - type: 'dynamic', + customSlug: qrType === 'dynamic' ? (customSlug || randomSlug) : undefined, // Pass the previewed slug so the backend uses it! + type: qrType, dataType: 'URL', destinationUrl: destinationUrl, designData: qrOptions @@ -134,6 +148,34 @@ export default function CreateQRPage() {

QR Content

+
+ +
+ + +
+
+
-

This is a dynamic QR. You can change this URL later without reprinting the code.

+ {qrType === 'dynamic' && ( +

This is a dynamic QR. You can change this URL later without reprinting the code.

+ )} + {qrType === 'static' && ( +

This URL is embedded directly into the code and cannot be changed later.

+ )}
-
- -
- - {(process.env.NEXT_PUBLIC_APP_URL || 'https://qr.houseofwebsites.ai').replace(/^https?:\/\//, '')}/l/ - - + {qrType === 'dynamic' && ( +
+ +
+ + {(process.env.NEXT_PUBLIC_APP_URL || 'https://qr.houseofwebsites.ai').replace(/^https?:\/\//, '')}/l/ + + +
+

Leave blank to auto-generate a random link.

-

Leave blank to auto-generate a random link.

-
+ )}