Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Fasilkom UI Open Source Software
Kape
Commits
92a0fe86
Commit
92a0fe86
authored
Apr 26, 2017
by
M. Reza Qorib
Browse files
[#140652771] #29 Finalize react routing
parent
1a17638c
Changes
3
Hide whitespace changes
Inline
Side-by-side
assets/js/VacancyPage.jsx
View file @
92a0fe86
import
React
from
'
react
'
;
import
Tabs
from
'
./components/Tabs
'
;
import
Pane
from
'
./components/Pane
'
;
import
Storage
from
'
./lib/Storage
'
;
import
VacancyList
from
'
./components/VacancyList
'
;
export
default
class
VacancyPage
extends
React
.
Component
{
static
getRole
()
{
const
student
=
Storage
.
get
(
'
user-data
'
).
student
;
const
company
=
Storage
.
get
(
'
user-data
'
).
company
;
if
(
student
)
{
return
{
id
:
student
.
id
,
type
:
'
student
'
};
}
else
if
(
company
)
{
return
{
id
:
company
.
id
,
type
:
'
company
'
};
static
propTypes
=
{
user
:
React
.
PropTypes
.
object
.
isRequired
,
};
static
getId
(
user
)
{
const
role
=
user
.
role
;
if
(
role
===
'
student
'
)
{
return
user
.
data
.
student
.
id
;
}
else
if
(
role
===
'
company
'
)
{
return
user
.
data
.
company
.
id
;
}
return
{
id
:
'
0
'
,
type
:
'
error
'
}
;
return
0
;
}
constructor
(
props
)
{
super
(
props
);
/* istanbul ignore next */
const
role
=
VacancyPage
.
getRole
();
this
.
state
=
{
vacancies
:
[],
id
:
role
.
id
,
role
:
role
.
type
,
id
:
VacancyPage
.
getId
(
this
.
props
.
user
),
};
}
generateVacancies
()
{
if
(
this
.
state
.
role
===
'
student
'
)
{
if
(
this
.
props
.
user
.
role
===
'
student
'
)
{
return
(
<
Tabs
selected
=
{
0
}
>
<
Pane
label
=
"Semua Lowongan"
>
...
...
@@ -57,7 +57,7 @@ export default class VacancyPage extends React.Component {
</
Pane
>
</
Tabs
>
);
}
else
if
(
this
.
state
.
role
===
'
company
'
)
{
}
else
if
(
this
.
props
.
user
.
role
===
'
company
'
)
{
return
(
<
VacancyList
key
=
{
1
}
userId
=
{
this
.
state
.
id
}
url
=
{
`/companies/
${
this
.
state
.
id
}
/vacancies/`
}
type
=
"company"
/>
);
...
...
assets/js/components/VacancyList.jsx
View file @
92a0fe86
...
...
@@ -24,10 +24,10 @@ export default class VacancyList extends React.Component {
constructor
(
props
)
{
super
(
props
);
/* istanbul ignore next */
this
.
state
=
{
vacancies
:
[],
bookmarkList
:
[]
};
if
(
this
.
props
.
type
===
'
student
'
)
{
this
.
updateBookmarkList
();
}
this
.
state
=
{
vacancies
:
[],
bookmarkList
:
[]
};
Server
.
get
(
this
.
props
.
url
,
false
).
then
((
data
)
=>
{
this
.
setState
({
vacancies
:
data
});
});
...
...
assets/js/index.jsx
View file @
92a0fe86
...
...
@@ -13,13 +13,14 @@ export default class App extends React.Component {
static
getRole
()
{
if
(
Server
.
isLoggedIn
())
{
if
(
Storage
.
get
(
'
user-data
'
).
is_staff
)
{
const
data
=
Storage
.
get
(
'
user-data
'
);
if
(
data
.
is_staff
)
{
return
'
admin
'
;
}
else
if
(
Storage
.
get
(
'
user-
data
'
)
.
supervisor
)
{
}
else
if
(
data
.
supervisor
)
{
return
'
supervisor
'
;
}
else
if
(
Storage
.
get
(
'
user-
data
'
)
.
student
)
{
}
else
if
(
data
.
student
)
{
return
'
student
'
;
}
else
if
(
Storage
.
get
(
'
user-
data
'
)
.
company
)
{
}
else
if
(
data
.
company
)
{
return
'
company
'
;
}
return
'
error
'
;
...
...
@@ -40,18 +41,19 @@ export default class App extends React.Component {
class
WithAuthorization
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
user
:
{
role
:
App
.
getRole
(),
data
:
Storage
.
get
(
'
user-data
'
),
},
};
}
render
()
{
const
{
role
}
=
this
.
state
.
user
;
// const props = this.props;
if
(
allowedRoles
.
includes
(
role
))
{
return
<
WrappedComponent
{
...
this
.
props
}
/>;
return
<
WrappedComponent
{
...
this
.
props
}
{
...
this
.
state
}
/>;
}
return
<
div
>
{
browserHistory
.
push
(
'
/home
'
)
}
</
div
>;
}
...
...
@@ -63,14 +65,15 @@ export default class App extends React.Component {
};
handleHome
=
(
nextState
,
replace
,
cb
)
=>
{
console
.
log
(
Server
.
isLoggedIn
());
if
(
Server
.
isLoggedIn
())
{
Storage
.
getUserData
().
then
(()
=>
{
if
(
App
.
getRole
()
===
'
student
'
)
{
replace
({
pathname
:
'
/lowongan
'
});
cb
(
);
}
else
if
(
App
.
getRole
()
===
'
company
'
)
{
replace
({
pathname
:
'
/pelamar
'
});
cb
();
}
}
);
console
.
log
(
'
masuk
'
);
if
(
App
.
getRole
()
===
'
student
'
)
{
console
.
log
(
'
masuk3
'
);
replace
({
pathname
:
'
/lowongan
'
});
cb
();
}
else
if
(
App
.
getRole
()
===
'
company
'
)
{
replace
({
pathname
:
'
/lowongan
'
});
cb
();
}
}
replace
({
pathname
:
'
/login
'
});
cb
();
};
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment