feat: update license manually

This commit is contained in:
Tristan Yang
2022-11-29 14:59:32 +08:00
parent 55f26a6077
commit 82ebe7b677
10 changed files with 136 additions and 45 deletions
+9 -4
View File
@@ -1,4 +1,4 @@
// import { useEffect } from "react";
import { useEffect } from "react";
import {
useCheckLicenseMutation,
useGetLicenseQuery,
@@ -10,12 +10,12 @@ const useLicense = () => {
const { userCount, isGuest } = useAppSelector((store) => {
return { userCount: store.users.ids.length, isGuest: store.authData.guest };
});
const { data: license } = useGetLicenseQuery(undefined, {
const { data: license, refetch: refetchLicense } = useGetLicenseQuery(undefined, {
refetchOnMountOrArgChange: true,
skip: isGuest
});
const [check, { isLoading: isChecking, isSuccess: checked }] = useCheckLicenseMutation();
const [upsert, { isSuccess: upserted, isLoading: upserting }] = useUpsertLicenseMutation();
const [upsert, { isSuccess: upserted, isLoading: upserting, reset: resetUpsert }] = useUpsertLicenseMutation();
const checkLicense = (l: string) => {
check(l);
};
@@ -28,7 +28,12 @@ const useLicense = () => {
return false;
}
};
console.log("uuu", userCount, license);
useEffect(() => {
if (upserted) {
refetchLicense();
resetUpsert();
}
}, [upserted]);
const lUserLimit = license?.user_limit ?? Number.MAX_SAFE_INTEGER;
return {
reachLimit: userCount >= lUserLimit,