Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bodysch-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
JetBrains YouTrack
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KSZK
DevTeam
org
BodySCH
bodysch-frontend
Commits
84f070d4
Commit
84f070d4
authored
4 years ago
by
Chif Gergő
Browse files
Options
Downloads
Patches
Plain Diff
Refactor context, add types from request
parent
a57ef9fc
No related branches found
No related tags found
2 merge requests
!7
update master to dev
,
!5
Add api data types
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
package-lock.json
+9
-5
9 additions, 5 deletions
package-lock.json
src/core/context/UserContext.tsx
+11
-18
11 additions, 18 deletions
src/core/context/UserContext.tsx
src/core/types.ts
+25
-0
25 additions, 0 deletions
src/core/types.ts
with
45 additions
and
23 deletions
package-lock.json
+
9
−
5
View file @
84f070d4
...
@@ -2512,6 +2512,14 @@
...
@@ -2512,6 +2512,14 @@
}
}
}
}
},
},
"@material-ui/icons": {
"version": "4.9.1",
"resolved": "https://registry.npmjs.org/@material-ui/icons/-/icons-4.9.1.tgz",
"integrity": "sha512-GBitL3oBWO0hzBhvA9KxqcowRUsA0qzwKkURyC8nppnC3fw54KPKZ+d4V1Eeg/UnDRSzDaI9nGCdel/eh9AQMg==",
"requires": {
"@babel/runtime": "^7.4.4"
}
},
"@material-ui/styles": {
"@material-ui/styles": {
"version": "4.10.0",
"version": "4.10.0",
"resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.10.0.tgz",
"resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.10.0.tgz",
...
@@ -2934,7 +2942,6 @@
...
@@ -2934,7 +2942,6 @@
"version": "3.3.1",
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz",
"resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz",
"integrity": "sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==",
"integrity": "sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==",
"dev": true,
"requires": {
"requires": {
"@types/react": "*",
"@types/react": "*",
"hoist-non-react-statics": "^3.3.0"
"hoist-non-react-statics": "^3.3.0"
...
@@ -3037,7 +3044,6 @@
...
@@ -3037,7 +3044,6 @@
"version": "0.63.6",
"version": "0.63.6",
"resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.63.6.tgz",
"resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.63.6.tgz",
"integrity": "sha512-qAv/VOyXAk4it9MOsQoyUjUnEJ3kAW1FCRGi0OvfQDKLH1/FFogVFvoB6xAlBNc6lPyBtCg+nvzj/ScYe0PqCQ==",
"integrity": "sha512-qAv/VOyXAk4it9MOsQoyUjUnEJ3kAW1FCRGi0OvfQDKLH1/FFogVFvoB6xAlBNc6lPyBtCg+nvzj/ScYe0PqCQ==",
"dev": true,
"requires": {
"requires": {
"@types/react": "*"
"@types/react": "*"
}
}
...
@@ -3080,7 +3086,6 @@
...
@@ -3080,7 +3086,6 @@
"version": "5.1.2",
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/@types/styled-components/-/styled-components-5.1.2.tgz",
"resolved": "https://registry.npmjs.org/@types/styled-components/-/styled-components-5.1.2.tgz",
"integrity": "sha512-HNocYLfrsnNNm8NTS/W53OERSjRA8dx5Bn6wBd2rXXwt4Z3s+oqvY6/PbVt3e6sgtzI63GX//WiWiRhWur08qQ==",
"integrity": "sha512-HNocYLfrsnNNm8NTS/W53OERSjRA8dx5Bn6wBd2rXXwt4Z3s+oqvY6/PbVt3e6sgtzI63GX//WiWiRhWur08qQ==",
"dev": true,
"requires": {
"requires": {
"@types/hoist-non-react-statics": "*",
"@types/hoist-non-react-statics": "*",
"@types/react": "*",
"@types/react": "*",
...
@@ -3091,8 +3096,7 @@
...
@@ -3091,8 +3096,7 @@
"csstype": {
"csstype": {
"version": "3.0.2",
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.2.tgz",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.2.tgz",
"integrity": "sha512-ofovWglpqoqbfLNOTBNZLSbMuGrblAf1efvvArGKOZMBrIoJeu5UsAipQolkijtyQx5MtAzT/J9IHj/CEY1mJw==",
"integrity": "sha512-ofovWglpqoqbfLNOTBNZLSbMuGrblAf1efvvArGKOZMBrIoJeu5UsAipQolkijtyQx5MtAzT/J9IHj/CEY1mJw=="
"dev": true
}
}
}
}
},
},
...
...
This diff is collapsed.
Click to expand it.
src/core/context/UserContext.tsx
+
11
−
18
View file @
84f070d4
import
React
,
{
createContext
,
ReactNode
,
useReducer
}
from
'
react
'
;
import
React
,
{
createContext
,
ReactNode
,
useState
}
from
'
react
'
;
import
{
Profile
}
from
'
../types
'
;
// Interface definitions
// Interface definitions
interface
IWarnings
extends
Document
{
interface
IWarnings
extends
Document
{
...
@@ -31,37 +32,29 @@ type Props = {
...
@@ -31,37 +32,29 @@ type Props = {
children
:
ReactNode
;
children
:
ReactNode
;
};
};
interface
I
ContextProps
{
interface
ContextProps
{
stat
e
:
I
Profile
;
profil
e
:
Profile
;
dispatch
:
({
type
}:
{
type
:
string
}
)
=>
void
;
setProfile
:
(
profile
:
Profile
)
=>
void
;
}
}
// Context
// Context
const
initialState
=
{
const
initialState
:
Profile
=
{
external_id
:
'
abcd
'
,
external_id
:
'
abcd
'
,
studentCardNumber
:
'
1234
'
,
studentCardNumber
:
'
1234
'
,
roomNumber
:
104
,
roomNumber
:
'
104
'
,
picture
:
'
alma.jpg
'
,
picture
:
'
alma.jpg
'
,
role
:
Role
.
User
,
role
:
Role
.
User
,
email
:
'
alma@gmail.com
'
,
email
:
'
alma@gmail.com
'
,
name
:
'
Nagy Gizike
'
,
name
:
'
Nagy Gizike
'
,
warning
:
[],
warning
s
:
[],
};
};
export
const
userContext
=
createContext
({}
as
IContextProps
);
export
const
userContext
=
createContext
({}
as
IContextProps
);
const
{
Provider
}
=
userContext
;
const
{
Provider
}
=
userContext
;
export
const
UserStateProvider
:
React
.
FunctionComponent
<
Props
>
=
(
props
:
Props
)
=>
{
export
const
UserStateProvider
:
React
.
FC
=
({
children
})
=>
{
const
{
children
}
=
props
;
const
[
profile
,
setProfile
]
=
useState
<
Profile
>
(
initialState
);
const
[
state
,
dispatch
]
=
useReducer
((
prevState
:
any
,
action
:
any
)
=>
{
switch
(
action
.
type
)
{
case
'
update
'
:
return
action
.
payload
;
default
:
return
prevState
;
// do nothing
}
},
initialState
);
return
<
Provider
value
=
{
{
state
,
dispatch
}
}
>
{
children
}
</
Provider
>;
return
<
Provider
value
=
{
{
profile
,
setProfile
}
}
>
{
children
}
</
Provider
>;
};
};
export
default
{
userContext
,
UserStateProvider
};
export
default
{
userContext
,
UserStateProvider
};
This diff is collapsed.
Click to expand it.
src/core/types.ts
0 → 100644
+
25
−
0
View file @
84f070d4
export
enum
Role
{
Admin
,
Staff
,
User
,
}
export
interface
Profile
{
external_id
:
string
;
studentCardNumber
:
string
;
roomNumber
?:
string
;
picture
:
string
;
role
:
Role
.
Admin
|
Role
.
Staff
|
Role
.
User
;
email
?:
string
;
name
?:
string
;
warnings
:
[
Warnings
]
|
[];
}
export
interface
Warnings
{
text
:
string
;
date
:
Date
;
given_by
:
{
_id
:
string
;
name
:
string
;
};
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment