Spaces:
Sleeping
Sleeping
File size: 5,745 Bytes
9a9d08c 73d7d71 9a9d08c 5e0990b 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 743fc77 5e0990b 9a9d08c e7ef90f 9a9d08c 743fc77 9a9d08c 5e0990b 9a9d08c 5e0990b 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c 73d7d71 9a9d08c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
import { useState } from "react";
import { motion } from "framer-motion";
import BoxContainer from "./components/BoxContainer";
import VideoWrapper from "@/components/VideoWrapper.tsx";
import ResultContainer from "@/components/ResultContainer.tsx";
import DarkVideoWrapper from "@/components/DarkVideoWrapper.tsx";
export type fetchResult = "Valid" | "Not Valid" | "Fetching" | "Error";
enum StepType {
takeId,
verifyId,
takeFrontPic,
verifyProfile,
result,
}
const stepsArray: StepType[] = [
StepType.takeId,
StepType.verifyId,
StepType.takeFrontPic,
StepType.verifyProfile,
StepType.result,
];
export default function VerificationScene() {
const [currentStep, setCurrentStep] = useState<StepType>(StepType.takeId);
const [idCardPicture, setIdCardPicture] = useState<string>();
const [profilePicture, setProfilePicture] = useState<string>();
const handleNextStep = () => {
if (currentStep === StepType.result) return;
setCurrentStep((currentStep + 1) % stepsArray.length);
};
const handlePrevStep = () => {
if (currentStep === StepType.takeId) return;
setCurrentStep((currentStep - 1) % stepsArray.length);
};
const sendImageToServer = async (
idCard: string,
profileImage: string,
setLoading: (n: fetchResult) => void,
) => {
try {
const response = await fetch("https://0.0.0.0:7860/uploadids", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ idCard: idCard, profileImage: profileImage }),
});
if (!response.ok) {
throw new Error("Erreur lors de l'envoi de l'image");
}
const data = await response.json();
console.log("Image envoyée avec succès:", data);
setLoading(data.message === "Valid" ? "Valid" : "Not Valid");
} catch (error) {
console.error("Erreur:", error);
setLoading("Error");
}
};
// Animation settings for Framer Motion
const animationProps = {
initial: { opacity: 0, y: 50 },
animate: { opacity: 1, y: 0 },
exit: { opacity: 0, y: -50 },
transition: { duration: 0.5 },
};
let stepContent = undefined;
if (currentStep === StepType.takeId) {
stepContent = (
<motion.div
key="takeId"
{...animationProps}
className="flex flex-col items-center"
>
<h1 className="text-black text-2xl mt-20 text-center px-28">
Take a picture of the Capture the front side of your ID Card
</h1>
<VideoWrapper
handleNextStep={handleNextStep}
setImage={setIdCardPicture}
className="shadow-lg mt-20"
height="250px"
width="400px"
/>
</motion.div>
);
}
if (currentStep === StepType.verifyId) {
stepContent = (
<motion.div
key="verifyId"
{...animationProps}
className="flex flex-col items-center"
>
<div className="overflow-hidden w-2/3 h-2/4 mt-10">
<img src={idCardPicture} alt="captured" />
</div>
<h1 className="text-2xl font-bold mt-10">Is This Picture Correct?</h1>
<div className="mt-32 space-x-20">
<button
onClick={handlePrevStep}
className="bg-red-600 transition text-white rounded-2xl text-xl hover:bg-red-800 w-40 h-16"
>
No
</button>
<button
onClick={handleNextStep}
className="bg-blue-600 transition text-white rounded-2xl text-xl hover:bg-gray-800 w-40 h-16"
>
Yes
</button>
</div>
</motion.div>
);
}
if (currentStep === StepType.takeFrontPic) {
stepContent = (
<motion.div
key="takeFrontPic"
{...animationProps}
className="flex flex-col items-center"
>
<h1 className="mt-5 font-bold text-lg">Center your face</h1>
<DarkVideoWrapper
setImage={setProfilePicture}
className="mt-12 w-3/4 h-3/5 overflow-hidden"
handleNextStep={handleNextStep}
/>
</motion.div>
);
}
if (currentStep === StepType.verifyProfile) {
stepContent = (
<motion.div
key="verifyProfile"
{...animationProps}
className="flex flex-col items-center"
>
<div className="overflow-hidden w-2/3 h-2/4 mt-10">
<img src={profilePicture} alt="captured" />
</div>
<h1 className="text-2xl font-bold mt-10">Is This Picture Correct?</h1>
<div className="mt-32 space-x-20">
<button
onClick={handlePrevStep}
className="bg-red-600 transition text-white rounded-2xl text-xl hover:bg-red-800 w-40 h-16"
>
No
</button>
<button
onClick={handleNextStep}
className="bg-blue-600 transition text-white rounded-2xl text-xl hover:bg-gray-800 w-40 h-16"
>
Yes (Submit)
</button>
</div>
</motion.div>
);
}
if (currentStep === StepType.result) {
stepContent = (
<motion.div
key="result"
{...animationProps}
className="flex flex-col items-center"
>
<ResultContainer
sendImageToServer={sendImageToServer}
idCardPicture={idCardPicture ?? ""}
profileImage={profilePicture ?? ""}
/>
</motion.div>
);
}
return (
<>
<div className="bg-gray-100">
<BoxContainer headerName="Identity Verification Required">
<div className="h-full w-full flex flex-col items-center justify-center overflow-hidden">
{stepContent}
</div>
</BoxContainer>
</div>
</>
);
}
|