Skip to content

Commit c1f02ef

Browse files
committed
#163 redirect, class -> functional, smaller tasks
1 parent 38313ea commit c1f02ef

File tree

10 files changed

+354
-44
lines changed

10 files changed

+354
-44
lines changed

book/11-end/app/components/discussions/CreateDiscussionForm.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import DialogContent from '@mui/material/DialogContent';
44
import DialogTitle from '@mui/material/DialogTitle';
55
import FormControl from '@mui/material/FormControl';
66
import FormHelperText from '@mui/material/FormHelperText';
7-
import InputLabel from '@mui/material/InputLabel';
87
import Select from '@mui/material/Select';
98
import MenuItem from '@mui/material/MenuItem';
109
import TextField from '@mui/material/TextField';
@@ -207,10 +206,10 @@ class CreateDiscussionForm extends React.Component<Props, State> {
207206
return;
208207
}
209208

210-
if (!memberIds || memberIds.length < 1) {
211-
notify('Please assign at least one person to this Discussion.');
212-
return;
213-
}
209+
// if (!memberIds || memberIds.length < 1) {
210+
// notify('Please assign at least one person to this Discussion.');
211+
// return;
212+
// }
214213

215214
if (!notificationType) {
216215
notify('Please select notification type.');

book/11-end/app/components/discussions/EditDiscussionForm.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import DialogContentText from '@mui/material/DialogContentText';
66
import DialogTitle from '@mui/material/DialogTitle';
77
import FormControl from '@mui/material/FormControl';
88
import FormHelperText from '@mui/material/FormHelperText';
9-
import InputLabel from '@mui/material/InputLabel';
109
import Select from '@mui/material/Select';
1110
import MenuItem from '@mui/material/MenuItem';
1211
import TextField from '@mui/material/TextField';
@@ -174,10 +173,10 @@ class EditDiscussionForm extends React.Component<Props, State> {
174173
memberIds.push(discussion.store.currentUser._id);
175174
}
176175

177-
if (!memberIds || memberIds.length < 1) {
178-
notify('Please assign at least one person to this Discussion.');
179-
return;
180-
}
176+
// if (!memberIds || memberIds.length < 1) {
177+
// notify('Please assign at least one person to this Discussion.');
178+
// return;
179+
// }
181180

182181
if (!notificationType) {
183182
notify('Please select notification type.');

book/11-end/app/components/layout/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class Layout extends React.Component<Props> {
182182

183183
// console.log(isMobile);
184184

185-
// console.log(currentTeam);
185+
console.log(store, currentUser, currentTeam);
186186

187187
if (!currentUser) {
188188
return (

book/11-end/app/lib/store/index.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,7 @@ class Store {
5151

5252
this.currentUrl = initialState.currentUrl || '';
5353

54-
// console.log(initialState.user);
55-
56-
// if (initialState.teamSlug || (initialState.user && initialState.user.defaultTeamSlug)) {
57-
// this.setCurrentTeam(
58-
// initialState.teamSlug || initialState.user.defaultTeamSlug,
59-
// initialState.teams,
60-
// );
61-
// }
62-
63-
// console.log(initialState.team);
54+
console.log(initialState);
6455

6556
this.setCurrentTeam(initialState.team);
6657

book/11-end/app/lib/withAuth.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ export default function withAuth(Component, { loginRequired = true, logoutRequir
6969
redirectUrl = '/create-team';
7070
asUrl = '/create-team';
7171
} else {
72-
redirectUrl = `/your-settings`;
73-
asUrl = `/your-settings`;
72+
redirectUrl = `/your-settings?teamSlug=${user.defaultTeamSlug}`;
73+
asUrl = `/teams/${user.defaultTeamSlug}/your-settings`;
7474
}
7575
}
7676

book/11-end/app/pages/_app.tsx

+6-12
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MyApp extends App {
2727
}
2828

2929
if (
30-
ctx.pathname.includes('/your-settings') || // because of MenuWithLinks inside `Layout` HOC
30+
ctx.pathname.includes('/your-settings') ||
3131
ctx.pathname.includes('/team-settings') ||
3232
ctx.pathname.includes('/discussion') ||
3333
ctx.pathname.includes('/billing')
@@ -52,6 +52,8 @@ class MyApp extends App {
5252

5353
const appProps = { pageProps };
5454

55+
console.log('before getStore');
56+
5557
const store = getStore();
5658
if (store) {
5759
return appProps;
@@ -80,8 +82,6 @@ class MyApp extends App {
8082

8183
// console.log(initialData);
8284

83-
// console.log(teamSlug);
84-
8585
let selectedTeamSlug = '';
8686

8787
if (teamRequired) {
@@ -93,24 +93,18 @@ class MyApp extends App {
9393
let team;
9494
if (initialData && initialData.teams) {
9595
team = initialData.teams.find((t) => {
96-
return t.slug === selectedTeamSlug;
96+
return t.slug === selectedTeamSlug || userObj.defaultTeamSlug;
9797
});
9898
}
9999

100+
console.log(initialData.teams, team);
101+
100102
return {
101103
...appProps,
102104
initialState: { user: userObj, currentUrl: ctx.asPath, team, teamSlug, ...initialData },
103105
};
104106
}
105107

106-
public componentDidMount() {
107-
// Remove the server-side injected CSS.
108-
const jssStyles = document.querySelector('#jss-server-side');
109-
if (jssStyles && jssStyles.parentNode) {
110-
jssStyles.parentNode.removeChild(jssStyles);
111-
}
112-
}
113-
114108
private store: Store;
115109

116110
constructor(props) {

0 commit comments

Comments
 (0)