import { useTest } from "@/api/tests";
import { useStartTestMutation } from "@/api/userTests";
import Question from "@/components/question";
import Test from "@/components/test";
import { ButtonText } from "@/components/ui/button";
import Content from "@/components/ui/content";
import CustomButton from "@/components/ui/custom-button";
import getErrorAxiosMessage from "@/utils/get-error-axios-message";
import { router, Stack, useLocalSearchParams } from "expo-router";
import { View } from "react-native";
import { useToast } from "react-native-toast-notifications";
const TestScreen = () => {
const { id: idParam } = useLocalSearchParams<{ id: string }>();
const id = +idParam;
const { data, isLoading } = useTest(id);
const { mutate, isPending } = useStartTestMutation();
const toast = useToast();
if (!data)
return (
<>
{isLoading && }
>
);
const handleStartTest = () => {
mutate(
{
test_id: data.id,
},
{
onSuccess: (data) => {
router.push(`/user-tests/doing/${data.id}`);
},
onError: (error) => {
toast.show(getErrorAxiosMessage(error), { type: "danger" });
},
}
);
};
return (
<>
{data.is_available && (
Start Test
)}
{data.questions?.map((question) => (
router.push(`/questions/${question.id}`)} />
))}
>
);
};
export default TestScreen;