diff --git a/shared/i18n/langs/en-US/translation.json b/shared/i18n/langs/en-US/translation.json index 49c0c303..4d83b7c7 100644 --- a/shared/i18n/langs/en-US/translation.json +++ b/shared/i18n/langs/en-US/translation.json @@ -225,6 +225,7 @@ "keda14478": "You are the group manager, leaving the group will cause the group to be dissolved", "kee9108f1": "Modify success", "kef25594f": "Nickname#0000", + "kef3676e1": "The invitation code has expired", "kefaf9956": "Created", "kefc07278": "Back to login", "kf02c6db": "Friend List", diff --git a/shared/i18n/langs/zh-CN/translation.json b/shared/i18n/langs/zh-CN/translation.json index 116aef33..813993d1 100644 --- a/shared/i18n/langs/zh-CN/translation.json +++ b/shared/i18n/langs/zh-CN/translation.json @@ -225,6 +225,7 @@ "keda14478": "您是群组管理者,退出群组会导致解散群组", "kee9108f1": "修改成功", "kef25594f": "用户昵称#0000", + "kef3676e1": "该邀请码已过期", "kefaf9956": "创建时间", "kefc07278": "返回登录", "kf02c6db": "好友列表", diff --git a/web/src/components/InviteCodeExpiredAt.tsx b/web/src/components/InviteCodeExpiredAt.tsx index deea6ebc..8834926d 100644 --- a/web/src/components/InviteCodeExpiredAt.tsx +++ b/web/src/components/InviteCodeExpiredAt.tsx @@ -19,6 +19,10 @@ export const InviteCodeExpiredAt: React.FC = return t('该邀请码永不过期'); } + if (new Date(invite.expiredAt).valueOf() < Date.now()) { + return t('该邀请码已过期'); + } + return ( 该邀请将于{' '} diff --git a/web/src/routes/Invite/InviteInfo.tsx b/web/src/routes/Invite/InviteInfo.tsx index baff8c1c..ee51b203 100644 --- a/web/src/routes/Invite/InviteInfo.tsx +++ b/web/src/routes/Invite/InviteInfo.tsx @@ -2,16 +2,16 @@ import { Avatar } from '@/components/Avatar'; import { InviteCodeExpiredAt } from '@/components/InviteCodeExpiredAt'; import { LoadingSpinner } from '@/components/LoadingSpinner'; import { UserName } from '@/components/UserName'; +import { Divider } from 'antd'; import React from 'react'; import { - datetimeFromNow, getCachedGroupInviteInfo, getGroupBasicInfo, showErrorToasts, t, - Trans, useAsync, } from 'tailchat-shared'; +import { JoinBtn } from './JoinBtn'; interface Props { inviteCode: string; @@ -19,7 +19,7 @@ interface Props { export const InviteInfo: React.FC = React.memo((props) => { const { inviteCode } = props; - const { loading, value } = useAsync(async () => { + const { loading, value: inviteInfo } = useAsync(async () => { try { const invite = await getCachedGroupInviteInfo(inviteCode); if (invite === null) { @@ -44,36 +44,42 @@ export const InviteInfo: React.FC = React.memo((props) => { return ; } - if (!value) { + if (!inviteInfo) { return
{t('群组信息加载失败')}
; } return ( -
-
- -
-
- {' '} - {t('邀请您加入群组')} -
-
{value.group.name}
-
- {t('当前成员数')}: {value.group.memberCount} -
- - {/* 永久邀请码不显示过期时间 */} - {value.expired && ( + <> +
+
+ +
- + {' '} + {t('邀请您加入群组')}
- )} -
+
{inviteInfo.group.name}
+
+ {t('当前成员数')}: {inviteInfo.group.memberCount} +
+ + {/* 永久邀请码不显示过期时间 */} + {inviteInfo.expired && ( +
+ +
+ )} +
+ + + + + ); }); InviteInfo.displayName = 'InviteInfo'; diff --git a/web/src/routes/Invite/JoinBtn.tsx b/web/src/routes/Invite/JoinBtn.tsx index 1a712029..3441da50 100644 --- a/web/src/routes/Invite/JoinBtn.tsx +++ b/web/src/routes/Invite/JoinBtn.tsx @@ -7,7 +7,6 @@ import { applyGroupInvite, checkTokenValid, getCachedGroupInviteInfo, - showToasts, t, useAsync, useAsyncRequest, @@ -16,6 +15,7 @@ import { SuccessModal } from './SuccessModal'; interface Props { inviteCode: string; + expired?: string; } export const JoinBtn: React.FC = React.memo((props) => { const history = useHistory(); @@ -55,6 +55,14 @@ export const JoinBtn: React.FC = React.memo((props) => { ); } + if (props.expired && new Date(props.expired).valueOf() < Date.now()) { + return ( + + ); + } + return isTokenValid ? (