mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-25 22:36:38 +00:00
add license system and ui
This commit is contained in:
72
src/providers/LicenseStatusProvider.tsx
Normal file
72
src/providers/LicenseStatusProvider.tsx
Normal file
@@ -0,0 +1,72 @@
|
||||
// This file is licensed under the Fossorial Commercial License.
|
||||
// Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||
//
|
||||
// Copyright (c) 2025 Fossorial LLC. All rights reserved.
|
||||
|
||||
"use client";
|
||||
|
||||
import LicenseStatusContext from "@app/contexts/licenseStatusContext";
|
||||
import { LicenseStatus } from "@server/license/license";
|
||||
import { useState } from "react";
|
||||
|
||||
interface ProviderProps {
|
||||
children: React.ReactNode;
|
||||
licenseStatus: LicenseStatus | null;
|
||||
}
|
||||
|
||||
export function LicenseStatusProvider({
|
||||
children,
|
||||
licenseStatus
|
||||
}: ProviderProps) {
|
||||
const [licenseStatusState, setLicenseStatusState] =
|
||||
useState<LicenseStatus | null>(licenseStatus);
|
||||
|
||||
const updateLicenseStatus = (updatedLicenseStatus: LicenseStatus) => {
|
||||
setLicenseStatusState((prev) => {
|
||||
return {
|
||||
...updatedLicenseStatus
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const isUnlocked = () => {
|
||||
if (licenseStatusState?.isHostLicensed) {
|
||||
if (licenseStatusState?.isLicenseValid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const isLicenseViolation = () => {
|
||||
if (
|
||||
licenseStatusState?.isHostLicensed &&
|
||||
!licenseStatusState?.isLicenseValid
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
licenseStatusState?.maxSites &&
|
||||
licenseStatusState?.usedSites &&
|
||||
licenseStatusState.usedSites > licenseStatusState.maxSites
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
return (
|
||||
<LicenseStatusContext.Provider
|
||||
value={{
|
||||
licenseStatus: licenseStatusState,
|
||||
updateLicenseStatus,
|
||||
isLicenseViolation,
|
||||
isUnlocked
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</LicenseStatusContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export default LicenseStatusProvider;
|
||||
Reference in New Issue
Block a user