Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 9aaede83 authored by Zamil Majdy's avatar Zamil Majdy
Browse files

[#140652771] [#21] [Green] Add delete vacancy implementation

parent 8d29ad34
No related branches found
No related tags found
No related merge requests found
......@@ -8,9 +8,11 @@ const defaultImage = 'http://semantic-ui.com/images/wireframe/image.png';
export default class CompanyVacancy extends React.Component {
static propTypes = {
data: React.PropTypes.object.isRequired,
deleteCallback: React.PropTypes.func.isRequired,
deleteCallback: React.PropTypes.func,
};
static defaultProps = { deleteCallback: () => {} };
constructor(props) {
super(props);
moment.locale('id');
......
......@@ -22,7 +22,7 @@ export default class LoginForm extends React.Component {
constructor(props) {
super(props);
/* istanbul ignore next */
this.state = { username: '', password: '', errorFlag: false };
this.state = { username: '', password: '', errorFlag: false, loading: false };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
......@@ -38,12 +38,12 @@ export default class LoginForm extends React.Component {
username: this.state.username,
password: this.state.password,
};
this.setState({ loading: true });
Server.post('/login/', data).then((response) => {
Storage.set('user-data', response);
browserHistory.push('/home');
}, () => {
this.setState({ errorFlag: true });
this.setState({ errorFlag: true, loading: false });
});
}
......@@ -56,8 +56,8 @@ export default class LoginForm extends React.Component {
<Image src={`./assets/img/${this.props.imgSrc}`} size={this.props.imgSize} verticalAlign="middle" /> <span>{ this.props.header }</span>
</Segment>
<Segment inverted className='header' >
<Form onSubmit={e => this.handleSubmit(e)} error={this.state.errorFlag}>
<Segment inverted className="header" >
<Form loading={this.state.loading} onSubmit={e => this.handleSubmit(e)} error={this.state.errorFlag}>
<Form.Group widths="equal">
<Form.Field>
<label htmlFor="id"> Username </label>
......
......@@ -4,6 +4,7 @@ import { Link } from 'react-router';
import Vacancy from './Vacancy';
import CompanyVacancy from './CompanyVacancy';
import Server from '../lib/Server';
import ModalAlert from '../components/ModalAlert';
export default class VacancyList extends React.Component {
......@@ -49,6 +50,15 @@ export default class VacancyList extends React.Component {
});
}
deleteVacancy = id => Server.delete(`/vacancies/${id}/`, this.state).then(() => {
this.modalAlert.open('Hapus Lowongan', 'Lowongan berhasil dihapus');
const newVacancies = [];
this.state.vacancies.map(vacancy => vacancy.id !== id && newVacancies.push(vacancy));
this.setState({ vacancies: newVacancies });
}, error => error.then((r) => {
this.modalAlert.open('Gagal Menghapus Lowongan', r.error);
}));
generateVacancies() {
if (this.props.type === 'student') {
return this.state.vacancies.map(vacancy =>
......@@ -63,19 +73,20 @@ export default class VacancyList extends React.Component {
);
}
return this.state.vacancies.map(vacancy =>
(
<CompanyVacancy key={vacancy.id} data={vacancy} />
),
return this.state.vacancies.map(vacancy => (<CompanyVacancy
key={vacancy.id}
data={vacancy}
deleteCallback={() => this.deleteVacancy(vacancy.id)}
/>),
);
}
companyHeader() {
if (this.props.type === 'company') {
return (
<Grid style={{ padding: '10px' }}>
<Button fluid size="mini" icon="eye" labelPosition="left" color="facebook" content="Lihat Semua Pendaftar" />
<Button fluid size="mini" as={Link} to="/buat-lowongan" icon="add" labelPosition="left" content="Tambah Lowongan Baru" color="teal" />
<Grid textAlign="center">
<Button size="tiny" icon="eye" labelPosition="left" color="facebook" content="Lihat Semua Pendaftar" />
<Button size="tiny" as={Link} to="/buat-lowongan" icon="add" labelPosition="left" content="Tambah Lowongan Baru" color="teal" />
</Grid>
);
}
......@@ -85,13 +96,12 @@ export default class VacancyList extends React.Component {
render = () => (
<Segment>
<ModalAlert ref={(modal) => { this.modalAlert = modal; }} />
<Grid container columns="eleven" doubling>
{ this.companyHeader() }
<Item.Group relaxed style={{ width: '100%' }}>
{ this.generateVacancies() }
</Item.Group>
</Grid>
</Segment>
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment