From 3f247b6720880b9d044eb8f78f26a626b353887a Mon Sep 17 00:00:00 2001
From: Tima
Date: Wed, 20 Jun 2018 10:42:54 -0700
Subject: [PATCH] login redirects for invited, existing, new user.
---
api/server/google.ts | 12 ++++++--
api/server/models/EmailTemplate.ts | 6 ++--
app/components/common/LoginButton.tsx | 8 ++---
app/components/teams/InviteMember.tsx | 2 +-
app/pages/invitation.tsx | 44 +++++++++++++++------------
5 files changed, 42 insertions(+), 30 deletions(-)
diff --git a/api/server/google.ts b/api/server/google.ts
index 19517b3f..79408d84 100644
--- a/api/server/google.ts
+++ b/api/server/google.ts
@@ -70,6 +70,12 @@ export default function auth({ ROOT_URL, server }) {
prompt: 'select_account',
};
+ if (req.query && req.query.next && req.query.next.startsWith('/')) {
+ req.session.next_url = req.query.next;
+ } else {
+ req.session.next_url = null;
+ }
+
if (req.query && req.query.invitationToken) {
req.session.invitationToken = req.query.invitationToken;
} else {
@@ -93,15 +99,17 @@ export default function auth({ ROOT_URL, server }) {
if (req.user && req.user.isAdmin) {
res.redirect(`${URL_APP}/admin`);
+ } else if (req.session.next_url) {
+ let redirectUrlAfterLogin;
+ redirectUrlAfterLogin = req.session.next_url;
+ res.redirect(`${URL_APP}${redirectUrlAfterLogin}`);
} else {
let redirectUrlAfterLogin;
-
if (!req.user.defaultTeamSlug) {
redirectUrlAfterLogin = 'settings/create-team';
} else {
redirectUrlAfterLogin = `team/${req.user.defaultTeamSlug}/t/projects`;
}
-
res.redirect(`${URL_APP}/${redirectUrlAfterLogin}`);
}
},
diff --git a/api/server/models/EmailTemplate.ts b/api/server/models/EmailTemplate.ts
index 06763fc0..a86293f7 100644
--- a/api/server/models/EmailTemplate.ts
+++ b/api/server/models/EmailTemplate.ts
@@ -41,7 +41,7 @@ async function insertTemplates() {
If you're interested in hiring our team to build custom SaaS features, please fill out our form
- We hope you like pain.
+ We hope you don't like pain.
Kelly & Timur, Team Async
@@ -49,8 +49,8 @@ async function insertTemplates() {
},
{
name: 'invitation',
- subject: 'Async: Team Invitation',
- message: `You've been invited to join {{teamName}}.
+ subject: 'You are invited to join a team at async-await.com',
+ message: `You've been invited to join {{teamName}}.
Click here to accept the invitation: {{invitationURL}}
`,
},
diff --git a/app/components/common/LoginButton.tsx b/app/components/common/LoginButton.tsx
index e2f98045..49d7580f 100644
--- a/app/components/common/LoginButton.tsx
+++ b/app/components/common/LoginButton.tsx
@@ -1,13 +1,15 @@
import React from 'react';
import Button from '@material-ui/core/Button';
+import env from '../../lib/env';
import { styleLoginButton } from '../../lib/sharedStyles';
// TS errors: https://github.com/mui-org/material-ui/issues/8198
const dev = process.env.NODE_ENV !== 'production';
-const LOGIN_URL = dev ? 'http://localhost:8000' : 'https://saas-api.async-await.com';
+const { PRODUCTION_URL_API } = env;
+const LOGIN_URL = dev ? 'http://localhost:8000' : PRODUCTION_URL_API;
class LoginButton extends React.PureComponent<{ next?: string; invitationToken?: string }> {
render() {
@@ -16,9 +18,7 @@ class LoginButton extends React.PureComponent<{ next?: string; invitationToken?:
let url = `${LOGIN_URL}/auth/google`;
if (next && invitationToken) {
- url += `?next=${url}&invitationToken=${invitationToken}`;
- } else if (next) {
- url += `?next=${url}`;
+ url += `?next=${next}&invitationToken=${invitationToken}`;
}
return (
diff --git a/app/components/teams/InviteMember.tsx b/app/components/teams/InviteMember.tsx
index 2eee0d5e..87417480 100644
--- a/app/components/teams/InviteMember.tsx
+++ b/app/components/teams/InviteMember.tsx
@@ -56,7 +56,7 @@ class InviteMember extends React.Component {
await store.currentTeam.inviteMember(email);
this.setState({ email: '' });
- notify('Invited');
+ notify('You successfully sent invitation.');
this.props.onClose();
NProgress.done();
} catch (error) {
diff --git a/app/pages/invitation.tsx b/app/pages/invitation.tsx
index 6540fbbb..31e71fd0 100644
--- a/app/pages/invitation.tsx
+++ b/app/pages/invitation.tsx
@@ -6,7 +6,7 @@ import Error from 'next/error';
import Router from 'next/router';
import LoginButton from '../components/common/LoginButton';
-import { getInvitedTeamByToken } from '../lib/api/public';
+import { getInvitedTeamByToken, removeInvitationIfMemberAdded } from '../lib/api/public';
import { Store, Team } from '../lib/store';
import withAuth from '../lib/withAuth';
import withLayout from '../lib/withLayout';
@@ -30,13 +30,17 @@ class Invitation extends React.Component<{ store: Store; team: Team; token: stri
}
componentDidMount() {
- const { store, team } = this.props;
+ const { store, team, token } = this.props;
const user = store.currentUser;
if (user && team) {
if (team.memberIds.includes(user._id)) {
- Router.push(`/projects?teamSlug=${team.slug}`, `/team/${team.slug}/projects`);
+ removeInvitationIfMemberAdded(token);
+ Router.push(
+ `/topics/detail?teamSlug=${team.slug}&topicSlug=projects`,
+ `/team/${team.slug}/t/projects`,
+ );
} else {
Router.push(`/`);
}
@@ -62,23 +66,23 @@ class Invitation extends React.Component<{ store: Store; team: Team; token: stri
Team Invitation: {team.name}
-
- {' '}
- {team.name}
-
-
- Join {team.name} logging in with your Google account.
-
-
+
+
+ {' '}
+ {team.name}
+
+ Join {team.name} by logging in with your Google account.
+
+
+
);
}