feat: get license
This commit is contained in:
Vendored
+4
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"todohighlight.isCaseSensitive": false,
|
||||||
"css.validate": false,
|
"css.validate": false,
|
||||||
"editor.quickSuggestions": {
|
"editor.quickSuggestions": {
|
||||||
"other": true,
|
"other": true,
|
||||||
@@ -40,6 +41,9 @@
|
|||||||
"tippyjs",
|
"tippyjs",
|
||||||
"toastui",
|
"toastui",
|
||||||
"uiball",
|
"uiball",
|
||||||
|
"upsert",
|
||||||
|
"upserted",
|
||||||
|
"upserting",
|
||||||
"vocechat"
|
"vocechat"
|
||||||
],
|
],
|
||||||
"reactSnippets.settings.prettierEnabled": true,
|
"reactSnippets.settings.prettierEnabled": true,
|
||||||
|
|||||||
@@ -194,6 +194,11 @@ export const serverApi = createApi({
|
|||||||
url: `/admin/system/initialized`
|
url: `/admin/system/initialized`
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
getLicense: builder.query<LicenseResponse, void>({
|
||||||
|
query: () => ({
|
||||||
|
url: `/license`
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
|
||||||
checkLicense: builder.mutation<LicenseResponse, string>({
|
checkLicense: builder.mutation<LicenseResponse, string>({
|
||||||
query: (license) => ({
|
query: (license) => ({
|
||||||
@@ -205,7 +210,7 @@ export const serverApi = createApi({
|
|||||||
upsertLicense: builder.mutation<boolean, string>({
|
upsertLicense: builder.mutation<boolean, string>({
|
||||||
query: (license) => ({
|
query: (license) => ({
|
||||||
url: "/license/save",
|
url: "/license/save",
|
||||||
method: "POST",
|
method: "PUT",
|
||||||
body: { license }
|
body: { license }
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -241,5 +246,6 @@ export const {
|
|||||||
useCreateAdminMutation,
|
useCreateAdminMutation,
|
||||||
useGetInitializedQuery,
|
useGetInitializedQuery,
|
||||||
useUpsertLicenseMutation,
|
useUpsertLicenseMutation,
|
||||||
useCheckLicenseMutation
|
useCheckLicenseMutation,
|
||||||
|
useGetLicenseQuery
|
||||||
} = serverApi;
|
} = serverApi;
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import { useEffect } from "react";
|
// import { useEffect } from "react";
|
||||||
import { useCheckLicenseMutation, useUpsertLicenseMutation } from "../../app/services/server";
|
import {
|
||||||
|
useCheckLicenseMutation,
|
||||||
|
useGetLicenseQuery,
|
||||||
|
useUpsertLicenseMutation
|
||||||
|
} from "../../app/services/server";
|
||||||
|
|
||||||
const useLicense = (license?: string) => {
|
const useLicense = () => {
|
||||||
const [check, { data, isLoading: isChecking, isSuccess: checked }] = useCheckLicenseMutation();
|
const { data: license } = useGetLicenseQuery();
|
||||||
|
const [check, { isLoading: isChecking, isSuccess: checked }] = useCheckLicenseMutation();
|
||||||
const [upsert, { isSuccess: upserted, isLoading: upserting }] = useUpsertLicenseMutation();
|
const [upsert, { isSuccess: upserted, isLoading: upserting }] = useUpsertLicenseMutation();
|
||||||
const checkLicense = (l: string) => {
|
const checkLicense = (l: string) => {
|
||||||
check(l);
|
check(l);
|
||||||
@@ -16,14 +21,9 @@ const useLicense = (license?: string) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
|
||||||
if (license) {
|
|
||||||
checkLicense(license);
|
|
||||||
}
|
|
||||||
}, [license]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
validInfo: data,
|
license,
|
||||||
checked,
|
checked,
|
||||||
checking: isChecking,
|
checking: isChecking,
|
||||||
upserting,
|
upserting,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ChangeEvent, useState } from "react";
|
import { ChangeEvent, useState, useEffect } from "react";
|
||||||
|
import dayjs from "dayjs";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import Tippy from "@tippyjs/react";
|
import Tippy from "@tippyjs/react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
@@ -28,6 +29,34 @@ const StyledConfirm = styled.div`
|
|||||||
gap: 14px;
|
gap: 14px;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
const StyledInfo = styled.div`
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: 5px;
|
||||||
|
border: 2px solid #557d2340;
|
||||||
|
background-color: #d1fadf60;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 15px;
|
||||||
|
.item {
|
||||||
|
white-space: nowrap;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: flex-start;
|
||||||
|
line-height: 1.2;
|
||||||
|
.label {
|
||||||
|
font-size: 13px;
|
||||||
|
color: #aaa;
|
||||||
|
&:after {
|
||||||
|
content: ":";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.info {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
const Styled = styled.div`
|
const Styled = styled.div`
|
||||||
max-width: 500px;
|
max-width: 500px;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -45,7 +74,7 @@ const Styled = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export default function License() {
|
export default function License() {
|
||||||
const { checking, upserting, upsertLicense } = useLicense();
|
const { license: licenseInfo, checking, upserting, upsertLicense } = useLicense();
|
||||||
const [license, setLicense] = useState("");
|
const [license, setLicense] = useState("");
|
||||||
const handleUpsert = async () => {
|
const handleUpsert = async () => {
|
||||||
if (!license) {
|
if (!license) {
|
||||||
@@ -64,12 +93,52 @@ export default function License() {
|
|||||||
const handleLicenseInput = (evt: ChangeEvent<HTMLTextAreaElement>) => {
|
const handleLicenseInput = (evt: ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
setLicense(evt.target.value);
|
setLicense(evt.target.value);
|
||||||
};
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
if (licenseInfo?.base58) {
|
||||||
|
setLicense(licenseInfo.base58);
|
||||||
|
}
|
||||||
|
}, [licenseInfo]);
|
||||||
|
|
||||||
|
const disableBtn = checking || upserting || !license || license === licenseInfo?.base58;
|
||||||
|
console.log("ddd", licenseInfo);
|
||||||
|
|
||||||
const disableBtn = checking || upserting || !license;
|
|
||||||
return (
|
return (
|
||||||
<Styled>
|
<Styled>
|
||||||
<div className="input">
|
<div className="input">
|
||||||
<Textarea rows={10} id="license" value={license} onChange={handleLicenseInput} />
|
<Tippy
|
||||||
|
placement="right-start"
|
||||||
|
visible={!!licenseInfo}
|
||||||
|
content={
|
||||||
|
<StyledInfo>
|
||||||
|
<div className="item">
|
||||||
|
<span className="label">Signed</span>
|
||||||
|
<span className="info">{licenseInfo?.sign ? "Yes" : "Not Yet"}</span>
|
||||||
|
</div>
|
||||||
|
<div className="item">
|
||||||
|
<span className="label">Domains</span>
|
||||||
|
<span className="info"> {licenseInfo?.domains.join(",")}</span>
|
||||||
|
</div>
|
||||||
|
<div className="item">
|
||||||
|
<span className="label">User Limit</span>
|
||||||
|
<span className="info"> {licenseInfo?.user_limit}</span>
|
||||||
|
</div>
|
||||||
|
<div className="item">
|
||||||
|
<span className="label">Expired At</span>
|
||||||
|
<span className="info">
|
||||||
|
{dayjs(licenseInfo?.expired_at).format("YYYY-MM-DD h:mm:ss A")}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="item">
|
||||||
|
<span className="label">Created At</span>
|
||||||
|
<span className="info">
|
||||||
|
{dayjs(licenseInfo?.created_at).format("YYYY-MM-DD h:mm:ss A")}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</StyledInfo>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Textarea rows={15} id="license" value={license} onChange={handleLicenseInput} />
|
||||||
|
</Tippy>
|
||||||
</div>
|
</div>
|
||||||
<Tippy
|
<Tippy
|
||||||
interactive
|
interactive
|
||||||
@@ -89,7 +158,7 @@ export default function License() {
|
|||||||
</StyledConfirm>
|
</StyledConfirm>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Button disabled={disableBtn}>Save License</Button>
|
<Button disabled={disableBtn}>Update License</Button>
|
||||||
</Tippy>
|
</Tippy>
|
||||||
</Styled>
|
</Styled>
|
||||||
);
|
);
|
||||||
|
|||||||
+3
-1
@@ -59,10 +59,12 @@ export interface LoginConfig {
|
|||||||
third_party: boolean;
|
third_party: boolean;
|
||||||
}
|
}
|
||||||
export interface LicenseResponse {
|
export interface LicenseResponse {
|
||||||
domain: string;
|
domains: string[];
|
||||||
created_at: string;
|
created_at: string;
|
||||||
expired_at: string;
|
expired_at: string;
|
||||||
sign: boolean;
|
sign: boolean;
|
||||||
|
base58: string;
|
||||||
|
user_limit: number;
|
||||||
}
|
}
|
||||||
export interface CreateAdminDTO extends Pick<User, "email" | "name" | "gender"> {
|
export interface CreateAdminDTO extends Pick<User, "email" | "name" | "gender"> {
|
||||||
password: string;
|
password: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user