mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-30 05:34:21 +03:00
feat: mock invite
This commit is contained in:
parent
e3c1e6a5da
commit
c0c167fea8
@ -6,6 +6,7 @@ import Input from '@/ui/input';
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { getDataCenter } from '@affine/datacenter';
|
import { getDataCenter } from '@affine/datacenter';
|
||||||
import { Avatar } from '@mui/material';
|
import { Avatar } from '@mui/material';
|
||||||
|
import { setMember } from '@/hooks/mock-data/mock';
|
||||||
interface LoginModalProps {
|
interface LoginModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
@ -54,29 +55,34 @@ export const InviteMembers = ({
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const [userData, setUserData] = useState<any>({});
|
const [userData, setUserData] = useState<any>({});
|
||||||
const inputChange = (value: string) => {
|
const inputChange = (value: string) => {
|
||||||
setEmail(value);
|
|
||||||
setShowMember(true);
|
setShowMember(true);
|
||||||
if (gmailReg.test(value)) {
|
if (gmailReg.test(value)) {
|
||||||
|
setEmail(value);
|
||||||
setShowTip(false);
|
setShowTip(false);
|
||||||
debounce(
|
setUserData({
|
||||||
() => {
|
name: 'wxl',
|
||||||
getDataCenter()
|
avatar: 'https://avatars.githubusercontent.com/u/20501502?v=4',
|
||||||
.then(dc =>
|
email: value,
|
||||||
dc.apis.getUserByEmail({
|
});
|
||||||
email: value,
|
// debounce(
|
||||||
workspace_id: workspaceId,
|
// () => {
|
||||||
})
|
// getDataCenter()
|
||||||
)
|
// .then(dc =>
|
||||||
.then(data => {
|
// dc.apis.getUserByEmail({
|
||||||
if (data?.name) {
|
// email: value,
|
||||||
setUserData(data);
|
// workspace_id: workspaceId,
|
||||||
setShowTip(false);
|
// })
|
||||||
}
|
// )
|
||||||
});
|
// .then(data => {
|
||||||
},
|
// if (data?.name) {
|
||||||
300,
|
// setUserData(data);
|
||||||
true
|
// setShowTip(false);
|
||||||
)();
|
// }
|
||||||
|
// });
|
||||||
|
// },
|
||||||
|
// 300,
|
||||||
|
// true
|
||||||
|
// )();
|
||||||
} else {
|
} else {
|
||||||
setShowTip(true);
|
setShowTip(true);
|
||||||
}
|
}
|
||||||
@ -134,16 +140,18 @@ export const InviteMembers = ({
|
|||||||
shape="circle"
|
shape="circle"
|
||||||
type="primary"
|
type="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
getDataCenter()
|
setMember(workspaceId, userData);
|
||||||
.then(dc => dc.apis.inviteMember({ id: workspaceId, email }))
|
onInviteSuccess();
|
||||||
.then(() => {
|
// getDataCenter()
|
||||||
onClose();
|
// .then(dc => dc.apis.inviteMember({ id: workspaceId, email }))
|
||||||
onInviteSuccess && onInviteSuccess();
|
// .then(() => {
|
||||||
})
|
// onClose();
|
||||||
.catch(err => {
|
// onInviteSuccess && onInviteSuccess();
|
||||||
// toast('Invite failed');
|
// })
|
||||||
console.log(err);
|
// .catch(err => {
|
||||||
});
|
// // toast('Invite failed');
|
||||||
|
// console.log(err);
|
||||||
|
// });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Invite
|
Invite
|
||||||
|
@ -44,7 +44,9 @@ import { Empty } from '@/ui/empty';
|
|||||||
import { useAppState } from '@/providers/app-state-provider';
|
import { useAppState } from '@/providers/app-state-provider';
|
||||||
import { GeneralPage } from './general';
|
import { GeneralPage } from './general';
|
||||||
import {
|
import {
|
||||||
|
deleteMember,
|
||||||
getActiveWorkspace,
|
getActiveWorkspace,
|
||||||
|
getMembers,
|
||||||
getUserInfo,
|
getUserInfo,
|
||||||
Login,
|
Login,
|
||||||
setWorkspacePublish,
|
setWorkspacePublish,
|
||||||
@ -162,7 +164,7 @@ export const WorkspaceSetting = ({
|
|||||||
|
|
||||||
const MembersPage = ({ workspace }: { workspace: Workspace }) => {
|
const MembersPage = ({ workspace }: { workspace: Workspace }) => {
|
||||||
const [isInviteModalShow, setIsInviteModalShow] = useState(false);
|
const [isInviteModalShow, setIsInviteModalShow] = useState(false);
|
||||||
const [members, setMembers] = useState<Member[]>([]);
|
const [members, setMembers] = useState<User[]>([]);
|
||||||
const [userInfo, setUserInfo] = useState<User>();
|
const [userInfo, setUserInfo] = useState<User>();
|
||||||
// const refreshMembers = useCallback(() => {
|
// const refreshMembers = useCallback(() => {
|
||||||
// getDataCenter()
|
// getDataCenter()
|
||||||
@ -181,6 +183,7 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setUser();
|
setUser();
|
||||||
|
setMembersList();
|
||||||
// refreshMembers();
|
// refreshMembers();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -188,6 +191,10 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => {
|
|||||||
const user = getUserInfo();
|
const user = getUserInfo();
|
||||||
user && setUserInfo(user);
|
user && setUserInfo(user);
|
||||||
};
|
};
|
||||||
|
const setMembersList = () => {
|
||||||
|
const members = getMembers(workspace.id);
|
||||||
|
members && setMembers(members);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -212,33 +219,23 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => {
|
|||||||
return (
|
return (
|
||||||
<StyledMemberListItem key={member.id}>
|
<StyledMemberListItem key={member.id}>
|
||||||
<StyledMemberNameContainer>
|
<StyledMemberNameContainer>
|
||||||
{member.user.type === 'Registered' ? (
|
<StyledMemberAvatar alt="member avatar">
|
||||||
<Avatar src={member.user.avatar_url}></Avatar>
|
<EmailIcon></EmailIcon>
|
||||||
) : (
|
</StyledMemberAvatar>
|
||||||
<StyledMemberAvatar alt="member avatar">
|
|
||||||
<EmailIcon></EmailIcon>
|
|
||||||
</StyledMemberAvatar>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<StyledMemberInfo>
|
<StyledMemberInfo>
|
||||||
{member.user.type === 'Registered' ? (
|
<StyledMemberName>{member.name}</StyledMemberName>
|
||||||
<StyledMemberName>
|
|
||||||
{member.user.name}
|
<StyledMemberEmail>{member.email}</StyledMemberEmail>
|
||||||
</StyledMemberName>
|
|
||||||
) : (
|
|
||||||
<></>
|
|
||||||
)}
|
|
||||||
<StyledMemberEmail>
|
|
||||||
{member.user.email}
|
|
||||||
</StyledMemberEmail>
|
|
||||||
</StyledMemberInfo>
|
</StyledMemberInfo>
|
||||||
</StyledMemberNameContainer>
|
</StyledMemberNameContainer>
|
||||||
<StyledMemberRoleContainer>
|
<StyledMemberRoleContainer>
|
||||||
{member.accepted
|
{/* {member.accepted
|
||||||
? member.type !== 99
|
? member.type !== 99
|
||||||
? 'Member'
|
? 'Member'
|
||||||
: 'Workspace Owner'
|
: 'Workspace Owner'
|
||||||
: 'Pending'}
|
: 'Pending'} */}
|
||||||
|
Pending
|
||||||
</StyledMemberRoleContainer>
|
</StyledMemberRoleContainer>
|
||||||
<StyledMoreVerticalButton>
|
<StyledMoreVerticalButton>
|
||||||
<Menu
|
<Menu
|
||||||
@ -246,23 +243,25 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => {
|
|||||||
<>
|
<>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
deleteMember(workspace.id, 0);
|
||||||
|
setMembersList();
|
||||||
// confirm({
|
// confirm({
|
||||||
// title: 'Delete Member?',
|
// title: 'Delete Member?',
|
||||||
// content: `will delete member`,
|
// content: `will delete member`,
|
||||||
// confirmText: 'Delete',
|
// confirmText: 'Delete',
|
||||||
// confirmType: 'danger',
|
// confirmType: 'danger',
|
||||||
// }).then(confirm => {
|
// }).then(confirm => {
|
||||||
getDataCenter()
|
// getDataCenter()
|
||||||
.then(dc =>
|
// .then(dc =>
|
||||||
dc.apis.removeMember({
|
// dc.apis.removeMember({
|
||||||
permissionId: member.id,
|
// permissionId: member.id,
|
||||||
})
|
// })
|
||||||
)
|
// )
|
||||||
.then(() => {
|
// .then(() => {
|
||||||
// console.log('data: ', data);
|
// // console.log('data: ', data);
|
||||||
toast('Moved to Trash');
|
// toast('Moved to Trash');
|
||||||
// refreshMembers();
|
// // refreshMembers();
|
||||||
});
|
// });
|
||||||
// });
|
// });
|
||||||
}}
|
}}
|
||||||
icon={<TrashIcon />}
|
icon={<TrashIcon />}
|
||||||
@ -301,6 +300,8 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => {
|
|||||||
setIsInviteModalShow(false);
|
setIsInviteModalShow(false);
|
||||||
}}
|
}}
|
||||||
onInviteSuccess={() => {
|
onInviteSuccess={() => {
|
||||||
|
setMembersList();
|
||||||
|
setIsInviteModalShow(false);
|
||||||
// refreshMembers();
|
// refreshMembers();
|
||||||
}}
|
}}
|
||||||
workspaceId={workspace.id}
|
workspaceId={workspace.id}
|
||||||
|
@ -27,8 +27,7 @@ type SelectorPopperContentProps = {
|
|||||||
export const SelectorPopperContent = ({
|
export const SelectorPopperContent = ({
|
||||||
isShow,
|
isShow,
|
||||||
}: SelectorPopperContentProps) => {
|
}: SelectorPopperContentProps) => {
|
||||||
const { user, workspacesMeta, workspaces, refreshWorkspacesMeta } =
|
const { user, workspacesMeta, refreshWorkspacesMeta } = useAppState();
|
||||||
useAppState();
|
|
||||||
const [settingWorkspaceId, setSettingWorkspaceId] = useState<string | null>(
|
const [settingWorkspaceId, setSettingWorkspaceId] = useState<string | null>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
@ -115,13 +114,9 @@ export const SelectorPopperContent = ({
|
|||||||
type={workspace.type}
|
type={workspace.type}
|
||||||
key={workspace.id}
|
key={workspace.id}
|
||||||
id={workspace.id}
|
id={workspace.id}
|
||||||
icon={
|
icon={`loading...`}
|
||||||
(workspaces[workspace.id]?.meta.avatar &&
|
|
||||||
`/api/blob/${workspaces[workspace.id]?.meta.avatar}`) ||
|
|
||||||
`loading...`
|
|
||||||
}
|
|
||||||
onClickSetting={handleClickSettingWorkspace}
|
onClickSetting={handleClickSettingWorkspace}
|
||||||
name={workspaces[workspace.id]?.meta.name || `loading...`}
|
name={`loading...`}
|
||||||
memberCount={workSpaceDetails[workspace.id]?.memberCount || 1}
|
memberCount={workSpaceDetails[workspace.id]?.memberCount || 1}
|
||||||
/>
|
/>
|
||||||
) : null;
|
) : null;
|
||||||
|
@ -69,6 +69,20 @@ export function getMembers(id: string): User[] {
|
|||||||
return memberMap[id] || [];
|
return memberMap[id] || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setMember(workspaceId: string, member: User) {
|
||||||
|
const memberMap = JSON.parse(localStorage.getItem('affine-member') ?? '{}');
|
||||||
|
memberMap[workspaceId] = memberMap[workspaceId] || [];
|
||||||
|
memberMap[workspaceId].push(member);
|
||||||
|
localStorage.setItem('affine-member', JSON.stringify(memberMap));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteMember(workspaceId: string, index: number) {
|
||||||
|
const memberMap = JSON.parse(localStorage.getItem('affine-member') ?? '{}');
|
||||||
|
const memberList = memberMap[workspaceId];
|
||||||
|
memberList.splice(index, 1);
|
||||||
|
memberMap[workspaceId] = memberList;
|
||||||
|
localStorage.setItem('affine-member', JSON.stringify(memberMap));
|
||||||
|
}
|
||||||
export function leaveWorkspace(id: string) {
|
export function leaveWorkspace(id: string) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user