"use client"; import QuizContext from "@/context/QuizContext"; import { useQuizSearchActive } from "@/store/store"; import { AnimatePresence, motion } from "framer-motion"; import { ChangeEvent, FormEvent, useContext, useState } from "react"; const QuizSearch = ({ quizId }: { quizId: number }) => { const [phone, setPhone] = useState(""); const { setActive } = useQuizSearchActive(); const { setSearchActive } = useContext(QuizContext).quizSearchActiveContext; const { setQuizSearchData } = useContext(QuizContext).quizSearchContext; const handleCleanSearch = () => { setQuizSearchData(undefined); setPhone(""); setSearchActive(false); setActive(false); }; const handleSearchChange = (event: ChangeEvent) => { setPhone(event.target.value.trim()); }; const handleKeyPress = (event: React.KeyboardEvent) => { if (event.key === "Enter") { // Prevent the default form submission behavior event.preventDefault(); // Call the function to handle the form submission handleSearchSubmit; } }; const handleSearchSubmit = async ( event: React.FormEvent ) => { event.preventDefault(); try { const response = await fetch( `https://sms.turkmentv.gov.tm/api/quiz/${quizId}/search`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ phone }), } ); // Handle the response as needed const data = await response.json(); setQuizSearchData(data); setSearchActive(true); setActive(true); } catch (error) {} }; return (

Öz jogaplaryňyzy görüň

{" "} {phone.length != 0 ? ( ) : null}

Her soragyň aşagynda siziň ugradan jogaplaryňyz görkeziler{" "}

); }; export default QuizSearch;