This commit is contained in:
MuslemRahimi 2024-09-18 22:57:37 +02:00
parent d36a323788
commit bb67104c26

View File

@ -652,8 +652,14 @@ function calculateStats(data) {
const getHistoricalFlow = async () => { const getHistoricalFlow = async () => {
// Create a delay using setTimeout wrapped in a Promise // Create a delay using setTimeout wrapped in a Promise
if(data?.user?.tier === 'Pro') {
isLoaded = false; isLoaded = false;
await new Promise(resolve => setTimeout(resolve, 500));
displayRules = allRows?.filter(row => ruleOfList.some(rule => rule.name === row.rule));
displayedData = [];
calculateStats(displayedData);
await new Promise(resolve => setTimeout(resolve, 300));
// Make the POST request after the delay // Make the POST request after the delay
const convertDate = new Date(df.format(selectedDate?.toDate())) const convertDate = new Date(df.format(selectedDate?.toDate()))
@ -661,7 +667,6 @@ const getHistoricalFlow = async () => {
const month = String(convertDate?.getMonth() + 1).padStart(2, '0'); const month = String(convertDate?.getMonth() + 1).padStart(2, '0');
const day = String(convertDate?.getDate()).padStart(2, '0'); const day = String(convertDate?.getDate()).padStart(2, '0');
console.log(`${year}-${month}-${day}`)
const postData = { 'selectedDate': `${year}-${month}-${day}`} const postData = { 'selectedDate': `${year}-${month}-${day}`}
try { try {
@ -674,17 +679,11 @@ const getHistoricalFlow = async () => {
}); });
rawData = await response?.json(); rawData = await response?.json();
console.log(rawData)
if(rawData?.length !== 0) { if(rawData?.length !== 0) {
rawData?.forEach((item) => { rawData?.forEach((item) => {
item.dte = daysLeft(item?.date_expiration); item.dte = daysLeft(item?.date_expiration);
}); });
shouldLoadWorker.set(true); shouldLoadWorker.set(true);
} else {
displayRules = allRows?.filter(row => ruleOfList.some(rule => rule.name === row.rule));
displayedData = [];
calculateStats(displayedData);
} }
} catch (error) { } catch (error) {
console.error("Error fetching historical flow:", error); console.error("Error fetching historical flow:", error);
@ -692,6 +691,14 @@ const getHistoricalFlow = async () => {
} finally { } finally {
isLoaded = true; isLoaded = true;
} }
}
else {
toast.error('Only for Pro Members', {
style: 'border-radius: 200px; background: #333; color: #fff;'
});
}
}; };