From 3073ef90b8341ef8c1248d2b3d00c1fdef655407 Mon Sep 17 00:00:00 2001 From: deepvasoya Date: Wed, 28 May 2025 15:36:20 +0530 Subject: [PATCH] feat: payment dues handling --- src/constants/index.js | 1 + src/services/clinics.service.js | 10 ++++++++++ src/views/ClinicDetails/index.jsx | 4 ---- src/views/ClinicsList/index.jsx | 8 ++++---- .../Dashboard/Tiles/SuperAdminTotals.jsx | 9 +++++++++ src/views/Dashboard/components/SuperAdmin.jsx | 4 +++- src/views/Dashboard/index.jsx | 19 ++++++++++++++++++- src/views/Signup/YourDetailsForm.jsx | 12 +++++++----- 8 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/constants/index.js b/src/constants/index.js index 99928cd..d0ed4a3 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -43,6 +43,7 @@ export const CLINIC_STATUS = { APPROVAL_PENDING_DOCUMENT_RESUBMITTED: 'APPROVAL_PENDING_DOCUMENT_RESUBMITTED', INACTIVE: 'inactive', + PAYMENT_DUE: "payment_due", }; export const CLINIC_DOCUMENT_STATUS = { diff --git a/src/services/clinics.service.js b/src/services/clinics.service.js index f8244c9..88987b5 100644 --- a/src/services/clinics.service.js +++ b/src/services/clinics.service.js @@ -39,6 +39,16 @@ export const getClinicsById = (id) => { }); }; +export const generatePaymentSession = () =>{ + const url = `/stripe/create-payment-session`; + return new Promise((resolve, reject) => { + axiosInstance + .post(url) + .then((response) => resolve(response)) + .catch((err) => reject(err)); + }); +} + export const updateClinicStatus = (data) => { const url = `/admin/clinic/status`; return new Promise((resolve, reject) => { diff --git a/src/views/ClinicDetails/index.jsx b/src/views/ClinicDetails/index.jsx index 2895798..18f6712 100644 --- a/src/views/ClinicDetails/index.jsx +++ b/src/views/ClinicDetails/index.jsx @@ -246,10 +246,6 @@ function ClinicDetails() { setButtonClickStatus("Rejected"); }; - const handleOnHoldClick = () => { - setIsShowReasonModel(true); - setButtonClickStatus("On Hold"); - }; const handleAcceptClick = () => { // setIsShowReasonModel(true); diff --git a/src/views/ClinicsList/index.jsx b/src/views/ClinicsList/index.jsx index b9d93ed..39e401f 100644 --- a/src/views/ClinicsList/index.jsx +++ b/src/views/ClinicsList/index.jsx @@ -211,8 +211,8 @@ const ClinicsList = () => { label={ status === CLINIC_STATUS.UNDER_REVIEW.toLowerCase() ? ( "Under Review" - ) : status === CLINIC_STATUS.NOT_REVIEWED ? ( - "Approval Pending" + ) : status === CLINIC_STATUS.PAYMENT_DUE ? ( + "Payment Due" ) : status === CLINIC_STATUS.APPROVAL_PENDING_DOCUMENT_RESUBMITTED ? (
@@ -231,7 +231,7 @@ const ClinicsList = () => { backgroundColor: status === CLINIC_STATUS.ON_HOLD.toLowerCase() ? theme.palette.orange.light - : status === CLINIC_STATUS.NOT_REVIEWED.toLowerCase() || + : status === CLINIC_STATUS.PAYMENT_DUE.toLowerCase() || status === CLINIC_STATUS.REJECTED.toLowerCase() ? theme.palette.primary.highlight : status === @@ -241,7 +241,7 @@ const ClinicsList = () => { color: status === CLINIC_STATUS.ON_HOLD.toLowerCase() ? theme.palette.orange.main - : status === CLINIC_STATUS.NOT_REVIEWED.toLowerCase() || + : status === CLINIC_STATUS.PAYMENT_DUE.toLowerCase() || status === CLINIC_STATUS.REJECTED.toLowerCase() ? theme.palette.primary.main : status === diff --git a/src/views/Dashboard/Tiles/SuperAdminTotals.jsx b/src/views/Dashboard/Tiles/SuperAdminTotals.jsx index ee10082..5e2c670 100644 --- a/src/views/Dashboard/Tiles/SuperAdminTotals.jsx +++ b/src/views/Dashboard/Tiles/SuperAdminTotals.jsx @@ -46,6 +46,15 @@ const SuperAdminTotals = ({ isLoading, data }) => { color={theme.palette.grey[57]} /> + + viewAllClick(false)} + value={rejected} + color={theme.palette.grey[57]} + /> + { registrationRequest: 0, rejected: 0, registered: 0, + paymentDue: 0, }); const fetchDashboardStats = async () => { @@ -26,7 +27,8 @@ const SuperAdmin = () => { registrationRequest: apiData?.totalUnderReviewClinics, rejected: apiData?.totalRejectedClinics, registered: apiData?.totalActiveClinics, - }); + paymentDue: apiData?.totalPaymentDueClinics, + }); } catch (error) { console.error("Error fetching data:", error); } finally { diff --git a/src/views/Dashboard/index.jsx b/src/views/Dashboard/index.jsx index 443eac7..31d9fbe 100644 --- a/src/views/Dashboard/index.jsx +++ b/src/views/Dashboard/index.jsx @@ -8,7 +8,7 @@ import { selectUserRole, setUserRole } from "../../redux/userRoleSlice"; import Totals from "./Tiles/Totals"; import { useStyles } from "./dashboardStyles"; import { NOTIFICATION, USER_ROLES } from "../../constants"; -import { getClinicsById } from "../../services/clinics.service"; +import { generatePaymentSession, getClinicsById } from "../../services/clinics.service"; import { pushNotification } from "../../utils/notification"; import { useNavigate } from "react-router-dom"; import { updateFormDetails } from "../Signup/signupAction"; @@ -66,6 +66,23 @@ function Dashboard() { navigation("/docs"); } + if(status=="payment_due"){ + setIsActive(false); + pushNotification("Payment due", NOTIFICATION.WARNING); + const session = await generatePaymentSession(); + + if(session?.data?.error){ + pushNotification(session?.data?.message, NOTIFICATION.ERROR); + return; + } + + const newWindow = window.open(session?.data?.data, "_blank", "noopener,noreferrer"); + if (!newWindow || newWindow.closed || typeof newWindow.closed === 'undefined') { + // Fallback in case popup is blocked + window.location.href = session?.data?.data; + } + } + // if(status=="payment_due"){ // setIsActive(false); // pushNotification("Payment due", NOTIFICATION.WARNING); diff --git a/src/views/Signup/YourDetailsForm.jsx b/src/views/Signup/YourDetailsForm.jsx index 1a7eb5b..93c2614 100644 --- a/src/views/Signup/YourDetailsForm.jsx +++ b/src/views/Signup/YourDetailsForm.jsx @@ -94,10 +94,6 @@ function YourDetailsForm() { const selectedLocalityRef = useRef(); const [testConnection, setTestConnDone] = useState(false); - const errorStatus = new URLSearchParams(window.location.search).get("status"); - - console.log(errorStatus); - useEffect(() => { setIsLoading(true); getLatestClinicId().then((res) => { @@ -397,8 +393,14 @@ function YourDetailsForm() { return; } pushNotification(response?.data?.message, NOTIFICATION.SUCCESS); + // open new page for stripe payment from url + const newWindow = window.open(response?.data?.data, "_blank", "noopener,noreferrer"); + if (!newWindow || newWindow.closed || typeof newWindow.closed === 'undefined') { + // Fallback in case popup is blocked + window.location.href = response?.data?.data; + } dispatch(resetFormData()); - navigate("/auth/signup/payment"); + navigate("/"); } catch (error) { console.error("Error signing up:", error); } finally {