Skip to content

Commit

Permalink
fix: failing cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
jainpawan21 committed Mar 19, 2024
1 parent 5a22a1d commit 5b3704b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/pages/auth/InvitationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function InvitationPage() {
useEffect(() => {
// auto accept invitation when logged in as invited user
if (isLoggedInAsInvitedUser) {
submitToken(tokensRef.current.token as string, tokensRef.current.invitationToken as string, true);
submitToken(tokensRef.current.token as string, tokensRef.current.invitationToken as string, true, false);
}
}, [isLoggedInAsInvitedUser, submitToken]);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/pages/auth/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function LoginPage() {
}

if (invitationToken) {
submitToken(token, invitationToken);
submitToken(token, invitationToken, false, false);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/pages/auth/components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function LoginForm({ email, invitationToken }: LoginFormProps) {
}

if (invitationToken) {
submitToken(token, invitationToken);
submitToken(token, invitationToken, false, false);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/pages/auth/components/SignUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function SignUpForm({ invitationToken, email }: SignUpFormProps) {
applyToken(token);

if (invitationToken) {
submitToken(token, invitationToken);
submitToken(token, invitationToken, false, true);
} else {
setToken(token);
}
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/pages/auth/components/useAcceptInvite.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { useCallback } from 'react';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useNavigate } from 'react-router-dom';
import * as Sentry from '@sentry/react';
import type { IResponseError } from '@novu/shared';

import { api } from '../../../api/api.client';
import { useAuthContext } from '../../../components/providers/AuthProvider';
import { applyToken } from '../../../hooks';
import { ROUTES } from '../../../constants/routes.enum';
import { errorMessage } from '../../../utils/notifications';

export function useAcceptInvite() {
const { setToken } = useAuthContext();
const queryClient = useQueryClient();
const navigate = useNavigate();

const { isLoading, mutateAsync, error, isError } = useMutation<string, IResponseError, string>((tokenItem) =>
api.post(`/v1/invites/${tokenItem}/accept`, {})
);

const submitToken = useCallback(
async (token: string, invitationToken: string, refetch = false) => {
async (token: string, invitationToken: string, refetch = false, isSignUp = true) => {
try {
// just set the header, user is logged in after token is submitted
applyToken(token);
Expand All @@ -30,13 +33,18 @@ export function useAcceptInvite() {
predicate: (query) => query.queryKey.includes('/v1/organizations'),
});
}
if (isSignUp) {
navigate(ROUTES.AUTH_APPLICATION);
} else {
navigate(ROUTES.WORKFLOWS);
}
} catch (e: unknown) {
errorMessage('Failed to accept an invite.');

Sentry.captureException(e);
}
},
[mutateAsync, queryClient, setToken]
[mutateAsync, navigate, queryClient, setToken]
);

return {
Expand Down

0 comments on commit 5b3704b

Please sign in to comment.