feat: add create invite code edited data update. now can review changed info

pull/109/head
moonrailgun 2 years ago
parent b6e978e569
commit f44a5c9ec0

@ -44,6 +44,7 @@
"k250e392c": "System is busy, please try again later", "k250e392c": "System is busy, please try again later",
"k263bff41": "Edit invite link", "k263bff41": "Edit invite link",
"k267cc491": "Me", "k267cc491": "Me",
"k29498d11": "Can be used <2>{{num}}</2> times",
"k2a1422d2": "Configuration", "k2a1422d2": "Configuration",
"k2a8031e": "Homepage", "k2a8031e": "Homepage",
"k2b411a11": "Component can only work in the group panel", "k2b411a11": "Component can only work in the group panel",

@ -44,6 +44,7 @@
"k250e392c": "系统忙, 请稍后再试", "k250e392c": "系统忙, 请稍后再试",
"k263bff41": "编辑邀请链接", "k263bff41": "编辑邀请链接",
"k267cc491": "我", "k267cc491": "我",
"k29498d11": "可使用 <2>{{num}}</2> 次",
"k2a1422d2": "配置", "k2a1422d2": "配置",
"k2a8031e": "个人主页", "k2a8031e": "个人主页",
"k2b411a11": "组件只能在群组面板中才能正常显示", "k2b411a11": "组件只能在群组面板中才能正常显示",

@ -1,4 +1,4 @@
import { Tooltip } from 'antd'; import { Divider, Tooltip } from 'antd';
import React from 'react'; import React from 'react';
import { import {
datetimeFromNow, datetimeFromNow,
@ -9,21 +9,21 @@ import {
} from 'tailchat-shared'; } from 'tailchat-shared';
interface InviteCodeExpiredAtProps { interface InviteCodeExpiredAtProps {
invite: Pick<GroupInvite, 'expiredAt'>; invite: Pick<GroupInvite, 'expiredAt' | 'usageLimit'>;
} }
export const InviteCodeExpiredAt: React.FC<InviteCodeExpiredAtProps> = export const InviteCodeExpiredAt: React.FC<InviteCodeExpiredAtProps> =
React.memo((props) => { React.memo((props) => {
const { invite } = props; const { invite } = props;
if (!invite.expiredAt) { if (invite.expiredAt && new Date(invite.expiredAt).valueOf() < Date.now()) {
return <span>{t('该邀请码永不过期')}</span>;
}
if (new Date(invite.expiredAt).valueOf() < Date.now()) {
return <span>{t('该邀请码已过期')}</span>; return <span>{t('该邀请码已过期')}</span>;
} }
return ( return (
<>
{!invite.expiredAt ? (
<span>{t('该邀请码永不过期')}</span>
) : (
<Trans> <Trans>
{' '} {' '}
<Tooltip title={formatFullTime(invite.expiredAt)}> <Tooltip title={formatFullTime(invite.expiredAt)}>
@ -33,6 +33,22 @@ export const InviteCodeExpiredAt: React.FC<InviteCodeExpiredAtProps> =
</Tooltip>{' '} </Tooltip>{' '}
</Trans> </Trans>
)}
{invite.usageLimit && (
<>
<Divider type="vertical" />
<Trans>
使{' '}
<span className="font-bold">
{{ num: invite.usageLimit } as any}
</span>{' '}
</Trans>
</>
)}
</>
); );
}); });
InviteCodeExpiredAt.displayName = 'InviteCodeExpiredAt'; InviteCodeExpiredAt.displayName = 'InviteCodeExpiredAt';

@ -51,8 +51,18 @@ export const CreateInviteCode: React.FC<CreateInviteCodeProps> = React.memo(
<EditGroupInvite <EditGroupInvite
groupId={groupId} groupId={groupId}
code={createdInvite.code} code={createdInvite.code}
onEditSuccess={() => { onEditSuccess={({ expiredAt, usageLimit }) => {
showToasts(t('邀请设置修改成功'), 'success'); showToasts(t('邀请设置修改成功'), 'success');
setCreateInvite(
(state) =>
({
...state,
expiredAt: expiredAt
? new Date(expiredAt).toISOString()
: undefined,
usageLimit: usageLimit,
} as any)
);
closeModal(key); closeModal(key);
}} }}
/> />

@ -90,21 +90,30 @@ const fields: MetaFormFieldMeta[] = [
interface EditGroupInviteProps { interface EditGroupInviteProps {
groupId: string; groupId: string;
code: string; code: string;
onEditSuccess: () => void; onEditSuccess: (info: {
expiredAt: number | undefined;
usageLimit: number | undefined;
}) => void;
} }
export const EditGroupInvite: React.FC<EditGroupInviteProps> = React.memo( export const EditGroupInvite: React.FC<EditGroupInviteProps> = React.memo(
(props) => { (props) => {
const handleEditGroupInvite = useEvent(async (values: MetaFormValues) => { const handleEditGroupInvite = useEvent(async (values: MetaFormValues) => {
const expiredAt =
values.expiredAt === -1
? undefined
: Date.now() + values.expiredAt * 1000;
const usageLimit =
values.usageLimit === -1 ? undefined : values.usageLimit;
await model.group.editGroupInvite( await model.group.editGroupInvite(
props.groupId, props.groupId,
props.code, props.code,
values.expiredAt === -1 expiredAt,
? undefined usageLimit
: Date.now() + values.expiredAt * 1000,
values.usageLimit === -1 ? undefined : values.usageLimit
); );
props.onEditSuccess(); props.onEditSuccess({ expiredAt, usageLimit });
}); });
return ( return (

Loading…
Cancel
Save