feat: license setting

This commit is contained in:
Tristan Yang
2022-07-11 20:24:00 +08:00
parent 45a147ae67
commit cb80f87033
5 changed files with 164 additions and 2 deletions
+36
View File
@@ -0,0 +1,36 @@
import { useEffect } from "react";
import { useCheckLicenseMutation, useUpsertLicenseMutation } from "../../app/services/server";
const useLicense = (license?: string) => {
const [check, { data, isLoading: isChecking, isSuccess: checked }] = useCheckLicenseMutation();
const [upsert, { isSuccess: upserted, isLoading: upserting }] = useUpsertLicenseMutation();
const checkLicense = (l: string) => {
check(l);
};
const upsertLicense = async (l: string) => {
// check first
const resp = await check(l);
if ("data" in resp && resp.data.sign) {
return await upsert(l);
} else {
return false;
}
};
useEffect(() => {
if (license) {
checkLicense(license);
}
}, [license]);
return {
validInfo: data,
checked,
checking: isChecking,
upserting,
upserted,
checkLicense,
upsertLicense
};
};
export default useLicense;