import React, { useState, useContext } from "react"; import { Card, Box, Button, FormControl, Grid, InputLabel, OutlinedInput, Stack, Typography, FormHelperText, } from "@mui/material"; import backgroundImage from "../assets/images/background_dot.png"; import { ThemeColors } from "../utility/context/ThemeColors.js"; import { useHistory } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { useSnackbar } from "notistack"; import ApplicationService from "../services/ApplicationService.js"; const VerifyAndAccessSurvey = () => { const history = useHistory(); const { t } = useTranslation(); const { enqueueSnackbar } = useSnackbar(); const [error, setError] = useState({ email: "", }); const [sendList, setSendList] = useState({ email: "", tc: "", surveyLink: "", }); const { colors } = useContext(ThemeColors); const isEmail = (email) => /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]/i.test(email); const currentURL = window.location.href; const onSendSurveyVerificationModalButtonPressed = async (e) => { e.preventDefault(); if (!isEmail(sendList?.email) || sendList?.email === "") { setError({ email: t("PasswordLabel.enterEmail"), }); } else { await ApplicationService.http() .post( "/graphql", { query: ` mutation { verifyAndAccessSurvey( participant_email: "${sendList?.email}", participant_id: "${sendList?.tc}", hashedLink: "${currentURL}", ) } `, }, { headers: { Authorization: "Bearer " + localStorage.getItem("accessToken"), }, } ) .then((response) => { if (response.data?.errors) { enqueueSnackbar("Doğrulama başarısız." + t("Warnings.notFound"), { variant: "error", preventDuplicate: true, }); } else { enqueueSnackbar("Doğrulama başarılı.", { variant: "success", preventDuplicate: true, }); const response1 = response.data.data.verifyAndAccessSurvey.split("redirect:"); const redirectUrl = response1[1].trim(); if (redirectUrl) { history.push(redirectUrl); } else { console.error("Invalid redirect URL."); } } }); } }; const renderVerify = () => { return ( *": { flexGrow: 1, flexBasis: "50%", }, }} content="false" > {"Anket Doğrulama"} {/* {t("PasswordLabel.enterEmail")} */}
Email setSendList({ ...sendList, email: e.target.value, }) } label="Email" /> Anket Kodu setSendList({ ...sendList, tc: e.target.value, }) } label="tc" /> {error?.email && ( {error.email} )}
); }; return ( {renderVerify()} ); }; export default VerifyAndAccessSurvey;