Fakultas Ilmu Komputer UI

Commit 1a17638c authored by M. Reza Qorib's avatar M. Reza Qorib
Browse files

Merge branch 'UserStory3' of https://gitlab.com/PPL2017csui/PPLA1 into Features/react-routing

# Conflicts:
#	assets/js/index.jsx
parents 5f81b015 b8438bad
......@@ -11,6 +11,7 @@
"func-names": ["error", "never"],
"react/prefer-stateless-function": [0, { "ignorePureComponents": true }],
"react/forbid-prop-types": [0],
"react/no-multi-comp": [0, { "ignoreStateless": 1 }],
"import/extensions": ["off", "never"],
"import/no-unresolved": 0,
"no-underscore-dangle" : 0,
......
......@@ -12,3 +12,4 @@ test/*
.coverage
.tmp/
npm-debug.log
debug.log
body{
padding: 0;
height: auto;
width: auto;
background-color: black;
}
.center{
text-align: center;
}
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
body {
font: 300 14px/1.4 'Helvetica Neue', Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
.applicant{
margin-left: 150px;
margin-right: 150px;
}
.ui.inverted.segment.header{
background-color: #EEEEEE;
color:black;
}
.halamanLowongan{
.ui.card.register{
background-color: #EEEEEE;
}
.create-lowongan{
margin: 60px 19% 100px;
}
.ui.segment.form-segment{
padding-bottom: 50px;
}
.tabs {
margin-top: 100px;
margin-left: 150px;
margin-right: 150px;
background: #fff;
border: 1px solid #e5e5e5;
border-radius: 3px;
margin-bottom: 30px;
margin: 100px 100px 30px;
}
.tabs__labels {
margin: 0;
......@@ -59,29 +59,23 @@ body {
}
.halamanLogin{
background-image: url("../img/bw.jpg");
background-size: cover;
background-position: center;
background-attachment: fixed;
height: 700px;
background: url("../img/background.png")no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
padding-bottom: 80px;
}
.register{
margin-left:180px;
margin-right:110px;
.headerLoginform{
background-color: #2e6da4;
}
.formLogin{
margin: 0 auto;
margin-top: 100px;
width: 430px;
border: 2px solid transparent;
border-radius: 12px;
border-color:#e8e8e8;
padding: 20px;
background-color: white;
margin: 30px auto 0;
width: 430px;
}
.registerModal{
......@@ -95,7 +89,6 @@ padding: 20px;
.formLogin img{
height: 70px !important;
margin:5px;
margin-bottom:30px;
}
.formLogin span{
......@@ -115,7 +108,7 @@ font-size: 32px;
}
.daftar{
float: right;
margin-top:10px;
margin-top:10px;
}
.coverLetter{
......@@ -129,23 +122,24 @@ font-size: 32px;
margin-bottom: 10px;
}
.registerForm{
margin: 0 auto;
padding:50px;
/*padding:50px;*/
background-color: #3B8686;
}
item{
h3{
color:black;
}
textarea{
width: 800px !important;
height: 160px !important;
h4{
color: black;
}
h5{
color: black;
}
.note {
color: gray;
......@@ -170,7 +164,19 @@ card .formRegis{
margin-top: 100px;
}
itemLowongan{
.itemLowongan{
color: black;
}
.ui.pointing.secondary.menu{
background-color: #ffffff;
}
.extra.extra-company h3{
padding-top:10px;
}
.extra.extra-company h2{
color: black;
}
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 {
constructor(props) {
super(props);
/* istanbul ignore next */
this.state = {
email: '',
password: '',
errorFlag: false,
vacancies: [],
};
this.handleItemClick = this.handleItemClick.bind(this);
}
handleItemClick = (e, { name }) => this.setState({ activeItem: name });
render() {
const student = Storage.get('user-data').student;
return (
<div className="halamanPendaftar">
<Tabs selected={0}>
<Pane label="Lamaran Baru" >
<VacancyList key={1} studentId={student.id} url="/vacancies/" />
</Pane>
<Pane label="Bintangi" >
<VacancyList key={2} status="Batal" studentId={student.id} url={`/students/${student.id}/applied-vacancies/`} />
</Pane>
<Pane label="Semua Lamaran" >
<VacancyList key={3} studentId={student.id} url={`/students/${student.id}/bookmarked-vacancies/`} />
</Pane>
</Tabs>
</div>
);
}
}
import React from 'react';
import { Segment, Button, Form, Header, Icon, Input } from 'semantic-ui-react';
import { browserHistory } from 'react-router';
import DatePicker from 'react-datepicker';
import moment from 'moment';
import ModalAlert from './components/ModalAlert';
import Server from './lib/Server';
import Storage from './lib/Storage';
import Dumper from './lib/Dumper';
export default class CreateVacancy extends React.Component {
static propTypes = {
params: React.PropTypes.object.isRequired,
};
constructor(props) {
super(props);
/* istanbul ignore next */
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.state = {
formLoading: false,
company: Storage.get('user-data').company,
vacancyId: this.props.params.id,
open_time: moment(),
close_time: moment(),
name: '',
description: '',
};
this.state.vacancyId && Server.get(`/vacancies/${this.state.vacancyId}/`).then((r) => {
this.setState({
description: r.description,
name: r.name,
open_time: moment(r.open_time),
close_time: moment(r.close_time),
});
});
}
handleChange = (e) => {
this.setState({ [e.target.name]: e.target.value });
};
handleSubmit = (e) => {
e.preventDefault();
this.setState({ formLoading: true });
const data = Object.assign({}, this.state);
data.open_time = data.open_time.format();
data.close_time = data.close_time.format();
data.company = this.state.company.id;
const url = this.state.vacancyId ? `/vacancies/${this.state.vacancyId}/` : '/vacancies/';
const method = this.state.vacancyId ? 'PATCH' : 'POST';
Server.sendRequest(url, method, data).then(() => {
browserHistory.push('/lowongan');
}, error => error.then((r) => {
this.modalAlert.open('Gagal Membuat Lowongan', Dumper.dump(r, ' '));
this.setState({ formLoading: false });
}));
};
render = () => (
<div className="create-lowongan" >
<ModalAlert ref={(modal) => { this.modalAlert = modal; }} />
<Segment className="form-segment">
<Header as="h2" icon textAlign="center">
<Icon name="briefcase" circular />
<Header.Content>
Lowongan KP
</Header.Content>
</Header>
<Form loading={this.state.formLoading} onSubmit={this.handleSubmit}>
<Form.Field label="Posisi" name="name" control={Input} onChange={this.handleChange} value={this.state.name} required />
<Form.TextArea
name="description"
label="Deskripsi"
placeholder="Deskripsi Lowongan..."
onChange={this.handleChange}
value={this.state.description} required
/>
<Form.Group widths="equal">
<Form.Field
className="open-time-field"
control={DatePicker}
label="Waktu Buka Lowongan"
selected={this.state.open_time}
onChange={date => this.setState({ open_time: date })}
required
/>
<Form.Field
className="close-time-field"
control={DatePicker}
label="Waktu Tutup Lowongan"
selected={this.state.close_time}
onChange={date => this.setState({ close_time: date })}
required
/>
</Form.Group>
<Button type="submit" primary floated="right">Submit</Button>
</Form>
</Segment>
</div>
);
}
import React from 'react';
import { Grid, Segment, Card } from 'semantic-ui-react';
import { Grid, Segment, Header, Card, Image } from 'semantic-ui-react';
import LoginForm from './components/LoginForm';
import RegisterModal from './components/RegisterModal';
import CompanyRegisterModal from './components/CompanyRegisterModal';
export default class Login extends React.Component {
......@@ -17,26 +17,37 @@ export default class Login extends React.Component {
};
render = () => (
<div className="halamanLogin">
<Grid columns={2} relaxed>
<div className="headerLogin">
<Header as="h2" icon textAlign="center" >
<Image src="/assets/img/logo.png" size="medium" centered />
<Header.Content >
Kanal Akses Pendaftaran KP Elektronik
</Header.Content>
</Header>
</div>
<Grid stackable columns={2} relaxed>
<Grid.Column>
<Segment basic>
<LoginForm type="company" header="Company Login" imgSrc="logo.png" imgSize="small" />
{this.props.children}
</Segment >
<div className="register">
<Card>
<Card centered className="register" >
<Card.Content>
<Card.Header>
New to us ?
</Card.Header>
<RegisterModal />
<Grid columns={2} relaxed>
<Grid.Column>
<Header as="h3">New to us ?</Header>
</Grid.Column>
<Grid.Column>
<CompanyRegisterModal />
</Grid.Column>
</Grid>
</Card.Content>
</Card>
</div>
</Grid.Column>
<Grid.Column>
......@@ -45,7 +56,6 @@ export default class Login extends React.Component {
{this.props.children}
</Segment>
</Grid.Column>
</Grid>
</div>
)
......
......@@ -6,38 +6,78 @@ 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' };
}
return { id: '0', type: 'error' };
}
constructor(props) {
super(props);
/* istanbul ignore next */
const role = VacancyPage.getRole();
this.state = {
email: '',
password: '',
errorFlag: false,
vacancies: [],
student: false,
id: role.id,
role: role.type,
};
Storage.getUserData().then(r => this.setState({ student: r.student }));
this.handleItemClick = this.handleItemClick.bind(this);
}
handleItemClick = (e, { name }) => this.setState({ activeItem: name });
render = () => (
this.state.student && (
<div className="halamanLowongan">
generateVacancies() {
if (this.state.role === 'student') {
return (
<Tabs selected={0}>
<Pane label="Semua Lowongan" >
<VacancyList key={1} studentId={this.state.student.id} url="/vacancies/" />
<VacancyList
key={1}
userId={this.state.id}
url="/vacancies/"
/>
</Pane>
<Pane label="Lamaran saya" >
<VacancyList key={2} status="Batal" studentId={this.state.student.id} url={`/students/${this.state.student.id}/applied-vacancies/`} />
<VacancyList
key={2}
status="Batal"
userId={this.state.id}
url={`/students/${this.state.id}/applied-vacancies/`}
/>
</Pane>
<Pane label="Lamaran Ditandai" >
<VacancyList key={3} studentId={this.state.student.id} url={`/students/${this.state.student.id}/bookmarked-vacancies/`} />
<VacancyList
key={3}
userId={this.state.id}
url={`/students/${this.state.id}/bookmarked-vacancies/`}
/>
</Pane>
</Tabs>
);
} else if (this.state.role === 'company') {
return (
<VacancyList key={1} userId={this.state.id} url={`/companies/${this.state.id}/vacancies/`} type="company" />
);
}
return (
<div>
<h3>
Anda tidak terautentifikasi. Harap logout dan login
kembali dengan akun yang benar
</h3>
</div>
)
);
);
}
render() {
return (
<div className="applicant">
{ this.generateVacancies() }
</div>
);
}
}
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import fetchMock from 'fetch-mock';
import CreateVacancy from '../CreateVacancy';
import Storage from '../lib/Storage';
describe('CreateVacancy', () => {
const companySession = {
url: 'http://localhost:8001/api/users/8/',
username: 'Tutuplapak',
email: '',
is_staff: false,
company: {
id: 3,
user: {
url: 'http://localhost:8001/api/users/8/',
username: 'Tutuplapak',
email: '',
is_staff: false,
},
name: 'Tutuplapak',
created: '2017-03-28T07:30:10.535000Z',
updated: '2017-03-28T07:30:10.535000Z',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla aliquet semper neque a fermentum. Duis ac tellus vitae augue iaculis ultrices. Curabitur commodo et neque nec feugiat. Morbi ac diam vel nunc commodo cursus. Phasellus nulla sapien, hendrerit vitae bibendum at, sollicitudin eu ante. Maecenas maximus, ante eu sollicitudin convallis, mauris nunc posuere risus, eu porttitor diam lacus vitae enim. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse at lectus a elit sollicitudin tempor. Nullam condimentum, justo nec tincidunt maximus, neque mi vulputate leo, sit amet lacinia massa ex eget sem. Duis ac erat facilisis, fringilla mauris in, consequat neque. In et neque consequat, vehicula magna at, efficitur ante. Mauris ac lacinia nibh.\r\n\r\nProin sagittis, lectus quis maximus varius, libero justo sollicitudin augue, non lacinia risus orci a enim. Curabitur iaculis enim quis ullamcorper commodo. Vivamus id nisi rhoncus, dignissim tellus quis, interdum est. Fusce sollicitudin eu libero ac feugiat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas semper posuere ex, sed accumsan libero iaculis faucibus. Fusce laoreet ac ligula ut consectetur. Donec tortor mauris, rutrum at sodales et, viverra in dolor. Sed bibendum elit et maximus volutpat. Phasellus justo ipsum, laoreet sit amet faucibus eu, ultricies suscipit mauris. Nullam aliquam libero eu ante ultrices mattis. Donec non justo hendrerit neque volutpat placerat. Ut euismod est nec sem mollis, sit amet porttitor massa rhoncus. Aenean id erat sit amet nunc ultrices scelerisque non in ipsum. Curabitur sollicitudin nulla id mi accumsan venenatis.',
verified: true,
logo: 'http://localhost:8001/files/company-logo/8a258a48-3bce-4873-b5d1-538b360d0059.png',
address: 'Jl. Kebayoran Baru nomor 13, Jakarta Barat',
},
supervisor: null,
student: null,
};
const errorSession = {
url: 'http://localhost:8001/api/users/8/',
username: 'Tutuplapak',
email: '',
is_staff: false,
company: null,
supervisor: null,
student: null,
};
it('renders for companies without problem', () => {
fetchMock.get('*', {});
Storage.set('user-data', companySession);
const createVacancy = ReactTestUtils.renderIntoDocument(
<CreateVacancy params={{ id: 1 }} />,
);
expect(createVacancy).to.exist;
fetchMock.restore();
});
it('renders without problem for error case', () => {
fetchMock.get('*', {});
Storage.set('user-data', errorSession);
const createVacancy = ReactTestUtils.renderIntoDocument(
<CreateVacancy params={{ id: 1 }} />,
);
expect(createVacancy).to.exist;
fetchMock.restore();
});
it('support handle change', () => {
fetchMock.get('*', {});
Storage.set('user-data', companySession);
const createVacancy = ReactTestUtils.renderIntoDocument(
<CreateVacancy params={{ id: 1 }} />,
);
createVacancy.setState({
name: 'stub',
description: 'stub',
});
createVacancy.handleChange({ target: { name: 'test', value: 'hue' } });
expect(createVacancy.state.test).to.equal('hue');
fetchMock.restore();
});
it('submit vacancy properly (loading)', () => {
fetchMock.post('*', 404);
fetchMock.get('*', {});
Storage.set('user-data', companySession);
const createVacancy = ReactTestUtils.renderIntoDocument(
<CreateVacancy params={{ id: undefined }} />,
);
createVacancy.setState({
name: 'stub',
description: 'stub',
});
const openField = ReactTestUtils.findRenderedDOMComponentWithClass(createVacancy, 'open-time-field');
const closeField = ReactTestUtils.findRenderedDOMComponentWithClass(createVacancy, 'close-time-field');
ReactTestUtils.Simulate.click(openField);
ReactTestUtils.Simulate.keyDown(openField, { key: 'Enter', keyCode: 13, which: 13 });
ReactTestUtils.Simulate.click(closeField);
ReactTestUtils.Simulate.keyDown(closeField, { key: 'Enter', keyCode: 13, which: 13 });
expect(createVacancy.state.formLoading).to.equal(false);
createVacancy.handleSubmit(new Event('click'));
expect(createVacancy.state.formLoading).to.equal(true);
fetchMock.restore();
});