mirror of
https://github.com/R0m1k3/Regisflow.git
synced 2026-10-14 18:57:29 +02:00
Improve photo capture process with error handling and browser support
Implement enhanced camera access with browser compatibility checks and error handling in useSimpleCamera hook and NewSaleFormMulti component. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 4b008663-bd72-492b-b0b6-fa252367e730 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/4b008663-bd72-492b-b0b6-fa252367e730/N4gXSMv
This commit is contained in:
1 parent
4254ebf94a
commit
ba643b557a
3 files changed
+124
-9
No files matched your search
@@ -137,7 +137,84 @@ export default function NewSaleFormMulti() {
|
||||
};
|
||||
|
||||
const handlePhotoCapture = async (photoType: PhotoType) => {
|
||||
await startCamera(photoType);
|
||||
console.log('=== PHOTO CAPTURE REQUESTED ===');
|
||||
console.log('Photo type:', photoType);
|
||||
|
||||
// Vérifications préliminaires
|
||||
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
||||
toast({
|
||||
title: "Navigateur non compatible",
|
||||
description: "Votre navigateur ne supporte pas la capture photo. Utilisez Chrome, Firefox ou Safari récent.",
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Vérifier si nous sommes en HTTPS (requis par certains navigateurs)
|
||||
if (location.protocol !== 'https:' && location.hostname !== 'localhost') {
|
||||
toast({
|
||||
title: "Connexion sécurisée requise",
|
||||
description: "L'accès à la caméra nécessite une connexion HTTPS.",
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('Attempting to start camera...');
|
||||
|
||||
// Afficher toast de démarrage
|
||||
toast({
|
||||
title: "Démarrage de la caméra",
|
||||
description: "Préparation de la caméra en cours...",
|
||||
});
|
||||
|
||||
// Démarrer la caméra simple
|
||||
await startCamera(photoType);
|
||||
console.log('Simple camera started successfully');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Camera start failed:', error);
|
||||
toast({
|
||||
title: "Erreur d'accès à la caméra",
|
||||
description: error instanceof Error ? error.message : "Impossible d'accéder à la caméra",
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleCapturePhoto = async () => {
|
||||
if (!currentPhotoType) return;
|
||||
|
||||
try {
|
||||
console.log('Attempting to capture photo...');
|
||||
const photoData = await capturePhoto();
|
||||
console.log('Photo captured successfully, data length:', photoData.length);
|
||||
|
||||
if (currentPhotoType === 'recto') {
|
||||
form.setValue('photoRecto', photoData);
|
||||
} else if (currentPhotoType === 'verso') {
|
||||
form.setValue('photoVerso', photoData);
|
||||
} else if (currentPhotoType === 'ticket') {
|
||||
form.setValue('photoTicket', photoData);
|
||||
}
|
||||
|
||||
toast({
|
||||
title: "Photo capturée",
|
||||
description: `Photo ${currentPhotoType} enregistrée avec succès`,
|
||||
variant: "success",
|
||||
});
|
||||
|
||||
stopCamera();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Photo capture failed:', error);
|
||||
toast({
|
||||
title: "Erreur de capture",
|
||||
description: error instanceof Error ? error.message : "Impossible de capturer la photo",
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemovePhoto = (photoType: PhotoType) => {
|
||||
@@ -188,7 +265,7 @@ export default function NewSaleFormMulti() {
|
||||
canvasRef={canvasRef}
|
||||
isCapturing={isCapturing}
|
||||
onClose={stopCamera}
|
||||
onCapture={capturePhoto}
|
||||
onCapture={handleCapturePhoto}
|
||||
/>
|
||||
|
||||
<Form {...form}>
|
||||
|
||||
Reference in new issue
Block a user