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));
});
};
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 = () => {
const url = `/clinics/latest-id`;
const url = `/auth/clinic/latest-id`;
return new Promise((resolve, reject) => {
axiosInstance
.get(url)

View File

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

View File

@ -72,7 +72,7 @@ import PasswordValidation from "../Login/component/PasswordValidation";
import { resetFormData, updateFormDetails } from "./signupAction";
import { useStyles } from "./styles/signupStyles";
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";
function YourDetailsForm() {
@ -82,6 +82,8 @@ function YourDetailsForm() {
const theme = useTheme();
const [latestClinicID, setLatestClinicID] = useState(0);
const [otpField, setOtpField] = useState(false);
const [otp, setOtp] = useState("");
const [otpVerified, setOtpVerified] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [showPassword, setShowPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
@ -236,7 +238,6 @@ function YourDetailsForm() {
confirmPassword: Yup.string()
.oneOf([Yup.ref("password"), null], "Passwords must match")
.required("The password must match"),
otp: Yup.string().required("OTP is required"),
// Clinic details validation
companyName: Yup.string().required("Clinic Name is required"),
@ -338,17 +339,48 @@ function YourDetailsForm() {
pushNotification("Test connection successful", "success");
};
const handleOTPButton = () => {
console.log("btn");
const handleOTPButton = async () => {
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 () => {
dispatch(updateFormDetails(formik.values));
if(!otpVerified){
pushNotification("Please verify OTP first", NOTIFICATION.ERROR);
return;
}
const body = formatedData(formik.values);
console.log(body);
try {
// TODO: verify otp first
@ -591,7 +623,7 @@ function YourDetailsForm() {
}
const handleSaveAndNext = async () => {
if (!otpField) {
if (!otpVerified) {
pushNotification("Please verify OTP first", NOTIFICATION.ERROR);
otpButtonRef.current?.focus();
return;
@ -853,12 +885,25 @@ function YourDetailsForm() {
color="secondary"
variant="outlined"
name="otp"
value={formik.values.otp}
onChange={formik.handleChange}
value={otp}
onChange={(e) => setOtp(e.target.value)}
onBlur={formik.handleBlur}
InputProps={{
type: "text",
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}
error={Boolean(

View File

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