Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 4a3f519a authored by M. Reza Qorib's avatar M. Reza Qorib
Browse files

[#140654507] #12 #13 change vacancy stuff component property type to get json,...

[#140654507] #12 #13 change vacancy stuff component property type to get json, improve Login component
parent c04c2533
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"rules": { "rules": {
"func-names": ["error", "never"], "func-names": ["error", "never"],
"react/prefer-stateless-function": [0, { "ignorePureComponents": true }], "react/prefer-stateless-function": [0, { "ignorePureComponents": true }],
"react/forbid-prop-types": [0],
"import/extensions": ["off", "never"], "import/extensions": ["off", "never"],
"import/no-unresolved": 0, "import/no-unresolved": 0,
"no-underscore-dangle" : 0, "no-underscore-dangle" : 0,
......
...@@ -19,14 +19,14 @@ export default class Login extends React.Component { ...@@ -19,14 +19,14 @@ export default class Login extends React.Component {
<Grid columns={2} relaxed> <Grid columns={2} relaxed>
<Grid.Column> <Grid.Column>
<Segment basic> <Segment basic>
<LoginForm url="/login/company" imgSrc="logo.png" imgSize="small" /> <LoginForm type="company" header="Company Login" imgSrc="logo.png" imgSize="small" />
{this.props.children} {this.props.children}
</Segment> </Segment>
</Grid.Column> </Grid.Column>
<Grid.Column> <Grid.Column>
<Segment basic> <Segment basic>
<LoginForm url="/login/sso" imgSrc="UI.png" imgSize="tiny" /> <LoginForm type="sso-ui" header="SSO Login" imgSrc="UI.png" imgSize="tiny" />
{this.props.children} {this.props.children}
</Segment> </Segment>
</Grid.Column> </Grid.Column>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import React from 'react'; import React from 'react';
import ReactTestUtils from 'react-addons-test-utils'; import ReactTestUtils from 'react-addons-test-utils';
import VacancyList from '../../components/VacancyList'; import VacancyList from '../../components/VacancyList';
import ModalPendaftaran from '../../components/ModalPendaftaran'; import Lowongan from '../../components/Lowongan';
describe('VacancyList', () => { describe('VacancyList', () => {
it('created without problem', () => { it('created without problem', () => {
...@@ -12,11 +12,11 @@ describe('VacancyList', () => { ...@@ -12,11 +12,11 @@ describe('VacancyList', () => {
it('renders without problem', () => { it('renders without problem', () => {
const vacancyList = ReactTestUtils.renderIntoDocument( const vacancyList = ReactTestUtils.renderIntoDocument(
<VacancyList header="header" content="content" buttonTitle="submit" />); <VacancyList vacancies={[{ key: 'value' }, { key2: 'value2' }]} />);
expect(vacancyList).to.exist; expect(vacancyList).to.exist;
React.Children.forEach(vacancyList.props.children, (child) => { React.Children.forEach(vacancyList.props.children, (child) => {
expect(child).to.be.an.instanceof(ModalPendaftaran); expect(child).to.be.an.instanceof(Lowongan);
}); });
}); });
}); });
import React from 'react'; import React from 'react';
import { Form, Input, Button, Image } from 'semantic-ui-react'; import { Form, Input, Button, Message, Image } from 'semantic-ui-react';
import { browserHistory } from 'react-router';
import Server from '../lib/server'; import Server from '../lib/server';
export default class LoginForm extends React.Component { export default class LoginForm extends React.Component {
static propTypes = { static propTypes = {
url: React.PropTypes.string.isRequired, type: React.PropTypes.string.isRequired,
imgSrc: React.PropTypes.string, imgSrc: React.PropTypes.string,
imgSize: React.PropTypes.string, imgSize: React.PropTypes.string,
header: React.PropTypes.string,
}; };
static defaultProps = { static defaultProps = {
imgSrc: '', imgSrc: '',
imgSize: 'small', imgSize: 'small',
header: 'Login',
}; };
constructor(props) { constructor(props) {
super(props); super(props);
/* istanbul ignore next */ /* istanbul ignore next */
this.state = { email: '', password: '' }; this.state = { email: '', password: '', errorFlag: false };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
} }
handleChange(name, event) { handleChange(event, name) {
this.setState({ [name]: event.target.value }); this.setState({ [name]: event.target.value });
} }
handleSubmit() { handleSubmit(event) {
Server.post(this.props.url, this.state); event.preventDefault();
const data = {
type: this.props.type,
email: this.state.email,
password: this.state.password
}
Server.post('api/login/', data).then(() => {
browserHistory.push('/home');
}, () => {
this.setState({ errorFlag: true });
});
} }
render = () => ( render = () => (
<div className="formLogin" > <div className="formLogin" >
<Form onSubmit={(e) => this.handleSubmit(e)} error={this.state.errorFlag}>
<Image src={`./assets/img/${this.props.imgSrc}`} size={this.props.imgSize} verticalAlign="middle" /> <span>Company Login</span> <div className="formHeader">
<Image src={`./assets/img/${this.props.imgSrc}`} size={this.props.imgSize} verticalAlign="middle" /> <span>{ this.props.header }</span>
<Form onSubmit={this.handleSubmit}> </div>
<Form.Group widths="equal"> <Form.Group widths="equal">
<Form.Field> <Form.Field required>
<label htmlFor="id"> Email </label> <label htmlFor="id"> Email </label>
<Input type="text" id="email" icon="user" iconPosition="left" placeholder="email" onChange={this.handleChange.bind(this, 'email')} /> <Input type="text" id="email" icon="user" iconPosition="left" placeholder="email" onChange={(e) => this.handleChange(e, 'email')} required />
</Form.Field> </Form.Field>
</Form.Group> </Form.Group>
<Form.Group widths="equal"> <Form.Group widths="equal">
<Form.Field> <Form.Field required>
<label htmlFor="password"> Password </label> <label htmlFor="password"> Password </label>
<Input type="password" id="password" icon="key" iconPosition="left" placeholder="password" onChange={this.handleChange.bind(this, 'password')} /> <Input type="password" id="password" icon="key" iconPosition="left" placeholder="password" onChange={(e) => this.handleChange(e, 'password')} required />
</Form.Field> </Form.Field>
</Form.Group> </Form.Group>
<Button type="submit" fluid color="blue">Login</Button> <Button type="submit" fluid color="blue">Login</Button>
<Message
error
content="Login gagal: email atau password salah."
/>
</Form> </Form>
</div> </div>
......
...@@ -21,7 +21,7 @@ export default class Lowongan extends React.Component { ...@@ -21,7 +21,7 @@ export default class Lowongan extends React.Component {
<Item.Description>{this.props.content}</Item.Description> <Item.Description>{this.props.content}</Item.Description>
<Item.Extra> <Item.Extra>
<div className="daftar"> <div className="daftar">
<ModalPendaftaran content={{ tes: 'dor' }} header="Pendaftaran Lowongan" buttontTitle="Daftar" /> <ModalPendaftaran data={{ tes: 'dor' }} buttonTitle="Daftar" />
</div> </div>
</Item.Extra> </Item.Extra>
</Item.Content> </Item.Content>
......
import React from 'react'; import React from 'react';
import { Modal, Button, Icon, TextArea, Form } from 'semantic-ui-react'; import { Modal, Button, Icon, TextArea, Form } from 'semantic-ui-react';
import ModalAlert from './ModalAlert'; import ModalAlert from './ModalAlert';
import Server from '../lib/Server';
export default class ModalPendaftaran extends React.Component { export default class ModalPendaftaran extends React.Component {
static propTypes = { static propTypes = {
header: React.PropTypes.oneOfType([ data: React.PropTypes.object.isRequired,
React.PropTypes.node, id: React.PropTypes.number.isRequired,
React.PropTypes.string, buttonTitle: React.PropTypes.string.isRequired,
]).isRequired, };
content: React.PropTypes.oneOfType([
React.PropTypes.node, static successResponse = 'Pendaftaran anda berhasil direkam. Harap menunggu kabar selanjutnya dari pihak yang terkait\n';
React.PropTypes.string, static failedResponse = 'Maaf pendaftaran yang anda lakukan gagal. Harap ulangi pendaftaran atau hubungi administrator\n';
]).isRequired,
buttontTitle: React.PropTypes.oneOfType([ constructor(props) {
React.PropTypes.node, super(props);
React.PropTypes.string, /* istanbul ignore next */
]).isRequired, this.state = {
modalOpen: false,
responseHeader: 'Menghubungkan ke Server',
responseText: 'Terima kasih sudah mendaftar!',
coverLetter: '',
}; };
this.handleChange = this.handleChange.bind(this);
}
state = { modalOpen: false }; handleChange(event) {
this.setState({ coverLetter: event.target.value });
}
handleOpen = () => this.setState({ handleOpen() {
modalOpen: true, const data = { coverLetter: this.state.coverLetter };
Server.post(`/students/${this.props.id}/application`, data).then((data) => {
this.setState({
responseHeader: 'Pendaftaran Berhasil',
responseText: this.successResponse + JSON.stringify(data),
});
}, (error) => {
this.setState({
responseHeader: 'Pendaftaran Gagal',
responseText: this.failedResponse + JSON.stringify(error),
}); });
});
this.setState({ modalOpen: true });
}
handleClose = () => this.setState({ handleClose = () => this.setState({
modalOpen: false, modalOpen: false,
...@@ -31,20 +51,20 @@ export default class ModalPendaftaran extends React.Component { ...@@ -31,20 +51,20 @@ export default class ModalPendaftaran extends React.Component {
render = () => ( render = () => (
<Modal <Modal
trigger={<Button onClick={this.handleOpen} >{this.props.buttontTitle}</Button>} trigger={<Button onClick={this.handleOpen} >{this.props.buttonTitle}</Button>}
closeIcon="close" closeIcon="close"
open={this.state.modalOpen} open={this.state.modalOpen}
onClose={this.handleClose} onClose={this.handleClose}
> >
<Modal.Header>{this.props.header}</Modal.Header> <Modal.Header>{this.props.data}</Modal.Header>
<Modal.Content image> <Modal.Content image>
<div className="image"> <div className="image">
<Icon name="right arrow" /> <Icon name="right arrow" />
</div> </div>
<Modal.Description> <Modal.Description>
<Modal.Header> <h3> Deskripsi Lowongan </h3></Modal.Header> <Modal.Header> <h3> Deskripsi Lowongan </h3></Modal.Header>
{this.props.content} {this.props.data}
<div className="linkCV"> <div className="linkCV">
<a> your latest CV </a> <a> your latest CV </a>
...@@ -53,14 +73,18 @@ export default class ModalPendaftaran extends React.Component { ...@@ -53,14 +73,18 @@ export default class ModalPendaftaran extends React.Component {
<div className="coverLetter"> <div className="coverLetter">
<h5> Write your Cover Letter </h5> <h5> Write your Cover Letter </h5>
<Form> <Form>
<TextArea placeholder="Tell us more" /> <TextArea placeholder="Tell us more" onChange={this.handleChange} />
</Form> </Form>
</div> </div>
</Modal.Description> </Modal.Description>
</Modal.Content> </Modal.Content>
<Modal.Actions> <Modal.Actions>
<ModalAlert onChangeValue={this.handleClose} header="Pendaftaran" content="Terima kasih sudah mendaftar!" /> <ModalAlert
onChangeValue={this.handleClose}
header={this.state.responseHeader}
content={this.state.responseText}
/>
</Modal.Actions> </Modal.Actions>
</Modal> </Modal>
) )
......
...@@ -4,22 +4,17 @@ import Lowongan from './Lowongan'; ...@@ -4,22 +4,17 @@ import Lowongan from './Lowongan';
export default class VacancyList extends React.Component { export default class VacancyList extends React.Component {
static propTypes = { static propTypes = {
vacancies: React.PropTypes.array vacancies: React.PropTypes.array.isRequired,
};
static defaultProps = {
vacancies: [],
}; };
generateVacancies() { generateVacancies() {
return( return this.props.vacancies.map((vacancy) =>
this.props.vacancies.map((vacancyData) => <Lowongan data={vacancy} />,
<Lowongan data={vacancyData}/>)
); );
} }
render = () => ( render = () => (
<div className="vscancyList" >{ this.generateVacancies() } <div className="vacancyList" >{ this.generateVacancies() }
</div> </div>
) )
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment