-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dc5534
commit 61d96ea
Showing
13 changed files
with
430 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useState, useEffect } from "react"; | ||
import { decryptData } from "@/lib/cryptoUtils"; | ||
|
||
const TrialRemaining = () => { | ||
const [installTimeValue, setInstallTimeValue] = useState<Date | null>(null); | ||
const [trialRemaining, setTrialRemaining] = useState<string | null>(null); | ||
const trialPeriod = 30; // 30-day trial | ||
|
||
useEffect(() => { | ||
const fetchInstallTime = async () => { | ||
try { | ||
// Fetch and decrypt the installation date from storage | ||
const encryptedInstallTimeString = await storage.getItem<string>( | ||
"sync:installDate" | ||
); | ||
|
||
if (encryptedInstallTimeString) { | ||
// Decrypt and parse the installation date | ||
const decryptedInstallTime = await decryptData( | ||
encryptedInstallTimeString | ||
); | ||
const timestamp = parseInt(decryptedInstallTime); | ||
const installDate = new Date(timestamp); | ||
setInstallTimeValue(installDate); | ||
|
||
// Calculate the remaining trial period | ||
calculateTrialRemaining(installDate); | ||
} else { | ||
// If no installation time is found, initialize with current date | ||
const currentInstallDate = new Date(); | ||
setInstallTimeValue(currentInstallDate); | ||
|
||
// Start trial calculation | ||
calculateTrialRemaining(currentInstallDate); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching or saving install date:", error); | ||
} | ||
}; | ||
|
||
// Calculate the remaining trial days | ||
const calculateTrialRemaining = (installDate: Date) => { | ||
const currentDate = new Date(); | ||
const diffTime = currentDate.getTime() - installDate.getTime(); | ||
const diffDays = Math.ceil(diffTime / (1000 * 3600 * 24)); // Convert ms to days | ||
|
||
const daysRemaining = trialPeriod - diffDays; | ||
|
||
if (daysRemaining > 0) { | ||
setTrialRemaining(`${daysRemaining} days`); | ||
} else { | ||
setTrialRemaining("Your trial period has expired."); | ||
} | ||
}; | ||
|
||
fetchInstallTime(); | ||
}, []); | ||
|
||
return ( | ||
<div className="trial-container"> | ||
{installTimeValue ? ( | ||
<span className="trial-info text-white"> | ||
Trial Remaining: {trialRemaining} | ||
</span> | ||
) : ( | ||
<span className="trial-info text-white animate-pulse"> | ||
Loading trial information... | ||
</span> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default TrialRemaining; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './App.tsx'; | ||
import './style.css'; | ||
import React from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import App from "./App.tsx"; | ||
import "./style.css"; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
ReactDOM.createRoot(document.getElementById("root")!).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
</React.StrictMode> | ||
); |
Oops, something went wrong.