Skip to content

Commit

Permalink
types for State (#156 in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed May 18, 2021
1 parent 72f1d36 commit 8681666
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 97 deletions.
26 changes: 17 additions & 9 deletions saas/app/components/common/Confirmer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ import React from 'react';

export let openConfirmDialogExternal;

class Confirmer extends React.Component {
public state = {
open: false,
title: 'Are you sure?',
message: '',
onAnswer: null,
};
type State = {
open: boolean;
title: string;
message: string;
onAnswer: (answer) => void;
};

class Confirmer extends React.Component<any, State> {
constructor(props) {
super(props);

this.state = {
open: false,
title: 'Are you sure?',
message: '',
onAnswer: null,
};

openConfirmDialogExternal = this.openConfirmDialog;
}

Expand All @@ -34,10 +42,10 @@ class Confirmer extends React.Component {
<DialogContentText id="alert-dialog-description">{this.state.message}</DialogContentText>
</DialogContent>
<DialogActions style={{ padding: '10px' }}>
<Button onClick={this.handleClose} variant="outlined" color="primary" autoFocus>
<Button onClick={this.handleClose} variant="contained" color="primary" autoFocus>
Cancel
</Button>
<Button onClick={this.handleYes} variant="contained" color="primary">
<Button onClick={this.handleYes} variant="contained" color="secondary">
OK
</Button>
</DialogActions>
Expand Down
6 changes: 5 additions & 1 deletion saas/app/components/common/LoginButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ type Props = { invitationToken?: string };
type State = { email: string };

class LoginButton extends React.PureComponent<Props, State> {
public state = { email: '' };
constructor(props) {
super(props);

this.state = { email: '' };
}

public render() {
const { invitationToken } = this.props;
Expand Down
8 changes: 4 additions & 4 deletions saas/app/components/common/MemberChooser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type Props = {
helperText?: string;
};

class MemberChooser extends React.Component<Props> {
public state = {
selectedItems: [],
};
type State = {
selectedItems: { label: string; id: string }[];
};

class MemberChooser extends React.Component<Props, State> {
constructor(props) {
super(props);

Expand Down
20 changes: 15 additions & 5 deletions saas/app/components/common/MenuWithLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ import Link from 'next/link';
import { NextRouter, withRouter } from 'next/router';
import React from 'react';

class MenuWithLinks extends React.PureComponent<{
type Props = {
options: any[];
router: NextRouter;
}> {
public state = {
anchorEl: null,
};
};

type State = {
anchorEl: Element | ((element: Element) => Element);
};

class MenuWithLinks extends React.PureComponent<Props, State> {
constructor(props) {
super(props);

this.state = {
anchorEl: null,
};
}

public render() {
const { options, children, router } = this.props;
Expand Down
34 changes: 22 additions & 12 deletions saas/app/components/common/MenuWithMenuItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@ import MoreVertIcon from '@material-ui/icons/MoreVert';
import MenuItem from '@material-ui/core/MenuItem';
import React from 'react';

class MenuWithMenuItems extends React.PureComponent<{
type Props = {
menuOptions: any;
itemOptions: any[];
}> {
public state = {
menuElm: null,
};
};

type State = {
menuElem: Element | ((element: Element) => Element);
};

class MenuWithMenuItems extends React.PureComponent<Props, State> {
constructor(props) {
super(props);

this.state = {
menuElem: null,
};
}

public render() {
const { menuOptions, itemOptions } = this.props;
const { menuElm } = this.state;
const { menuElem } = this.state;

return (
<div style={{ verticalAlign: 'middle' }}>
<MoreVertIcon
aria-controls={menuElm ? menuOptions.id : null}
aria-controls={menuElem ? menuOptions.id : null}
data-id={menuOptions.dataId}
aria-haspopup="true"
style={{ fontSize: '14px', opacity: 0.7, cursor: 'pointer' }}
Expand All @@ -27,8 +37,8 @@ class MenuWithMenuItems extends React.PureComponent<{

<Menu
id={menuOptions.id}
anchorEl={menuElm}
open={Boolean(menuElm)}
anchorEl={menuElem}
open={Boolean(menuElem)}
onClose={this.handleClose}
>
{itemOptions.map((option, i) => (
Expand All @@ -37,7 +47,7 @@ class MenuWithMenuItems extends React.PureComponent<{
data-id={option.dataId}
data-more-id={option.dataMoreId}
onClick={(e) => {
this.setState({ menuElm: null });
this.setState({ menuElem: null });
option.onClick(e);
}}
>
Expand All @@ -51,11 +61,11 @@ class MenuWithMenuItems extends React.PureComponent<{

public handleClick = (event) => {
event.preventDefault();
this.setState({ menuElm: event.currentTarget });
this.setState({ menuElem: event.currentTarget });
};

public handleClose = () => {
this.setState({ menuElm: null });
this.setState({ menuElem: null });
};
}

Expand Down
15 changes: 10 additions & 5 deletions saas/app/components/common/Notifier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import React from 'react';

export let openSnackbarExternal;

class Notifier extends React.PureComponent {
public state = {
open: false,
message: '',
};
type State = {
open: boolean;
message: string;
};

class Notifier extends React.PureComponent<any, State> {
constructor(props) {
super(props);
openSnackbarExternal = this.openSnackbar;

this.state = {
open: false,
message: '',
};
}

public render() {
Expand Down
22 changes: 13 additions & 9 deletions saas/app/components/discussions/CreateDiscussionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ type State = {
};

class CreateDiscussionForm extends React.Component<Props, State> {
public state = {
name: '',
memberIds: [],
disabled: false,
content: '',
notificationType: 'default',
};
constructor(props) {
super(props);

this.state = {
name: '',
memberIds: [],
disabled: false,
content: '',
notificationType: 'default',
};
}

public render() {
const { open, isMobile, store } = this.props;
Expand Down Expand Up @@ -121,7 +125,7 @@ class CreateDiscussionForm extends React.Component<Props, State> {
</Button>
{isMobile ? <p /> : null}
<Button
variant="outlined"
variant="contained"
onClick={this.handleClose}
disabled={this.state.disabled}
style={{ marginLeft: isMobile ? '0px' : '20px' }}
Expand All @@ -148,7 +152,7 @@ class CreateDiscussionForm extends React.Component<Props, State> {
</Button>
{isMobile ? <p /> : null}
<Button
variant="outlined"
variant="contained"
onClick={this.handleClose}
disabled={this.state.disabled}
style={{ marginLeft: isMobile ? '0px' : '20px' }}
Expand Down
12 changes: 8 additions & 4 deletions saas/app/components/discussions/DiscussionActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ type State = {
};

class DiscussionActionMenu extends React.Component<Props, State> {
public state = {
discussionFormOpen: false,
selectedDiscussion: null,
};
constructor(props) {
super(props);

this.state = {
discussionFormOpen: false,
selectedDiscussion: null,
};
}

public render() {
const { discussion, store } = this.props;
Expand Down
14 changes: 10 additions & 4 deletions saas/app/components/discussions/DiscussionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ import notify from '../../lib/notify';

type Props = { store: Store; team: Team; isMobile: boolean };

class DiscussionList extends React.Component<Props> {
public state = {
discussionFormOpen: false,
};
type State = { discussionFormOpen: boolean };

class DiscussionList extends React.Component<Props, State> {
constructor(props) {
super(props);

this.state = {
discussionFormOpen: false,
};
}

public componentDidMount() {
this.props.team.loadDiscussions().catch((err) => notify(err));
Expand Down
20 changes: 12 additions & 8 deletions saas/app/components/discussions/EditDiscussionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ type State = {
};

class EditDiscussionForm extends React.Component<Props, State> {
public state = {
name: '',
memberIds: [],
disabled: false,
discussionId: '',
notificationType: 'default',
};
constructor(props) {
super(props);

this.state = {
name: '',
memberIds: [],
disabled: false,
discussionId: '',
notificationType: 'default',
};
}

public static getDerivedStateFromProps(props: Props, state: State) {
const { discussion } = props;
Expand Down Expand Up @@ -117,7 +121,7 @@ class EditDiscussionForm extends React.Component<Props, State> {
<DialogActions>
<Button
color="primary"
variant="outlined"
variant="contained"
onClick={this.handleClose}
disabled={this.state.disabled}
>
Expand Down
2 changes: 1 addition & 1 deletion saas/app/components/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class Layout extends React.Component<Props> {
Select existing team or create a new team.
<p />
<Link href="/create-team" as="/create-team">
<Button variant="outlined" color="primary">
<Button variant="contained" color="primary">
Create new team
</Button>
</Link>
Expand Down
10 changes: 7 additions & 3 deletions saas/app/components/posts/PostEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ type Props = {
type State = { htmlContent: string };

class PostEditor extends React.Component<Props, State> {
public state = {
htmlContent: '',
};
constructor(props) {
super(props);

this.state = {
htmlContent: '',
};
}

public render() {
const { htmlContent } = this.state;
Expand Down
18 changes: 11 additions & 7 deletions saas/app/components/posts/PostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ type State = {
};

class PostForm extends React.Component<Props, State> {
public state = {
postId: null,
content: '',
disabled: false,
};
constructor(props) {
super(props);

this.state = {
postId: null,
content: '',
disabled: false,
};
}

public static getDerivedStateFromProps(props: Props, state: State) {
const { post } = props;
Expand Down Expand Up @@ -90,7 +94,7 @@ class PostForm extends React.Component<Props, State> {
)}
{isEditingPost ? (
<Button
variant="outlined"
variant="contained"
onClick={this.closeForm}
disabled={this.state.disabled}
style={{ marginLeft: '10px' }}
Expand All @@ -112,7 +116,7 @@ class PostForm extends React.Component<Props, State> {
<div style={{ margin: '20px 0px' }}>
{isEditingPost ? (
<Button
variant="outlined"
variant="contained"
onClick={this.closeForm}
disabled={this.state.disabled}
style={{ marginLeft: '10px' }}
Expand Down
Loading

0 comments on commit 8681666

Please sign in to comment.