Feat/add invite link (#603)

* Add UI for invite link

* Use invite link

* Isolate link component

* Improve UX
This commit is contained in:
Emilien Chauvet
2023-07-11 13:35:43 -07:00
committed by GitHub
parent 24bc2b72f9
commit 14caaf298a
4 changed files with 68 additions and 2 deletions

View File

@ -3397,7 +3397,7 @@ export type SearchCompanyQuery = { __typename?: 'Query', searchResults: Array<{
export type GetCurrentUserQueryVariables = Exact<{ [key: string]: never; }>;
export type GetCurrentUserQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: string, email: string, displayName: string, firstName?: string | null, lastName?: string | null, avatarUrl?: string | null, workspaceMember?: { __typename?: 'WorkspaceMember', id: string, workspace: { __typename?: 'Workspace', id: string, domainName?: string | null, displayName?: string | null, logo?: string | null } } | null } };
export type GetCurrentUserQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: string, email: string, displayName: string, firstName?: string | null, lastName?: string | null, avatarUrl?: string | null, workspaceMember?: { __typename?: 'WorkspaceMember', id: string, workspace: { __typename?: 'Workspace', id: string, domainName?: string | null, displayName?: string | null, logo?: string | null, inviteHash?: string | null } } | null } };
export type GetUsersQueryVariables = Exact<{ [key: string]: never; }>;
@ -5051,6 +5051,7 @@ export const GetCurrentUserDocument = gql`
domainName
displayName
logo
inviteHash
}
}
}

View File

@ -17,6 +17,7 @@ export const GET_CURRENT_USER = gql`
domainName
displayName
logo
inviteHash
}
}
}

View File

@ -0,0 +1,49 @@
import { useState } from 'react';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Button } from '@/ui/components/buttons/Button';
import { TextInput } from '@/ui/components/inputs/TextInput';
import { IconCheck, IconLink } from '@/ui/icons';
const StyledContainer = styled.div`
align-items: center;
display: flex;
flex-direction: row;
`;
const StyledLinkContainer = styled.div`
flex: 1;
margin-right: ${({ theme }) => theme.spacing(2)};
`;
type OwnProps = {
inviteLink: string;
};
export function WorkspaceInviteLink({ inviteLink }: OwnProps) {
const theme = useTheme();
const [isCopied, setIsCopied] = useState(false);
return (
<StyledContainer>
<StyledLinkContainer>
<TextInput value={inviteLink} disabled fullWidth />
</StyledLinkContainer>
<Button
icon={
isCopied ? (
<IconCheck size={theme.icon.size.md} />
) : (
<IconLink size={theme.icon.size.md} />
)
}
variant="primary"
title={isCopied ? 'Copied' : 'Copy link'}
onClick={() => {
setIsCopied(true);
navigator.clipboard.writeText(inviteLink);
}}
/>
</StyledContainer>
);
}

View File

@ -1,3 +1,4 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { useRecoilState } from 'recoil';
@ -7,6 +8,7 @@ import { MainSectionTitle } from '@/ui/components/section-titles/MainSectionTitl
import { SubSectionTitle } from '@/ui/components/section-titles/SubSectionTitle';
import { IconTrash } from '@/ui/icons';
import { NoTopBarContainer } from '@/ui/layout/containers/NoTopBarContainer';
import { WorkspaceInviteLink } from '@/workspace/components/WorkspaceInviteLink';
import { WorkspaceMemberCard } from '@/workspace/components/WorkspaceMemberCard';
import {
useGetWorkspaceMembersQuery,
@ -32,6 +34,8 @@ const ButtonContainer = styled.div`
export function SettingsWorkspaceMembers() {
const [currentUser] = useRecoilState(currentUserState);
const workspace = currentUser?.workspaceMember?.workspace;
const theme = useTheme();
const { data } = useGetWorkspaceMembersQuery();
@ -74,6 +78,17 @@ export function SettingsWorkspaceMembers() {
<NoTopBarContainer>
<StyledContainer>
<MainSectionTitle>Members</MainSectionTitle>
{workspace?.inviteHash && (
<>
<SubSectionTitle
title="Invite"
description="Send an invitation to use Twenty"
/>
<WorkspaceInviteLink
inviteLink={`${window.location.origin}/auth/invite/${workspace?.inviteHash}`}
/>
</>
)}
<SubSectionTitle
title="Members"
description="Manage the members of your space here"
@ -89,7 +104,7 @@ export function SettingsWorkspaceMembers() {
onClick={() => handleRemoveWorkspaceMember(member.user.id)}
variant="tertiary"
size="small"
icon={<IconTrash size={16} />}
icon={<IconTrash size={theme.icon.size.md} />}
/>
</ButtonContainer>
)