Skip to content

Commit 8a70eb5

Browse files
committed
added login form, no server side logic
1 parent dd24825 commit 8a70eb5

File tree

10 files changed

+236
-4
lines changed

10 files changed

+236
-4
lines changed

src/actionTypes/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ export const UPDATE_CHILDREN: string = 'UPDATE_CHILDREN';
4040
export const UPDATE_CHILDREN_SORT: string = 'UPDATE_CHILDREN_SORT';
4141
export const UPDATE_CODE: string = 'UPDATE_CODE';
4242
export const UPDATE_HTML_ATTR: string = 'UPDATE_HTML_ATTR';
43+
44+
export const SET_USERNAME: string = 'SET_USERNAME';
45+
export const SET_PASSWORD: string = 'SET_PASSWORD';

src/actions/actionCreators.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ import {
3838
TOGGLE_STATE,
3939
UNDO,
4040
UPDATE_HTML_ATTR,
41-
UPDATE_CODE
41+
UPDATE_CODE,
42+
SET_USERNAME,
43+
SET_PASSWORD
4244
} from '../actionTypes/index';
4345
import { loadState } from '../localStorage';
4446
import createFiles from '../utils/createFiles.util';
@@ -327,3 +329,13 @@ export const updateHtmlAttr = ({
327329
type: UPDATE_HTML_ATTR,
328330
payload: { attr, value }
329331
});
332+
333+
export const setUsername = (username: string): Action => ({
334+
type: SET_USERNAME,
335+
payload: username
336+
});
337+
338+
export const setPassword = (password: string): Action => ({
339+
type: SET_PASSWORD,
340+
payload: password
341+
})

src/components/login/SignIn.tsx

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import React from 'react';
2+
import Avatar from '@material-ui/core/Avatar';
3+
import Button from '@material-ui/core/Button';
4+
import CssBaseline from '@material-ui/core/CssBaseline';
5+
import TextField from '@material-ui/core/TextField';
6+
import FormControlLabel from '@material-ui/core/FormControlLabel';
7+
import Checkbox from '@material-ui/core/Checkbox';
8+
import Link from '@material-ui/core/Link';
9+
import Grid from '@material-ui/core/Grid';
10+
import Box from '@material-ui/core/Box';
11+
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
12+
import Typography from '@material-ui/core/Typography';
13+
import { makeStyles } from '@material-ui/core/styles';
14+
import Container from '@material-ui/core/Container';
15+
16+
function Copyright() {
17+
return (
18+
<Typography variant="body2" color="textSecondary" align="center">
19+
{'Copyright © '}
20+
<Link color="inherit" href="https://material-ui.com/">
21+
Your Website
22+
</Link>{' '}
23+
{new Date().getFullYear()}
24+
{'.'}
25+
</Typography>
26+
);
27+
}
28+
29+
const useStyles = makeStyles((theme) => ({
30+
paper: {
31+
marginTop: theme.spacing(8),
32+
display: 'flex',
33+
flexDirection: 'column',
34+
alignItems: 'center',
35+
},
36+
avatar: {
37+
margin: theme.spacing(1),
38+
backgroundColor: theme.palette.secondary.main,
39+
},
40+
form: {
41+
width: '100%', // Fix IE 11 issue.
42+
marginTop: theme.spacing(1),
43+
},
44+
submit: {
45+
margin: theme.spacing(3, 0, 2),
46+
},
47+
}));
48+
49+
export default function SignIn() {
50+
const classes = useStyles();
51+
52+
return (
53+
<Container component="main" maxWidth="xs">
54+
<CssBaseline />
55+
<div className={classes.paper}>
56+
<Avatar className={classes.avatar}>
57+
<LockOutlinedIcon />
58+
</Avatar>
59+
<Typography component="h1" variant="h5">
60+
Sign in
61+
</Typography>
62+
<form className={classes.form} noValidate>
63+
<TextField
64+
variant="outlined"
65+
margin="normal"
66+
required
67+
fullWidth
68+
id="username"
69+
label="Username"
70+
name="username"
71+
autoComplete="username"
72+
autoFocus
73+
/>
74+
<TextField
75+
variant="outlined"
76+
margin="normal"
77+
required
78+
fullWidth
79+
name="password"
80+
label="Password"
81+
type="password"
82+
id="password"
83+
autoComplete="current-password"
84+
/>
85+
<FormControlLabel
86+
control={<Checkbox value="remember" color="primary" />}
87+
label="Remember me"
88+
/>
89+
<Button
90+
type="submit"
91+
fullWidth
92+
variant="contained"
93+
color="primary"
94+
className={classes.submit}
95+
>
96+
Sign In
97+
</Button>
98+
<Grid container>
99+
<Grid item xs>
100+
<Link href="#" variant="body2">
101+
Forgot password?
102+
</Link>
103+
</Grid>
104+
<Grid item>
105+
<Link href="#" variant="body2">
106+
{"Don't have an account? Sign Up"}
107+
</Link>
108+
</Grid>
109+
</Grid>
110+
</form>
111+
</div>
112+
<Box mt={8}>
113+
<Copyright />
114+
</Box>
115+
</Container>
116+
);
117+
}

src/containers/LoginContainer.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// THIS FILE NOT CURRENTLY IN USE, DELETE
2+
import React, { useState } from 'react';
3+
4+
interface State {
5+
username: string,
6+
password: string
7+
};
8+
9+
class LoginContainer extends React.Component<State> {
10+
11+
state: State = {
12+
username: 'test',
13+
password: 'pass'
14+
}
15+
16+
render() {
17+
return (
18+
<p>Hello</p>
19+
)
20+
}
21+
}
22+
23+
export default LoginContainer

src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@ import { Provider } from 'react-redux';
55
import App from './components/App.tsx';
66
import store from './store';
77

8+
import SignIn from './components/login/SignIn.tsx';
9+
10+
811
ReactDOM.render(
912
<Provider store={store}>
1013
<App />
1114
</Provider>,
1215
document.getElementById('app'),
1316
);
17+
18+
19+
/*
20+
ReactDOM.render(
21+
<SignIn/>,
22+
document.getElementById('app'),
23+
);
24+
*/

src/interfaces/Interfaces.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ export interface ApplicationStateInt {
8484
codeReadOnly: boolean;
8585
}
8686

87+
export interface LoginInt {
88+
username: string;
89+
password: string;
90+
}
91+
8792
//Global Action interface \
8893
export interface Action {
8994
type: string;

src/localStorage.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import localforage from 'localforage';
22
import { ApplicationStateInt } from './interfaces/Interfaces';
33

4-
export const saveState = (state: ApplicationStateInt) =>
4+
export const saveState = (state: ApplicationStateInt) => {
55
localforage.setItem('state-v1.0.1', state);
6-
export const loadState = () => localforage.getItem('state-v1.0.1');
6+
}
7+
export const loadState = () => localforage.getItem('state-v1.0.1').then((value) => {
8+
console.log('The value stored in local storage: ', value);
9+
});

src/reducers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { combineReducers } from 'redux';
22

33
import componentReducer from './rootReducer';
4+
import loginReducer from './loginReducer';
45

56
const reducers = combineReducers({
67
workspace: componentReducer,
8+
credentials: loginReducer
79
});
810

911
export default reducers;

src/reducers/initialState.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import getColor from '../helperFunctions/colors';
44
import {
55
ComponentInt,
66
ChildInt,
7-
ApplicationStateInt
7+
ApplicationStateInt,
8+
LoginInt
89
} from '../interfaces/Interfaces';
910

1011
export const appComponent: ComponentInt = {
@@ -110,6 +111,11 @@ export const initialComponentState: ComponentInt = {
110111
changed: false
111112
};
112113

114+
export const initialLoginState: LoginInt = {
115+
username: '',
116+
password: ''
117+
};
118+
113119
export const nativeComponentTypes = [
114120
'RNView',
115121
'RNSafeAreaView',

src/reducers/loginReducer.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { initialLoginState } from './initialState';
2+
import { Action } from '../interfaces/Interfaces';
3+
import { SET_USERNAME, SET_PASSWORD } from '../actionTypes/index';
4+
/*
5+
export interface LoginInt {
6+
username: string;
7+
password: string;
8+
}
9+
10+
export const initialLoginState: LoginInt = {
11+
username: '',
12+
password: ''
13+
};
14+
15+
export interface Action {
16+
type: string;
17+
payload?: any;
18+
}
19+
20+
export const setUsername = (username: string): Action => ({
21+
type: SET_USERNAME,
22+
payload: username
23+
});
24+
25+
export const setPassword = (password: string): Action => ({
26+
type: SET_PASSWORD,
27+
payload: password
28+
})
29+
*/
30+
31+
const loginReducer = (state = initialLoginState, action: Action) => {
32+
switch(action.type) {
33+
case SET_USERNAME:
34+
return {
35+
...state,
36+
username: action.payload
37+
}
38+
39+
case SET_PASSWORD:
40+
return {
41+
...state,
42+
password: action.payload
43+
}
44+
45+
default:
46+
return state;
47+
}
48+
}
49+
50+
export default loginReducer

0 commit comments

Comments
 (0)