Skip to content

Commit

Permalink
Merge pull request #114 from nomandhoni-cs/develop
Browse files Browse the repository at this point in the history
fixing validation logic
  • Loading branch information
nomandhoni-cs authored Nov 27, 2024
2 parents 965ce27 + 8daad4e commit 4b0b5f3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
44 changes: 35 additions & 9 deletions src/components/LicenseValidationComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,51 @@ import Database from "@tauri-apps/plugin-sql";
import toast from "react-hot-toast";
import { fetch as tauriFetch } from "@tauri-apps/plugin-http";
import { useLicenseKey } from "../hooks/useLicenseKey";
import { useTrigger } from "../contexts/TriggerReRender";

const LicenseValidationComponent: React.FC = () => {
const [licenseKey, setLicenseKey] = useState<string>("");
const [isDataLoaded, setIsDataLoaded] = useState(false); // Track loading status
const { licenseData, refreshLicenseData } = useLicenseKey();
const { triggerUpdate } = useTrigger();

// Function to check if a date is today
const isNotToday = (dateString: string): boolean => {
const today = new Date();
const inputDate = new Date(dateString);
return (
inputDate.getFullYear() !== today.getFullYear() ||
inputDate.getMonth() !== today.getMonth() ||
inputDate.getDate() !== today.getDate()
);
};

useEffect(() => {
const validateLicense = async () => {
await refreshLicenseData();
if (licenseData) {
setLicenseKey(licenseData.license_key);
await handleLicenseValidation(
licenseData.last_validated,
licenseData.status,
licenseData.license_key
);
}
console.log("Running License Validator");
await refreshLicenseData(); // Ensure data is refreshed
setIsDataLoaded(true); // Mark data as loaded
};
validateLicense();
}, []);

useEffect(() => {
console.log(isNotToday("2024-11-27"), "is not Today");
if (
isDataLoaded &&
licenseData &&
isNotToday(licenseData.last_validated) // Add the new condition
) {
console.log(licenseData);
setLicenseKey(licenseData.license_key);
handleLicenseValidation(
licenseData.last_validated,
licenseData.status,
licenseData.license_key
);
}
}, [isDataLoaded]); // Re-run when data loads

// Function to handle license validation and activation status
const handleLicenseValidation = async (
lastValidated: string,
Expand Down Expand Up @@ -76,6 +101,7 @@ const LicenseValidationComponent: React.FC = () => {
if (diffInDays > 7) {
// If more than 7 days, update status to what was received in the response
await updateLicenseStatus("disabled");
triggerUpdate();
} else {
// If less than 7 days, update status
await updateLicenseStatus(data.license_key.status);
Expand Down
6 changes: 4 additions & 2 deletions src/components/window/UsageTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import { Button } from "../ui/button";
import UsageTimeChart from "../UsageChart";

const UsageTime = () => {
const { canAccessPremiumFeatures } = usePremiumFeatures();
const { canAccessPremiumFeatures, isPaidUser, isTrialOn } =
usePremiumFeatures();
console.log(canAccessPremiumFeatures, isPaidUser, isTrialOn);

return (
<div className="relative">
<UsageTimeChart />
{/* Glassmorphism Effect Overlay */}
{!canAccessPremiumFeatures && (
<div className="absolute p-8 top-0 left-0 w-full h-full bg-black bg-opacity-60 backdrop-blur-lg flex flex-col space-y-8 justify-center items-center rounded-lg">
<div className="absolute p-8 top-0 left-0 w-full h-full bg-black bg-opacity-60 backdrop-blur-3xl flex flex-col space-y-8 justify-center items-center rounded-lg">
<h3 className="text-center text-white font-bold text-3xl">
Your support will help the developer to make this project better &
add more features.
Expand Down
2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<PremiumFeaturesProvider>
<DefaultStartMinimize />
<EncryptionComponent />
<LicenseValidationComponent />
<ConfigDataLoader />
<TriggerProvider>
<LicenseValidationComponent />
<ReminderHandler />
<App />
</TriggerProvider>
Expand Down

0 comments on commit 4b0b5f3

Please sign in to comment.