Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(i18n): add time limit tip on join room #2104

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions desktop/renderer-app/src/pages/utils/join-room-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export const joinRoomHandler = async (
new Error("failed to join room: incorrect room type");
}
}

if (data.billing && data.billing.vipLevel === 0) {
void message.info(
FlatI18n.t("time-limit-tip", {
roomType: FlatI18n.t("vip-level." + data.billing.vipLevel),
minutes: data.billing.limit,
}),
);
}
} catch (e) {
// if room not found and is pmi room, show wait for teacher to enter
if (e.message.includes(RequestErrorCode.RoomNotFoundAndIsPmi)) {
Expand All @@ -43,5 +52,7 @@ export const joinRoomHandler = async (
}
pushHistory(RouteNameType.HomePage);
errorTips(e);

globalStore.setRequestRefreshRooms(true);
}
};
12 changes: 9 additions & 3 deletions packages/flat-i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,15 @@
"bad-request": "Bad request",
"jwt-verify-failed": "Login verify failed",
"forward-failed": "Request failed",
"the-room-is-full": "The room is full",
"the-room-is-expired": "The room has expired",
"the-room-is-not-started-yet": "The room has not started yet",
"rooms-has-reached-the-limit": "You have reached the limit of creating rooms this month, upgrade your account to create more rooms",
"the-room-is-full": "The room is full, please try again later or contact the owner",
"the-room-is-expired": "The room has ended",
"the-room-is-not-started-yet": "The room has not started yet, please try again later",
"time-limit-tip": "This {{roomType}} room has a limit of {{minutes}} minutes",
"vip-level": {
"0": "free",
"1": ""
},
"members": "Members",
"staging": "On Stage",
"stage-on": "You are on stage",
Expand Down
10 changes: 8 additions & 2 deletions packages/flat-i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,15 @@
"bad-request": "请求参数错误",
"jwt-verify-failed": "登录信息获取失败",
"forward-failed": "请求出错",
"the-room-is-full": "房间人数已达上限",
"rooms-has-reached-the-limit": "本月创建免费房间个数已达上限,升级版本享受更多权益",
"the-room-is-full": "免费版房间人数已达上限,暂时无法加入,请联系老师解决",
"the-room-is-expired": "房间已结束",
"the-room-is-not-started-yet": "房间还未开始",
"the-room-is-not-started-yet": "房间未开始,开课前 5 分钟可进入,已将该房间添加到房间列表",
"time-limit-tip": "你已加入{{roomType}} {{minutes}} 分钟限时房间",
"vip-level": {
"0": "免费版",
"1": "专业版"
},
"members": "学生",
"staging": "上/下台",
"stage-on": "你已上台",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
PmiDesc,
PmiExistTip,
Region,
errorTips,
formatInviteCode,
} from "flat-components";
import { Input, Modal, Checkbox, Form, InputRef, Dropdown, message, Button } from "antd";
Expand Down Expand Up @@ -290,6 +291,7 @@ export const CreateRoomBox = observer<CreateRoomBoxProps>(function CreateRoomBox
showModal(false);
} catch (e) {
console.error(e);
errorTips(e);
setLoading(false);
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/flat-pages/src/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ export const HomePage = observer(function HomePage() {
};
}, [refreshRooms, isLogin]);

useEffect(() => {
if (!isLogin) {
return;
}

if (globalStore.requestRefreshRooms) {
void refreshRooms();
void globalStore.updatePmiRoomList();
globalStore.setRequestRefreshRooms(false);
}
}, [refreshRooms, isLogin, globalStore.requestRefreshRooms]);

return (
<div className="homepage-layout-horizontal-container">
<MainRoomMenu />
Expand Down
11 changes: 11 additions & 0 deletions packages/flat-pages/src/utils/join-room-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export const joinRoomHandler = async (
new Error("failed to join room: incorrect room type");
}
}

if (data.billing && data.billing.vipLevel === 0) {
void message.info(
FlatI18n.t("time-limit-tip", {
roomType: FlatI18n.t("vip-level." + data.billing.vipLevel),
minutes: data.billing.limit,
}),
);
}
} catch (e) {
// if room not found and is pmi room, show wait for teacher to enter
if (e.message.includes(RequestErrorCode.RoomNotFoundAndIsPmi)) {
Expand All @@ -46,5 +55,7 @@ export const joinRoomHandler = async (
}
pushHistory(RouteNameType.HomePage);
errorTips(e);

globalStore.setRequestRefreshRooms(true);
}
};
6 changes: 4 additions & 2 deletions packages/flat-server-api/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export enum RequestErrorCode {

BadRequest = 210000, // bad request
JWTVerifyFailed, // jwt verify failed
RoomLimit, // join room reach max user limit
RoomUserLimit, // join room reach max user limit
RoomExpired, // room expired
RoomNotBegin, // join room before begin_time
RoomCreateLimit, // create room reach max limit

InternalError = 220000, // unknown error
ForwardFailed, // forward failed
Expand Down Expand Up @@ -117,9 +118,10 @@ export const RequestErrorMessage = {

[RequestErrorCode.BadRequest]: "bad-request",
[RequestErrorCode.JWTVerifyFailed]: "jwt-verify-failed",
[RequestErrorCode.RoomLimit]: "the-room-is-full",
[RequestErrorCode.RoomUserLimit]: "the-room-is-full",
[RequestErrorCode.RoomExpired]: "the-room-is-expired",
[RequestErrorCode.RoomNotBegin]: "the-room-is-not-started-yet",
[RequestErrorCode.RoomCreateLimit]: "rooms-has-reached-the-limit",

[RequestErrorCode.InternalError]: "unknown-error",
[RequestErrorCode.ForwardFailed]: "forward-failed",
Expand Down
7 changes: 5 additions & 2 deletions packages/flat-server-api/src/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ export interface JoinRoomResult {
showGuide: boolean;
region: Region;
billing?: {
expireAt: string;
/** minutes */
limit: number;
createdAt: number;
expireAt: number;
maxUser: number;
vipLevel: number; // 0 = normal, 1 = pro
vipLevel: 0 | 1; // 0 = normal, 1 = pro
};
}

Expand Down
6 changes: 6 additions & 0 deletions packages/flat-stores/src/global-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class GlobalStore {
public pmi: string | null = null;
public pmiRoomList: PmiRoom[] | null = [];

public requestRefreshRooms = false;

// login with password
public currentAccount: Account | null = null;
public accountHistory: Account[] = [];
Expand Down Expand Up @@ -319,6 +321,10 @@ export class GlobalStore {
public updateServerRegionConfig = (config: ServerRegionConfig | null): void => {
this.serverRegionConfig = config;
};

public setRequestRefreshRooms(value = true): void {
this.requestRefreshRooms = value;
}
}

export const globalStore = new GlobalStore();
Expand Down