Skip to content

Commit 75c1631

Browse files
FinleyGec121914yu
authored andcommitted
fix: invite link (#4229)
* fix: invite link * feat: create invite link and copy it directly
1 parent 97a182c commit 75c1631

File tree

6 files changed

+70
-34
lines changed

6 files changed

+70
-34
lines changed

packages/service/support/user/team/invitationLink/schema.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import {
2-
TeamCollectionName,
3-
TeamMemberCollectionName
4-
} from '@fastgpt/global/support/user/team/constant';
1+
import { TeamCollectionName } from '@fastgpt/global/support/user/team/constant';
52
import { connectionMongo, getMongoModel } from '../../../../common/mongo';
63
import { InvitationSchemaType } from './type';
7-
import addDays from 'date-fns/esm/fp/addDays/index.js';
4+
import { randomUUID } from 'crypto';
85
const { Schema } = connectionMongo;
96

107
export const InvitationCollectionName = 'team_invitation_links';
118

129
const InvitationSchema = new Schema({
10+
linkId: {
11+
type: String,
12+
required: true,
13+
unique: true,
14+
default: () => randomUUID()
15+
},
1316
teamId: {
1417
type: Schema.Types.ObjectId,
1518
ref: TeamCollectionName,

packages/service/support/user/team/invitationLink/type.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { TeamMemberSchema } from '@fastgpt/global/support/user/team/type';
22

33
export type InvitationSchemaType = {
44
_id: string;
5+
linkId: string;
56
teamId: string;
67
usedTimesLimit?: number;
78
forbidden?: boolean;
@@ -25,11 +26,10 @@ export type InvitationLinkCreateType = {
2526
expires: InvitationLinkExpiresType;
2627
usedTimesLimit: 1 | -1;
2728
};
28-
export type InvitationLinkUpdateType = Partial<
29-
Omit<InvitationSchemaType, 'members' | 'teamId' | '_id'>
30-
> & {
31-
linkId: string;
32-
};
29+
30+
// export type InvitationLinkUpdateType = Partial<
31+
// Omit<InvitationSchemaType, 'members' | 'teamId' | '_id'>
32+
// >;
3333

3434
export type InvitationInfoType = InvitationSchemaType & {
3535
teamAvatar: string;

projects/app/src/pageComponents/account/team/Invite/CreateInvitationModal.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
2222
import { useTranslation } from 'next-i18next';
2323
import { useForm } from 'react-hook-form';
2424

25-
function CreateInvitationModal({ onClose }: { onClose: () => void }) {
25+
function CreateInvitationModal({ onClose }: { onClose: (linkId?: string) => void }) {
2626
const { t } = useTranslation();
2727
const expiresOptions: Array<{ label: string; value: InvitationLinkExpiresType }> = [
2828
{ label: t('account_team:30mins'), value: '30m' }, // 30 mins
@@ -45,6 +45,9 @@ function CreateInvitationModal({ onClose }: { onClose: () => void }) {
4545
manual: true,
4646
successToast: t('common:common.Create Success'),
4747
errorToast: t('common:common.Create Failed'),
48+
onSuccess: (data) => {
49+
onClose(data);
50+
},
4851
onFinally: () => onClose()
4952
});
5053

@@ -55,7 +58,7 @@ function CreateInvitationModal({ onClose }: { onClose: () => void }) {
5558
iconColor="primary.500"
5659
title={<Box>{t('account_team:create_invitation_link')}</Box>}
5760
>
58-
<ModalCloseButton onClick={onClose} />
61+
<ModalCloseButton onClick={() => onClose()} />
5962
<ModalBody>
6063
<Grid gap={6} templateColumns="max-content 1fr" alignItems="center">
6164
<>
@@ -91,7 +94,7 @@ function CreateInvitationModal({ onClose }: { onClose: () => void }) {
9194
</Grid>
9295
</ModalBody>
9396
<ModalFooter>
94-
<Button isLoading={loading} onClick={onClose} variant="outline">
97+
<Button isLoading={loading} onClick={() => onClose()} variant="outline">
9598
{t('common:common.Cancel')}
9699
</Button>
97100
<Button isLoading={loading} onClick={handleSubmit(createInvitationLink)} ml="4">

projects/app/src/pageComponents/account/team/Invite/InviteModal.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import MemberTag from '@/components/support/user/team/Info/MemberTag';
22
import { useSystemStore } from '@/web/common/system/useSystemStore';
3-
import { getInvitationLinkList, putUpdateInvitationInfo } from '@/web/support/user/team/api';
3+
import { getInvitationLinkList, putForbidInvitationLink } from '@/web/support/user/team/api';
44
import { useUserStore } from '@/web/support/user/useUserStore';
55
import {
66
Box,
@@ -79,18 +79,11 @@ const InviteModal = ({
7979
[copyData]
8080
);
8181

82-
const { runAsync: onForbid, loading: forbiding } = useRequest2(
83-
(linkId: string) =>
84-
putUpdateInvitationInfo({
85-
linkId,
86-
forbidden: true
87-
}),
88-
{
89-
manual: true,
90-
onSuccess: refetchInvitationLinkList,
91-
successToast: t('account_team:forbid_success')
92-
}
93-
);
82+
const { runAsync: onForbid, loading: forbiding } = useRequest2(putForbidInvitationLink, {
83+
manual: true,
84+
onSuccess: refetchInvitationLinkList,
85+
successToast: t('account_team:forbid_success')
86+
});
9487

9588
return (
9689
<MyModal
@@ -134,7 +127,7 @@ const InviteModal = ({
134127
{invitationLinkList?.map((item) => {
135128
const isForbidden = item.forbidden || new Date(item.expires) < new Date();
136129
return (
137-
<Tr key={item._id} overflow={'unset'}>
130+
<Tr key={item.linkId} overflow={'unset'}>
138131
<Td maxW="200px" minW="100px">
139132
{item.description}
140133
</Td>
@@ -209,7 +202,7 @@ const InviteModal = ({
209202
<Button
210203
size="sm"
211204
variant="outline"
212-
onClick={() => onCopy(item._id)}
205+
onClick={() => onCopy(item.linkId)}
213206
color="myGray.900"
214207
>
215208
<Icon name="common/link" w="16px" mr="1" />
@@ -239,7 +232,7 @@ const InviteModal = ({
239232
variant="outline"
240233
colorScheme="red"
241234
onClick={() => {
242-
onForbid(item._id);
235+
onForbid(item.linkId);
243236
onClosePopover();
244237
}}
245238
>
@@ -268,7 +261,17 @@ const InviteModal = ({
268261
</ModalFooter>
269262
{isOpenCreate && (
270263
<CreateInvitationModal
271-
onClose={() => Promise.all([onCloseCreate(), refetchInvitationLinkList()])}
264+
onClose={(linkId?: string) =>
265+
Promise.all([
266+
onCloseCreate(),
267+
refetchInvitationLinkList(),
268+
(() => {
269+
if (linkId) {
270+
onCopy(linkId);
271+
}
272+
})()
273+
])
274+
}
272275
/>
273276
)}
274277
</MyModal>

projects/app/src/web/support/user/team/api.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import type { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fe
2121
import type {
2222
InvitationInfoType,
2323
InvitationLinkCreateType,
24-
InvitationLinkUpdateType,
2524
InvitationType
2625
} from '@fastgpt/service/support/user/team/invitationLink/type';
2726

@@ -64,9 +63,8 @@ export const postAcceptInvitationLink = (linkId: string) =>
6463

6564
export const getInvitationInfo = (linkId: string) =>
6665
GET<InvitationInfoType>(`/proApi/support/user/team/invitationLink/info`, { linkId });
67-
68-
export const putUpdateInvitationInfo = (data: InvitationLinkUpdateType) =>
69-
PUT('/proApi/support/user/team/invitationLink/update', data);
66+
export const putForbidInvitationLink = (linkId: string) =>
67+
PUT<string>(`/proApi/support/user/team/invitationLink/forbid`, { linkId });
7068

7169
/* -------------- team collaborator -------------------- */
7270
export const getTeamClbs = () =>

test/datas/users.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,32 @@ export async function getRootUser(): Promise<parseHeaderCertRet> {
3232
tmbId: tmb?._id
3333
};
3434
}
35+
36+
export async function getUser(username: string): Promise<parseHeaderCertRet> {
37+
const user = await MongoUser.create({
38+
username,
39+
password: '123456'
40+
});
41+
42+
const team = await MongoTeam.create({
43+
name: 'test team',
44+
ownerId: user._id
45+
});
46+
47+
const tmb = await MongoTeamMember.create({
48+
teamId: team._id,
49+
userId: user._id,
50+
status: 'active'
51+
});
52+
53+
return {
54+
userId: user._id,
55+
apikey: '',
56+
appId: '',
57+
authType: AuthUserTypeEnum.token,
58+
isRoot: false,
59+
sourceName: undefined,
60+
teamId: tmb?.teamId,
61+
tmbId: tmb?._id
62+
};
63+
}

0 commit comments

Comments
 (0)