import React from 'react'; import PropTypes from 'prop-types'; import { Menu, Image, Popup, Card, Button } from 'semantic-ui-react'; import { Link, browserHistory } from 'react-router'; import Server from '../lib/Server'; import Storage from '../lib/Storage'; import moment from 'moment'; import ModalAlert from './ModalAlert'; import CompanyInfo from './CompanyInfo'; var quotes = require('starwars'); const defaultPicture = 'https://semantic-ui.com/images/avatar/small/elliot.jpg'; export default class TopMenu extends React.Component { static getInfo(user) { const adminRole = { name: 'admin', user: { email: '', }, photo: null, }; const role = user.role; if (role === 'student') { return user.data.student; } else if (role === 'company') { return user.data.company; } else if (role === 'supervisor') { return user.data.supervisor; } return adminRole; } static propTypes = { user: PropTypes.object.isRequired, }; constructor(props) { super(props); /* istanbul ignore next */ moment.locale('id'); this.state = { // activeItem: Storage.get('menu-active-state'), activeItem: this.menuActiveState(), logoutLoading: false, currentDate: moment(new Date()).format('dddd') + ', ' + moment(new Date()).format('LL'), todayQuote: quotes(), isOpen: false, applianceInformation: "1. Pastikan anda sudah mengupdate profile anda\n" + "2. Cari lowongan internship yang ada di tab lowongan\n" + "3. Klik tombol 'Detail'\n" + "4. Pastikan persyaratan sudah terpenuhi\n" + "5. Jelaskan mengapa anda ingin mengikuti lowongan internship tersebut di 'Cover Letter'\n"+ "6. Klik tombol 'Daftar'\n", kapeDescription: "Kanal Akses Pendaftaran KP Elektronik", welcomeStudent: "Selamat Datang, " }; this.logout = this.logout.bind(this); this.logoutCompany = this.logoutCompany.bind(this); this.handleModalClick = this.handleModalClick.bind(this); console.log(this.state.todayQuote); console.log(Storage.get('menu-active-state')); } handleItemClick = (e, { name }) => { if(name === 'Logo') { this.setState({ activeItem: 'Beranda' }); } else { this.setState({ activeItem: name }); } } handleOpen = () => { this.setState({ isOpen: true }); }; handleClose = () => { this.setState({ isOpen: false }); clearTimeout(this.timeout) }; handleModalClick() { this.modalAlert.open( 'Cara mendaftar di lowongan yang ada:', this.state.applianceInformation, ); } logout = (e) => { e.preventDefault(); this.setState({ logoutLoading: true }); Server.get('/api-auth/logout/?next=/', true).then( () => { Storage.clear(); browserHistory.push('/login'); }, () => this.setState({ logoutLoading: false }), ); }; logoutCompany = /* istanbul ignore next */ (e) => { e.preventDefault(); const userData = Storage.get('user-data'); userData.company = null; Storage.set('user-data', userData); window.location.replace('/home'); }; menuActiveState() { if (Storage.get('menu-active-state') == null) { return 'Beranda'; } return Storage.get('menu-active-state'); } render() { const { activeItem } = this.state; const data = TopMenu.getInfo(this.props.user); const btn = ( ); return (
{this.state.todayQuote}
{this.props.user.data.is_staff && this.props.user.data.company && (

Anda login sebagai perusahaan: {this.props.user.data.company.name} (# {this.props.user.data.company.id}). Untuk kembali menjadi admin, klik{' '} {' '} link ini

)} { this.modalAlert = modal; }} /> {this.state.kapeDescription} {this.props.user.role === 'student' && ( {this.state.welcomeStudent} {data.name} )} {this.props.user.role === 'student' && ( {btn} )} {this.props.user.role === 'company' && ( Company Info )} {this.state.currentDate} { this.props.user.role === 'company' && } { this.props.user.data.is_staff && } } open={this.state.isOpen} on='click' onClose={this.handleClose} onOpen={this.handleOpen} > { this.props.user.role === 'student' &&
}
); } }