feat: add license upgrade flag to server

This commit is contained in:
Tristan Yang
2023-03-22 11:32:14 +08:00
parent f67d1a7dc3
commit dba894c7e4
6 changed files with 51 additions and 22 deletions
+6 -3
View File
@@ -11,12 +11,15 @@ let prices: Price[] = [
type: "booking",
}
];
const local_dev = `https://dev.voce.chat`;
const official_dev = `https://dev.voce.chat`;
// const local_dev = `http://07333.qicp.vip:3030`;
const local_dev = official_dev;
// const local_dev = `http://localhost:3333`;
export const BASE_ORIGIN = process.env.REACT_APP_RELEASE
? `${location.origin}`
: local_dev;
export const IS_OFFICIAL_DEMO = BASE_ORIGIN === official_dev;
const BASE_URL = `${BASE_ORIGIN}/api`;
export const getLicensePriceList = () => {
const ps = prices.map((p, idx) => {
@@ -69,7 +72,7 @@ export const PAYMENT_URL_PREFIX =
process.env.NODE_ENV === "production"
? `https://vera.nicegoodthings.com`
: `http://localhost:4000`;
export const CACHE_VERSION = `0.3.33`;
export const CACHE_VERSION = `0.3.36`;
export const GuestRoutes = ["/", "/chat", "/chat/channel/:channel_id"];
export const ContentTypes = {
text: "text/plain",
+19 -2
View File
@@ -1,5 +1,5 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import BASE_URL, { ContentTypes, PAYMENT_URL_PREFIX } from "../config";
import BASE_URL, { ContentTypes, IS_OFFICIAL_DEMO, PAYMENT_URL_PREFIX } from "../config";
import { updateInfo } from "../slices/server";
import baseQuery from "./base.query";
import { RootState } from "../store";
@@ -214,7 +214,24 @@ export const serverApi = createApi({
getLicense: builder.query<LicenseResponse, void>({
query: () => ({
url: `/license`
})
}),
async onQueryStarted(data, { dispatch, queryFulfilled, getState }) {
// vocechat官方demo 则忽略
if (IS_OFFICIAL_DEMO) return;
const rootStore = getState() as RootState;
const { upgraded: prevValue } = rootStore.server;
try {
const { data: { user_limit } } = await queryFulfilled;
const currValue = user_limit > 20;
if (prevValue !== currValue) {
dispatch(updateInfo({ upgraded: currValue }));
}
} catch {
console.error("update license upgraded status failed ");
}
}
}),
getLicensePaymentUrl: builder.mutation<RenewLicenseResponse, RenewLicense>({
+4 -1
View File
@@ -2,6 +2,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { Server } from "../../types/server";
export interface StoredServer extends Server {
upgraded: boolean,
logo: string;
inviteLink?: {
link: string;
@@ -9,6 +10,7 @@ export interface StoredServer extends Server {
};
}
const initialState: StoredServer = {
upgraded: false,
name: "",
description: "",
logo: "",
@@ -27,6 +29,7 @@ const serverSlice = createSlice({
},
fillServer(state, action: PayloadAction<StoredServer>) {
const {
upgraded = false,
inviteLink = {
link: "",
expire: 0
@@ -35,7 +38,7 @@ const serverSlice = createSlice({
name = "",
description = ""
} = action.payload || {};
return { name, logo, description, inviteLink };
return { upgraded, name, logo, description, inviteLink };
},
updateInfo(state, action: PayloadAction<Partial<StoredServer>>) {
const values = action.payload || {};