[MCH-FE] feat: Implement real QR code generation in CodiQR
- Added qrcode.react v4.2.0 dependency - Replaced visual placeholder with QRCodeSVG component - QR displays actual transaction qrData from backend - Added qrData state to capture API response - Configured QR with error correction level M and white margin Resolves: TASK-2026-01-20-003 audit P2 gap Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b20d5d7ee7
commit
88d7bcaa95
10
package-lock.json
generated
10
package-lock.json
generated
@ -14,6 +14,7 @@
|
|||||||
"i18next": "^25.7.4",
|
"i18next": "^25.7.4",
|
||||||
"i18next-browser-languagedetector": "^8.2.0",
|
"i18next-browser-languagedetector": "^8.2.0",
|
||||||
"lucide-react": "^0.562.0",
|
"lucide-react": "^0.562.0",
|
||||||
|
"qrcode.react": "^4.2.0",
|
||||||
"react": "^19.2.0",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.0",
|
"react-dom": "^19.2.0",
|
||||||
"react-i18next": "^16.5.3",
|
"react-i18next": "^16.5.3",
|
||||||
@ -6737,6 +6738,15 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/qrcode.react": {
|
||||||
|
"version": "4.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/qrcode.react/-/qrcode.react-4.2.0.tgz",
|
||||||
|
"integrity": "sha512-QpgqWi8rD9DsS9EP3z7BT+5lY5SFhsqGjpgW5DY/i3mK4M9DTBNz3ErMi8BWYEfI3L0d8GIbGmcdFAS1uIRGjA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/randombytes": {
|
"node_modules/randombytes": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
"i18next": "^25.7.4",
|
"i18next": "^25.7.4",
|
||||||
"i18next-browser-languagedetector": "^8.2.0",
|
"i18next-browser-languagedetector": "^8.2.0",
|
||||||
"lucide-react": "^0.562.0",
|
"lucide-react": "^0.562.0",
|
||||||
|
"qrcode.react": "^4.2.0",
|
||||||
"react": "^19.2.0",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.0",
|
"react-dom": "^19.2.0",
|
||||||
"react-i18next": "^16.5.3",
|
"react-i18next": "^16.5.3",
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||||
import { QrCode, Clock, Check, X, RefreshCw } from 'lucide-react';
|
import { QRCodeSVG } from 'qrcode.react';
|
||||||
|
import { Clock, Check, X, RefreshCw } from 'lucide-react';
|
||||||
import { codiSpeiApi } from '../../lib/api';
|
import { codiSpeiApi } from '../../lib/api';
|
||||||
|
|
||||||
interface CodiQRProps {
|
interface CodiQRProps {
|
||||||
@ -13,12 +14,14 @@ interface CodiQRProps {
|
|||||||
|
|
||||||
export function CodiQR({ amount, description, saleId, onSuccess, onCancel }: CodiQRProps) {
|
export function CodiQR({ amount, description, saleId, onSuccess, onCancel }: CodiQRProps) {
|
||||||
const [transactionId, setTransactionId] = useState<string | null>(null);
|
const [transactionId, setTransactionId] = useState<string | null>(null);
|
||||||
|
const [qrData, setQrData] = useState<string | null>(null);
|
||||||
const [timeLeft, setTimeLeft] = useState<number>(300); // 5 minutes in seconds
|
const [timeLeft, setTimeLeft] = useState<number>(300); // 5 minutes in seconds
|
||||||
|
|
||||||
const generateMutation = useMutation({
|
const generateMutation = useMutation({
|
||||||
mutationFn: () => codiSpeiApi.generateQr({ amount, description, saleId }),
|
mutationFn: () => codiSpeiApi.generateQr({ amount, description, saleId }),
|
||||||
onSuccess: (res) => {
|
onSuccess: (res) => {
|
||||||
setTransactionId(res.data.id);
|
setTransactionId(res.data.id);
|
||||||
|
setQrData(res.data.qrData);
|
||||||
setTimeLeft(300);
|
setTimeLeft(300);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -119,12 +122,16 @@ export function CodiQR({ amount, description, saleId, onSuccess, onCancel }: Cod
|
|||||||
|
|
||||||
{/* QR Code Display */}
|
{/* QR Code Display */}
|
||||||
<div className="bg-white p-4 rounded-xl shadow-lg mb-4">
|
<div className="bg-white p-4 rounded-xl shadow-lg mb-4">
|
||||||
<div className="w-48 h-48 bg-gray-100 rounded-lg flex items-center justify-center">
|
<div className="flex flex-col items-center justify-center">
|
||||||
{/* In production, generate actual QR code from qrData */}
|
<QRCodeSVG
|
||||||
<div className="text-center">
|
value={qrData || transactionId || ''}
|
||||||
<QrCode className="h-32 w-32 text-gray-800 mx-auto" />
|
size={200}
|
||||||
<p className="text-xs text-gray-400 mt-2">Escanea con tu app bancaria</p>
|
level="M"
|
||||||
</div>
|
includeMargin={true}
|
||||||
|
bgColor="#ffffff"
|
||||||
|
fgColor="#1f2937"
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-gray-400 mt-2">Escanea con tu app bancaria</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user