Skip to content

Commit

Permalink
book/7-end done
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed Jun 28, 2020
1 parent cd75c01 commit 73c0f58
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion book/7-end/app/components/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function LayoutWrapper({
]}
>
<Avatar
src={'https://storage.googleapis.com/async-await/default-user.png'}
src={store.currentUser.avatarUrl}
alt="Add username here later in the book"
style={{
margin: '20px auto',
Expand Down
12 changes: 9 additions & 3 deletions book/7-end/app/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ class MyApp extends App<{ isMobile: boolean }> {
teamRequired = true;
}

const { teamSlug } = ctx.query;
const { teamSlug, redirectMessage } = ctx.query;

console.log(`ctx.query.teamSlug:${teamSlug}`);
// console.log(`ctx.query.teamSlug:${teamSlug}`);

const pageProps = { isMobile: isMobile({ req: ctx.req }), firstGridItem, teamRequired, teamSlug };
const pageProps = {
isMobile: isMobile({ req: ctx.req }),
firstGridItem,
teamRequired,
teamSlug,
redirectMessage,
};

if (Component.getInitialProps) {
Object.assign(pageProps, await Component.getInitialProps(ctx));
Expand Down
7 changes: 4 additions & 3 deletions book/7-end/app/pages/invitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import React from 'react';
import LoginButton from '../components/common/LoginButton';
import Layout from '../components/layout';
import { acceptAndGetInvitedTeamByTokenApiMethod, removeInvitationIfMemberAddedApiMethod } from '../lib/api/public';
import notify from '../lib/notify';
import { Team } from '../lib/store/team';
import { Store } from '../lib/store';
import withAuth from '../lib/withAuth';
Expand Down Expand Up @@ -81,8 +80,10 @@ class Invitation extends React.Component<MyProps> {
if (user && team) {
if (team.memberIds.includes(user._id)) {
await removeInvitationIfMemberAddedApiMethod(token);
Router.push('/your-settings');
notify(`You are now a member of ${team.name} team.`);
Router.push({
pathname: '/your-settings',
query: { redirectMessage: `Success! You are now part of ${team.name} team.` }
});
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion book/7-end/app/pages/team-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class TeamSettings extends React.Component<MyProps, MyState> {
variant="outlined"
color="primary"
style={{ float: 'right', marginTop: '-20px' }}
disabled={this.state.disabled}
>
Invite member
</Button>
Expand Down Expand Up @@ -187,7 +188,7 @@ class TeamSettings extends React.Component<MyProps, MyState> {
{isTeamLeader && m._id !== currentUser._id ? 'Team Member' : 'Team Leader'}
</TableCell>
<TableCell>
{isTeamLeader ? (
{isTeamLeader && m._id !== currentUser._id ? (
<i
color="action"
data-id={m._id}
Expand Down
12 changes: 11 additions & 1 deletion book/7-end/app/pages/your-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { resizeImage } from '../lib/resizeImage';
import { Store } from '../lib/store';
import withAuth from '../lib/withAuth';

type MyProps = { isMobile: boolean; store: Store };
type MyProps = { isMobile: boolean; store: Store; redirectMessage?: string };

type MyState = { newName: string; newAvatarUrl: string; disabled: boolean };

Expand Down Expand Up @@ -125,6 +125,16 @@ class YourSettings extends React.Component<MyProps, MyState> {
);
}

public componentDidMount() {
const { redirectMessage } = this.props;

console.log(redirectMessage);

if (redirectMessage) {
notify(redirectMessage);
}
};

private onSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

Expand Down

0 comments on commit 73c0f58

Please sign in to comment.