diff --git a/src/services/auth.services.js b/src/services/auth.services.js index e14c6f3..da183d3 100644 --- a/src/services/auth.services.js +++ b/src/services/auth.services.js @@ -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)) + }); + }; \ No newline at end of file diff --git a/src/services/clinics.service.js b/src/services/clinics.service.js index e854075..ff2b344 100644 --- a/src/services/clinics.service.js +++ b/src/services/clinics.service.js @@ -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) diff --git a/src/views/Dashboard/index.jsx b/src/views/Dashboard/index.jsx index fc24aca..4000f18 100644 --- a/src/views/Dashboard/index.jsx +++ b/src/views/Dashboard/index.jsx @@ -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 = ( - {/* */} + diff --git a/src/views/Signup/YourDetailsForm.jsx b/src/views/Signup/YourDetailsForm.jsx index 04f436a..7093827 100644 --- a/src/views/Signup/YourDetailsForm.jsx +++ b/src/views/Signup/YourDetailsForm.jsx @@ -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: ( + + + + ), }} inputRef={fieldRefs.otp} error={Boolean( diff --git a/src/views/ThankYou/index.jsx b/src/views/ThankYou/index.jsx index 4900975..1586483 100644 --- a/src/views/ThankYou/index.jsx +++ b/src/views/ThankYou/index.jsx @@ -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.