feat: otp validation

This commit is contained in:
deepvasoya 2025-05-20 18:22:10 +05:30
parent 1508c54700
commit 3d91cee029
5 changed files with 90 additions and 12 deletions

View File

@ -9,3 +9,30 @@ export const signup = (data) => {
.catch((err) => reject(err)); .catch((err) => reject(err));
}); });
}; };
export const getEmailOtp = (data) => {
const url = '/auth/send-otp';
return new Promise((resolve, reject) => {
axiosInstance
.post(url, null, { params: data })
.then((response) => resolve(response))
.catch((err) => reject(err));
});
};
export const verifyOtp = (data) => {
const url = '/auth/verify-otp';
return new Promise((resolve, reject) => {
axiosInstance
.post(url, data)
.catch((err) => {
if(err.status==200){
resolve(err)
}else{
reject(err)
}
})
.then((response) => resolve(response))
});
};

View File

@ -36,7 +36,7 @@ export const getClinics = (params) => {
}; };
export const getLatestClinicId = () => { export const getLatestClinicId = () => {
const url = `/clinics/latest-id`; const url = `/auth/clinic/latest-id`;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axiosInstance axiosInstance
.get(url) .get(url)

View File

@ -26,6 +26,7 @@ function Dashboard() {
accounts: null, accounts: null,
lastPlanPurchase: null, lastPlanPurchase: null,
}); });
const [isActive, setIsActive] = useState(false);
const dispatch = useDispatch(); const dispatch = useDispatch();
const userRole = useSelector(selectUserRole); const userRole = useSelector(selectUserRole);
const user = useSelector((state) => state.login.user); const user = useSelector((state) => state.login.user);
@ -37,6 +38,11 @@ function Dashboard() {
// This logic can be adjusted based on your specific role criteria // This logic can be adjusted based on your specific role criteria
const isSuperAdmin = const isSuperAdmin =
user.userType == USER_ROLES.SUPER_ADMIN.toLowerCase(); user.userType == USER_ROLES.SUPER_ADMIN.toLowerCase();
const clinicStatus = user.created_clinics[0].status;
setIsActive(clinicStatus == "active");
if (isSuperAdmin) { if (isSuperAdmin) {
dispatch(setUserRole(USER_ROLES.SUPER_ADMIN)); dispatch(setUserRole(USER_ROLES.SUPER_ADMIN));
} else { } else {
@ -54,7 +60,7 @@ function Dashboard() {
const clinicAdmin = ( const clinicAdmin = (
<Box> <Box>
{/* <ThankYou /> */} <ThankYou isActive={isActive} canClose={false} />
<Box> <Box>
<Box> <Box>
<Box className={classes.dashboardTitleBox}> <Box className={classes.dashboardTitleBox}>

View File

@ -72,7 +72,7 @@ import PasswordValidation from "../Login/component/PasswordValidation";
import { resetFormData, updateFormDetails } from "./signupAction"; import { resetFormData, updateFormDetails } from "./signupAction";
import { useStyles } from "./styles/signupStyles"; import { useStyles } from "./styles/signupStyles";
import { getLatestClinicId } from "../../services/clinics.service"; import { getLatestClinicId } from "../../services/clinics.service";
import { signup } from "../../services/auth.services"; import { getEmailOtp, signup, verifyOtp } from "../../services/auth.services";
import { decodeJWT } from "../../services/jwt.services"; import { decodeJWT } from "../../services/jwt.services";
function YourDetailsForm() { function YourDetailsForm() {
@ -82,6 +82,8 @@ function YourDetailsForm() {
const theme = useTheme(); const theme = useTheme();
const [latestClinicID, setLatestClinicID] = useState(0); const [latestClinicID, setLatestClinicID] = useState(0);
const [otpField, setOtpField] = useState(false); const [otpField, setOtpField] = useState(false);
const [otp, setOtp] = useState("");
const [otpVerified, setOtpVerified] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [showPassword, setShowPassword] = useState(false); const [showPassword, setShowPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false);
@ -236,7 +238,6 @@ function YourDetailsForm() {
confirmPassword: Yup.string() confirmPassword: Yup.string()
.oneOf([Yup.ref("password"), null], "Passwords must match") .oneOf([Yup.ref("password"), null], "Passwords must match")
.required("The password must match"), .required("The password must match"),
otp: Yup.string().required("OTP is required"),
// Clinic details validation // Clinic details validation
companyName: Yup.string().required("Clinic Name is required"), companyName: Yup.string().required("Clinic Name is required"),
@ -338,17 +339,48 @@ function YourDetailsForm() {
pushNotification("Test connection successful", "success"); pushNotification("Test connection successful", "success");
}; };
const handleOTPButton = () => { const handleOTPButton = async () => {
console.log("btn");
setOtpField(true); setOtpField(true);
const payload = {
email: formik.values.email,
}
const response = await getEmailOtp(payload);
if (response?.data?.error) {
pushNotification(response?.data?.message, NOTIFICATION.ERROR);
return;
}
pushNotification(response?.data?.message, NOTIFICATION.SUCCESS);
}; };
const verifyOTP = () => {}; const verifyOTP = async (e) => {
e.preventDefault();
console.log(otp)
console.log("OTP verified");
const payload = {
email: formik.values.email,
otp: otp,
}
const response = await verifyOtp(payload);
if (response?.data?.error) {
pushNotification(response?.data?.message, NOTIFICATION.ERROR);
setOtpVerified(false);
return;
}
pushNotification("OTP verified successfully", NOTIFICATION.SUCCESS);
setOtpVerified(true);
setOtpField(true);
// setOtp("");
};
const handleFormSubmit = async () => { const handleFormSubmit = async () => {
dispatch(updateFormDetails(formik.values)); dispatch(updateFormDetails(formik.values));
if(!otpVerified){
pushNotification("Please verify OTP first", NOTIFICATION.ERROR);
return;
}
const body = formatedData(formik.values); const body = formatedData(formik.values);
console.log(body);
try { try {
// TODO: verify otp first // TODO: verify otp first
@ -591,7 +623,7 @@ function YourDetailsForm() {
} }
const handleSaveAndNext = async () => { const handleSaveAndNext = async () => {
if (!otpField) { if (!otpVerified) {
pushNotification("Please verify OTP first", NOTIFICATION.ERROR); pushNotification("Please verify OTP first", NOTIFICATION.ERROR);
otpButtonRef.current?.focus(); otpButtonRef.current?.focus();
return; return;
@ -853,12 +885,25 @@ function YourDetailsForm() {
color="secondary" color="secondary"
variant="outlined" variant="outlined"
name="otp" name="otp"
value={formik.values.otp} value={otp}
onChange={formik.handleChange} onChange={(e) => setOtp(e.target.value)}
onBlur={formik.handleBlur} onBlur={formik.handleBlur}
InputProps={{ InputProps={{
type: "text", type: "text",
pattern: "[0-9]*", pattern: "[0-9]*",
endAdornment: (
<InputAdornment position="end">
<Button
variant="text"
color="info"
disabled={!otpButtonRef}
onClick={verifyOTP}
ref={otpButtonRef}
>
Verify OTP
</Button>
</InputAdornment>
),
}} }}
inputRef={fieldRefs.otp} inputRef={fieldRefs.otp}
error={Boolean( error={Boolean(

View File

@ -140,7 +140,7 @@ const ThankYou = ({ canClose = true, setShowPopup }) => {
margin="auto" margin="auto"
className={classes.description} className={classes.description}
> >
Please wait while BSmart team is verifying your details. Please wait while 24x7 AIHR team is verifying your details.
</Typography> </Typography>
</Box> </Box>
<Box> <Box>