diff options
Diffstat (limited to 'src/pages/Profile')
-rw-r--r-- | src/pages/Profile/Profile.tsx (renamed from src/pages/Profile/Profile.js) | 19 | ||||
-rw-r--r-- | src/pages/Profile/Registration.tsx (renamed from src/pages/Profile/Registration/Registration.js) | 21 |
2 files changed, 26 insertions, 14 deletions
diff --git a/src/pages/Profile/Profile.js b/src/pages/Profile/Profile.tsx index 65c3734..83acb30 100644 --- a/src/pages/Profile/Profile.js +++ b/src/pages/Profile/Profile.tsx @@ -5,12 +5,13 @@ import { makeStyles, } from '@material-ui/core'; -import Registration from './Registration/Registration'; +import Registration from './Registration'; import { Window, ContentSection, SmartList, } from 'react-benzin'; +import { User, Solution, RenderPropTypes } from '../../types'; import SolutionCard from '../../components/SolutionCard/SolutionCard'; @@ -27,12 +28,18 @@ const useStyles = makeStyles(theme => ({ })); -const Profile = ({ user, setUser }) => { +interface PropTypes { + user: User; + setUser: (user: User) => void; +} + + +const Profile: React.FC<PropTypes> = ({ user, setUser }) => { const classes = useStyles(); - const [profileSolutions, setProfileSolutions] = useState([]); + const [profileSolutions, setProfileSolutions] = useState<Solution[]>([]); - const handleLogout = () => { + const handleLogout = (): void => { setUser({ username: 'anonymous', id: null }); localStorage.clear(); }; @@ -43,11 +50,11 @@ const Profile = ({ user, setUser }) => { }); }, [user]); - const removeSolution = (id) => { + const removeSolution = (id: number): void => { setProfileSolutions(profileSolutions.filter((solution => solution.id !== id))); }; - const renderItem = ({ index, style }) => { + const renderItem: React.FC<RenderPropTypes> = ({ index, style }) => { return ( <div style={style} className={classes.cell}> <SolutionCard data={profileSolutions[index]} removeThisCard={removeSolution} /> diff --git a/src/pages/Profile/Registration/Registration.js b/src/pages/Profile/Registration.tsx index b2d5503..a5e0f3e 100644 --- a/src/pages/Profile/Registration/Registration.js +++ b/src/pages/Profile/Registration.tsx @@ -7,25 +7,30 @@ import { FormControlLabel, Grid, } from '@material-ui/core'; +import { User } from '../../types'; import { ContentSection } from 'react-benzin'; -import { get, post } from '../../../requests'; +import { get, post } from '../../requests'; -const Registration = ({ setUser }) => { +interface PropTypes { + setUser: (user: User) => void; +} - const [username, setUsername] = useState(''); - const [isRememberMe, setIsRememberMe] = useState(false); +const Registration: React.FC<PropTypes> = ({ setUser }) => { - const handleChange = (event) => { + const [username, setUsername] = useState<string>(''); + const [isRememberMe, setIsRememberMe] = useState<boolean>(false); + + const handleChange = (event: React.ChangeEvent<HTMLInputElement>): void => { setUsername(event.target.value); }; - const handleCheck = (event) => { + const handleCheck = (event: React.ChangeEvent<HTMLInputElement>): void => { setIsRememberMe(event.target.checked); }; - const handleSubmit = () => { + const handleSubmit = (): void => { if (username !== '') { post('users/', { username }) .then(response => { @@ -37,7 +42,7 @@ const Registration = ({ setUser }) => { }) .catch(err => { get('users/').then(response => { - const user = response.data.filter(user => user.username === username)[0]; + const user = response.data.filter((user: User) => user.username === username)[0]; setUser(user); if (isRememberMe) { localStorage.setItem('userId', user.id); |