miissed file
This commit is contained in:
parent
902566b7dd
commit
388efd7f3b
|
|
@ -6,10 +6,9 @@ import {
|
||||||
getAppSubscriptionDate,
|
getAppSubscriptionDate,
|
||||||
} from './Features/BookingScreen/BookingData/BookingData.js';
|
} from './Features/BookingScreen/BookingData/BookingData.js';
|
||||||
import { sendSms } from './Features/Payment/PaymentDetails/PaymentDetails.js';
|
import { sendSms } from './Features/Payment/PaymentDetails/PaymentDetails.js';
|
||||||
import { getPurchasedAppDetails, postInvoice } from './Features/BookingScreen/Pricing/Pricing.js';
|
|
||||||
import { getSession } from './Services/Others.js';
|
import { getSession } from './Services/Others.js';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
const subDirectory = import.meta.env.ENV_BASE_URL;
|
||||||
const useSubscriptionManager = (sessionData, logout) => {
|
const useSubscriptionManager = (sessionData, logout) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
@ -21,11 +20,7 @@ const useSubscriptionManager = (sessionData, logout) => {
|
||||||
setExtendModel(false)
|
setExtendModel(false)
|
||||||
|
|
||||||
}
|
}
|
||||||
const handlePay = () => {
|
|
||||||
setExtendModel(false)
|
|
||||||
let AppName = getSession("AppName")
|
|
||||||
navigate(`${subDirectory}PricingPage`, { state: { AppName: AppName } });
|
|
||||||
}
|
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
const year = date.getFullYear();
|
const year = date.getFullYear();
|
||||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
|
@ -38,79 +33,8 @@ const useSubscriptionManager = (sessionData, logout) => {
|
||||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDays(dateString, days) {
|
|
||||||
// Make it ISO-safe for iOS / WebView
|
|
||||||
const isoDate = dateString.replace(' ', 'T');
|
|
||||||
const currentDate = new Date(isoDate);
|
|
||||||
|
|
||||||
currentDate.setDate(currentDate.getDate() + Number(days));
|
|
||||||
|
|
||||||
return formatDate(currentDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------- MAIN FUNCTION ----------------
|
|
||||||
const freeExtend = async () => {
|
|
||||||
try {
|
|
||||||
|
|
||||||
const UserId = getSession('UserId');
|
|
||||||
const AppId = getSession('AppId')
|
|
||||||
// Current date
|
|
||||||
const now = new Date();
|
|
||||||
const currentDate = formatDate(now);
|
|
||||||
|
|
||||||
// 1️⃣ Get purchased app details
|
|
||||||
const response1 = await dispatch(
|
|
||||||
getPurchasedAppDetails({ AppId, UserId })
|
|
||||||
).unwrap();
|
|
||||||
|
|
||||||
const PurchasedDetails = response1?.data?.data;
|
|
||||||
|
|
||||||
if (!PurchasedDetails || !PurchasedDetails.length) {
|
|
||||||
console.error('No purchased details found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2️⃣ Prepare post data
|
|
||||||
const postData = {
|
|
||||||
UserId: UserId,
|
|
||||||
AppId: AppId,
|
|
||||||
PricingId: PurchasedDetails[0]?.PricingId,
|
|
||||||
PurDate: currentDate,
|
|
||||||
NoofDays: 30,
|
|
||||||
PaymentMode: 27,
|
|
||||||
PaymentStatus: 'S',
|
|
||||||
LicenseStatus: PurchasedDetails[0]?.LicenseStatus,
|
|
||||||
Price: PurchasedDetails[0]?.Price ?? 0,
|
|
||||||
TaxId: PurchasedDetails[0]?.TaxId ?? 0,
|
|
||||||
NetPrice: PurchasedDetails[0]?.ExistingPlanNetPrice ?? 0,
|
|
||||||
ValidityStart: currentDate,
|
|
||||||
ValidityEnd: addDays(
|
|
||||||
currentDate,
|
|
||||||
PurchasedDetails[0]?.NoOfDays
|
|
||||||
),
|
|
||||||
CreatedBy: UserId,
|
|
||||||
TaxAmount: PurchasedDetails[0]?.TaxAmount ?? 0,
|
|
||||||
MobileNo: getSession('MobileNo'),
|
|
||||||
MailId: 'ts@gmmail.com',
|
|
||||||
Type: "FreeExtend"
|
|
||||||
};
|
|
||||||
|
|
||||||
// 3️⃣ Post invoice
|
|
||||||
const response = await dispatch(postInvoice(postData)).unwrap();
|
|
||||||
|
|
||||||
// 4️⃣ Send SMS if required
|
|
||||||
if (response?.data?.statusCode === 1 && response?.data?.SMSbody) {
|
|
||||||
await dispatch(
|
|
||||||
sendSms({ body: response.data.SMSbody })
|
|
||||||
);
|
|
||||||
setExtendModel(false)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('freeExtend error:', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!sessionData) return;
|
if (!sessionData) return;
|
||||||
|
|
||||||
|
|
@ -163,7 +87,7 @@ const useSubscriptionManager = (sessionData, logout) => {
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [sessionData]);
|
}, [sessionData]);
|
||||||
|
|
||||||
return { remainingDays, handleCancel, handlePay, freeExtend, extendModel };
|
return { remainingDays, handleCancel,extendModel,setExtendModel };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useSubscriptionManager;
|
export default useSubscriptionManager;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue