Add possibility to invite members to workspace (#579)
* Add possibility to invite members to workspace * Update endpoints * Wrap up front end * Fix according to review * Fix lint
This commit is contained in:
@ -1,7 +1,12 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { useChallengeMutation, useVerifyMutation } from '~/generated/graphql';
|
||||
import {
|
||||
useChallengeMutation,
|
||||
useSignUpMutation,
|
||||
useSignUpToWorkspaceMutation,
|
||||
useVerifyMutation,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
import { currentUserState } from '../states/currentUserState';
|
||||
import { isAuthenticatingState } from '../states/isAuthenticatingState';
|
||||
@ -13,6 +18,8 @@ export function useAuth() {
|
||||
const [, setIsAuthenticating] = useRecoilState(isAuthenticatingState);
|
||||
|
||||
const [challenge] = useChallengeMutation();
|
||||
const [signUp] = useSignUpMutation();
|
||||
const [SignUpToWorkspace] = useSignUpToWorkspaceMutation();
|
||||
const [verify] = useVerifyMutation();
|
||||
|
||||
const handleChallenge = useCallback(
|
||||
@ -74,10 +81,57 @@ export function useAuth() {
|
||||
setTokenPair(null);
|
||||
}, [setTokenPair]);
|
||||
|
||||
const handleSignUp = useCallback(
|
||||
async (email: string, password: string) => {
|
||||
const signUpResult = await signUp({
|
||||
variables: {
|
||||
email,
|
||||
password,
|
||||
},
|
||||
});
|
||||
|
||||
if (signUpResult.errors) {
|
||||
throw signUpResult.errors;
|
||||
}
|
||||
|
||||
if (!signUpResult.data?.signUp) {
|
||||
throw new Error('No login token');
|
||||
}
|
||||
|
||||
await handleVerify(signUpResult.data?.signUp.loginToken.token);
|
||||
},
|
||||
[signUp, handleVerify],
|
||||
);
|
||||
|
||||
const handleSignUpToWorkspace = useCallback(
|
||||
async (email: string, password: string, workspaceInviteHash: string) => {
|
||||
const signUpResult = await SignUpToWorkspace({
|
||||
variables: {
|
||||
email,
|
||||
password,
|
||||
workspaceInviteHash,
|
||||
},
|
||||
});
|
||||
|
||||
if (signUpResult.errors) {
|
||||
throw signUpResult.errors;
|
||||
}
|
||||
|
||||
if (!signUpResult.data?.signUp) {
|
||||
throw new Error('No login token');
|
||||
}
|
||||
|
||||
await handleVerify(signUpResult.data?.signUp.loginToken.token);
|
||||
},
|
||||
[SignUpToWorkspace, handleVerify],
|
||||
);
|
||||
|
||||
return {
|
||||
challenge: handleChallenge,
|
||||
verify: handleVerify,
|
||||
login: handleLogin,
|
||||
signUp: handleSignUp,
|
||||
signUpToWorkspace: handleSignUpToWorkspace,
|
||||
logout: handleLogout,
|
||||
};
|
||||
}
|
||||
|
||||
@ -11,6 +11,36 @@ export const CHALLENGE = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
export const SIGN_UP = gql`
|
||||
mutation SignUp($email: String!, $password: String!) {
|
||||
signUp(email: $email, password: $password) {
|
||||
loginToken {
|
||||
expiresAt
|
||||
token
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const SIGN_UP_TO_WORKSPACE = gql`
|
||||
mutation SignUpToWorkspace(
|
||||
$email: String!
|
||||
$password: String!
|
||||
$workspaceInviteHash: String!
|
||||
) {
|
||||
signUp(
|
||||
email: $email
|
||||
password: $password
|
||||
workspaceInviteHash: $workspaceInviteHash
|
||||
) {
|
||||
loginToken {
|
||||
expiresAt
|
||||
token
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const VERIFY = gql`
|
||||
mutation Verify($loginToken: String!) {
|
||||
verify(loginToken: $loginToken) {
|
||||
|
||||
@ -130,10 +130,10 @@ export function CommentThread({
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (commentThread) {
|
||||
if (commentThread && !title) {
|
||||
setTitle(commentThread?.title ?? '');
|
||||
}
|
||||
}, [commentThread]);
|
||||
}, [commentThread, title]);
|
||||
|
||||
if (!commentThread) {
|
||||
return <></>;
|
||||
|
||||
Reference in New Issue
Block a user