From 812c00b2d07c6dfaa6762fecf04e989c07d74068 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Sep 2024 17:31:52 +0530 Subject: [PATCH 1/2] routes fixed --- src/features/default/src/Layout/Participant.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/features/default/src/Layout/Participant.js b/src/features/default/src/Layout/Participant.js index 8241cce9..31d0ce9f 100644 --- a/src/features/default/src/Layout/Participant.js +++ b/src/features/default/src/Layout/Participant.js @@ -84,6 +84,7 @@ const SupportView = lazy(() => import("../Components/Support_New/SupportView")); const DashboardNew = lazy(() => import("../Views/Dashboard/DashboardNew")); const StreamlitFrame = lazy(() => import("../Views/Pages/Dashboard/streamlit")); const TempFile = lazy(() => import("../Views/GuestUser/TempFarmerFile")); +const DaFile = lazy(() => import("../Views/GuestUser/TempDaRegistryFile")); const Resources = lazy(() => import("../Views/Resources/Resources")); const AddResource = lazy(() => import("../Views/Resources/AddResource")); const EditResource = lazy(() => import("../Views/Resources/EditResource")); @@ -296,9 +297,20 @@ function Participant(props) { /> { + const { name } = props.match.params; + + if (name === "farmer_registry_dashboard") { + return ; + } else if (name === "da_registry_dashboard") { + return ; + } else { + return ; + } + }} /> + Date: Fri, 13 Sep 2024 14:28:42 +0530 Subject: [PATCH 2/2] password initial feature --- .../Components/NewOnboarding/VerifyEmail.jsx | 186 ++++---- .../NewOnboarding/VerifyEmaildummy.jsx | 423 ++++++++++++++++++ .../NewOnboarding/onboarding.module.css | 2 +- 3 files changed, 531 insertions(+), 80 deletions(-) create mode 100644 src/features/default/src/Components/NewOnboarding/VerifyEmaildummy.jsx diff --git a/src/features/default/src/Components/NewOnboarding/VerifyEmail.jsx b/src/features/default/src/Components/NewOnboarding/VerifyEmail.jsx index 8af4818c..dcb538be 100644 --- a/src/features/default/src/Components/NewOnboarding/VerifyEmail.jsx +++ b/src/features/default/src/Components/NewOnboarding/VerifyEmail.jsx @@ -31,6 +31,10 @@ import { import { CountdownCircleTimer } from "react-countdown-circle-timer"; import { useHistory } from "react-router-dom"; import { FarmStackContext } from "common/components/context/DefaultContext/FarmstackProvider"; +import Visibility from '@mui/icons-material/Visibility'; +import VisibilityOff from '@mui/icons-material/VisibilityOff'; +import IconButton from '@mui/material/IconButton'; +import InputAdornment from '@mui/material/InputAdornment'; const VerifyEmailStep = (props) => { const { callLoader, callToast } = useContext(FarmStackContext); @@ -43,13 +47,22 @@ const VerifyEmailStep = (props) => { const [loginError, setLoginError] = useState(""); const [emailId, setEmailId] = useState(""); const [otp, setOtp] = useState(""); - const [isValidEmailSent, setIsValidEmailSent] = useState(false); +// const [isValidEmailSent, setIsValidEmailSent] = useState(false); const [gotOtp, setGotOtp] = useState(false); const [key, setKey] = useState(0); const [resend, showResend] = useState(false); const [timer, showTimer] = useState(false); const [agreement, showAgreement] = useState(true); + const [showPassword, setShowPassword] = useState(false); + + const handleClickShowPassword = () => { + setShowPassword(!showPassword); + }; + + const handleMouseDownPassword = (event) => { + event.preventDefault(); + }; const history = useHistory(); @@ -81,7 +94,7 @@ const VerifyEmailStep = (props) => { console.log( "🚀 ~ file: VerifyEmail.jsx:80 ~ .then ~ response:", isEmailValid, - !isValidEmailSent, + // !isValidEmailSent, agreementChecked, response ); @@ -94,7 +107,7 @@ const VerifyEmailStep = (props) => { response?.data?.message ? response?.data?.message : "Enter Otp" ); // setTimer(10); - setIsValidEmailSent(true); + // setIsValidEmailSent(true); } else if (action == "otp") { callLoader(false); console.log(action, response); @@ -288,50 +301,102 @@ const VerifyEmailStep = (props) => { return (
- {" "} - {isValidEmailSent ? "Enter the OTP" : "Enter your email Id"} -
- -
- {isValidEmailSent - ? "we sent you the otp, please check your email." - : "We will send you otp to verify your email id."} + Enter your email ID and password to seamlessly sign in.
- !isValidEmailSent - ? setEmailId(e.target.value.toLowerCase()) - : setOtp( - e.target.value.length <= 6 && !isNaN(e.target.value) - ? e.target.value - : otp // If the input is not a valid 6-digit number, keep the current value - ) - } + // value={emailId} + // onChange={(e) => + // !isValidEmailSent + // ? setEmailId(e.target.value.toLowerCase()) + // : setOtp( + // e.target.value.length <= 6 && !isNaN(e.target.value) + // ? e.target.value + // : otp // If the input is not a valid 6-digit number, keep the current value + // ) + // } required - onKeyDown={(e) => { - console.log(e.key); - if (e.key == " ") { - e.preventDefault(); - } else if (e.key == "Enter") { - if (!isValidEmailSent && emailId && agreementChecked) { - handleSubmit("email"); - } else if (isValidEmailSent && otp) { - handleSubmit("otp"); - } - } + // onKeyDown={(e) => { + // console.log(e.key); + // if (e.key == " ") { + // e.preventDefault(); + // } else if (e.key == "Enter") { + // if (!isValidEmailSent && emailId && agreementChecked) { + // handleSubmit("email"); + // } else if (isValidEmailSent && otp) { + // handleSubmit("otp"); + // } + // } + // }} + error={loginError ? true : false} + helperText={loginError} + /> +
+
+ + // !isValidEmailSent + // ? setEmailId(e.target.value.toLowerCase()) + // : setOtp( + // e.target.value.length <= 6 && !isNaN(e.target.value) + // ? e.target.value + // : otp // If the input is not a valid 6-digit number, keep the current value + // ) + // } + required + // onKeyDown={(e) => { + // console.log(e.key); + // if (e.key == " ") { + // e.preventDefault(); + // } else if (e.key == "Enter") { + // if (!isValidEmailSent && emailId && agreementChecked) { + // handleSubmit("email"); + // } else if (isValidEmailSent && otp) { + // handleSubmit("otp"); + // } + // } + // }} + InputProps={{ + endAdornment: ( + + + {showPassword ? : } + + + ), }} error={loginError ? true : false} helperText={loginError} />
+
+ +
{agreement && (
{
)} - {timer && isValidEmailSent && ( -
- { - handleStates("resend"); - }} - > -
- )} - {isValidEmailSent && resend && ( -
- -
- )}
diff --git a/src/features/default/src/Components/NewOnboarding/VerifyEmaildummy.jsx b/src/features/default/src/Components/NewOnboarding/VerifyEmaildummy.jsx new file mode 100644 index 00000000..8af4818c --- /dev/null +++ b/src/features/default/src/Components/NewOnboarding/VerifyEmaildummy.jsx @@ -0,0 +1,423 @@ +import React, { useContext, useEffect, useState } from "react"; +import styles from "./onboarding.module.css"; +import { + Button, + Checkbox, + TextField, + useMediaQuery, + useTheme, +} from "@mui/material"; +// import { CheckBox } from "@mui/icons-material"; +import global_style from "../../Assets/CSS/global.module.css"; +import UrlConstant from "../../Constants/UrlConstants"; +// import { logIn } from "./utils"; +import HTTPService from "../../Services/HTTPService"; + +import validator from "validator"; +import { + GetErrorHandlingRoute, + GetErrorKey, + getRoleLocal, + isLoggedInUserAdmin, + isLoggedInUserCoSteward, + isLoggedInUserParticipant, + setOrgId, + setRefreshTokenLocal, + setRoleLocal, + setTokenLocal, + setUserId, + setUserMapId, +} from "../../Utils/Common"; +import { CountdownCircleTimer } from "react-countdown-circle-timer"; +import { useHistory } from "react-router-dom"; +import { FarmStackContext } from "common/components/context/DefaultContext/FarmstackProvider"; + +const VerifyEmailStep = (props) => { + const { callLoader, callToast } = useContext(FarmStackContext); + const theme = useTheme(); + const mobile = useMediaQuery(theme.breakpoints.down("sm")); + const [agreementChecked, setAgreementChecked] = useState( + localStorage.getItem("dev_mode") ? true : false + ); + const { setActiveStep } = props; + const [loginError, setLoginError] = useState(""); + const [emailId, setEmailId] = useState(""); + const [otp, setOtp] = useState(""); + const [isValidEmailSent, setIsValidEmailSent] = useState(false); + const [gotOtp, setGotOtp] = useState(false); + const [key, setKey] = useState(0); + + const [resend, showResend] = useState(false); + const [timer, showTimer] = useState(false); + const [agreement, showAgreement] = useState(true); + + const history = useHistory(); + + const handleSubmit = async (action) => { + console.log("handleSubmit", action); + setLoginError(""); + let data; + let url; + let method; + if (action == "email") { + url = UrlConstant.base_url + UrlConstant.login; + data = { + email: emailId, + }; + method = "POST"; + } else if (action == "otp") { + url = UrlConstant.base_url + UrlConstant.otp; + data = { + email: emailId?.toLowerCase(), + otp, + }; + method = "POST"; + } + callLoader(true); + console.log("🚀 ~ file: VerifyEmail.jsx:71 ~ handleSubmit ~ data:", data); + + HTTPService(method, url, data, false, false, false, false) + .then((response) => { + console.log( + "🚀 ~ file: VerifyEmail.jsx:80 ~ .then ~ response:", + isEmailValid, + !isValidEmailSent, + agreementChecked, + response + ); + if (action == "email") { + callLoader(false); + console.log(response); + setLoginError(""); + handleStates("timer"); + setGotOtp( + response?.data?.message ? response?.data?.message : "Enter Otp" + ); + // setTimer(10); + setIsValidEmailSent(true); + } else if (action == "otp") { + callLoader(false); + console.log(action, response); + if (response.status === 201) { + localStorage.setItem("email", response?.data?.email); + setRefreshTokenLocal(response?.data?.refresh); + setTokenLocal(response?.data?.access); + setRoleLocal(response?.data?.role); + setUserMapId(response?.data?.user_map); + setOrgId(response?.data?.org_id); + setUserId(response?.data?.user); + console.log(getRoleLocal()); + if (response?.data?.on_boarded) { + if (isLoggedInUserAdmin()) { + history.push("/datahub/new_datasets"); + } else if (isLoggedInUserParticipant()) { + history.push("/participant/new_datasets"); + } else if (isLoggedInUserCoSteward()) { + history.push("/datahub/new_datasets"); + } + } else { + setActiveStep((prev) => prev + 1); + return; + } + } else { + setLoginError("Some error occurred"); + return; + } + setActiveStep((prev) => prev + 1); + } + }) + .catch(async (e) => { + console.log("e.response.status", key, e.response?.status, e); + callLoader(false); + if ( + e.response != null && + e.response != undefined && + e.response.status === 401 + ) { + setLoginError( + e.response.data && e.response.data.message + ? e.response.data.message + : "User not registered" + ); + } else if ( + e.response != null && + e.response != undefined && + e.response.status === 403 + ) { + setLoginError( + e.response.data && e.response.data.message + ? e.response.data.message + : "User suspended. Please try after sometime." + ); + } else if ( + e.response != null && + e.response != undefined && + e.response.status === 400 + ) { + console.log( + "🚀 ~ file: VerifyEmail.jsx:158 ~ handleSubmit ~ data:", + key, + e.response.status, + e + ); + var returnValues = GetErrorKey( + e, + action == "email" ? ["email"] : ["otp"] + ); + var errorKeys = returnValues[0]; + var errorMessages = returnValues[1]; + if (errorKeys.length > 0) { + for (var i = 0; i < errorKeys.length; i++) { + switch (errorKeys[i]) { + case "email": + setLoginError(errorMessages[i]); + break; + case "otp": + setLoginError(errorMessages[i]); + break; + default: + break; + } + } + } else { + let error = await GetErrorHandlingRoute(e); + if (error) { + callToast(error?.message, "error", true); + } + } + } else { + let error = await GetErrorHandlingRoute(e); + if (error) { + callToast(error?.message, "error", true); + } + } + }); + }; + + const handleStates = (key) => { + if (key == "timer") { + showResend(false); + showAgreement(false); + showTimer(true); + } else if (key == "resend") { + showAgreement(false); + showTimer(false); + showResend(true); + } + }; + + const hanleResendOTp = async (e) => { + console.log("hanleResendOTp"); + e.preventDefault(); + let url = UrlConstant.base_url + UrlConstant.resend_otp; + callLoader(true); + HTTPService( + "POST", + url, + { + email: emailId?.toLowerCase(), + }, + false, + false + ) + .then((response) => { + console.log( + "🚀 ~ file: VerifyEmail.jsx:228 ~ .then ~ response:", + response + ); + callLoader(false); + console.log(response); + handleStates("timer"); + setKey((prevKey) => prevKey + 1); + }) + .catch(async (e) => { + callLoader(false); + if ( + e.response != null && + e.response != undefined && + e.response.status === 401 + ) { + setLoginError( + e.response.data && e.response.data.message + ? e.response.data.message + : "User not registered" + ); + } else if ( + e.response != null && + e.response != undefined && + e.response.status === 403 + ) { + setLoginError( + e.response.data && e.response.data.message + ? e.response.data.message + : "User suspended. Please try after sometime." + ); + } else { + let error = await GetErrorHandlingRoute(e); + if (error?.path) { + history.push(error.path); + } + if (error.toast) { + callToast(error?.message ?? "Unknown error", "error", true); + } + } + }); + }; + console.log("loginError", loginError); + + const children = ({ remainingTime }) => { + return ( +
+ {remainingTime} +
+ ); + }; + const isEmailValid = validator.isEmail(emailId); + // console.log( + // "🚀 ~ file: VerifyEmail.jsx:273 ~ .then ~ response:", + // isEmailValid, + // !isValidEmailSent, + // agreementChecked + // ); + console.log(isEmailValid); + useEffect(() => {}, []); + return ( +
+
+ {" "} + {isValidEmailSent ? "Enter the OTP" : "Enter your email Id"} +
+ +
+ {isValidEmailSent + ? "we sent you the otp, please check your email." + : "We will send you otp to verify your email id."} +
+
+ + !isValidEmailSent + ? setEmailId(e.target.value.toLowerCase()) + : setOtp( + e.target.value.length <= 6 && !isNaN(e.target.value) + ? e.target.value + : otp // If the input is not a valid 6-digit number, keep the current value + ) + } + required + onKeyDown={(e) => { + console.log(e.key); + if (e.key == " ") { + e.preventDefault(); + } else if (e.key == "Enter") { + if (!isValidEmailSent && emailId && agreementChecked) { + handleSubmit("email"); + } else if (isValidEmailSent && otp) { + handleSubmit("otp"); + } + } + }} + error={loginError ? true : false} + helperText={loginError} + /> +
+ {agreement && ( +
+ setAgreementChecked(e.target.checked)} + className={styles.checkbox} + />{" "} + + {" "} + Agree to the following{" "} + history.push("/home/legal")} + > + terms and privacy policy. + {" "} + +
+ )} + {timer && isValidEmailSent && ( +
+ { + handleStates("resend"); + }} + > +
+ )} + {isValidEmailSent && resend && ( +
+ +
+ )} + +
+ +
+
+ ); +}; + +export default VerifyEmailStep; diff --git a/src/features/default/src/Components/NewOnboarding/onboarding.module.css b/src/features/default/src/Components/NewOnboarding/onboarding.module.css index 6f16dece..ab16122c 100644 --- a/src/features/default/src/Components/NewOnboarding/onboarding.module.css +++ b/src/features/default/src/Components/NewOnboarding/onboarding.module.css @@ -130,7 +130,7 @@ align-self: stretch; flex-grow: 0; z-index: 0; - margin: 0px auto 10px auto; + margin: 25px auto 10px auto; } .checkbox {