import React from "react";
import {inject, observer} from "mobx-react";
import {Link} from "react-router-dom";
import {Helmet} from "react-helmet";
import "../../styles/constants.scss";
import "../../styles/style.scss";
import "./style.scss";
import {LINKS} from "../../routes";
import startcase from "lodash.startcase";
import Route from "./routes";
import moment from 'moment';
import {Icon, Button, Modal, notification} from 'antd';
import {
Divider,
Drawer,
List,
ListItem,
IconMenu,
IconButton,
MenuItem,
DropDownMenu,
RaisedButton,
Paper,
Dialog,
Snackbar,
Toolbar, ToolbarGroup, ToolbarSeparator, ToolbarTitle, Badge
} from 'material-ui';
import IconUserCircle from 'material-ui/svg-icons/action/account-circle';
import ShoppingCart from 'material-ui/svg-icons/action/shopping-cart';
import DepositDialog from './../DepositDialog';
import WithdrawDialog from './../WithdrawDialog';
import IconMenus from 'material-ui/svg-icons/navigation/menu';
import LoadingDialog from '../LoadingDialog/index';
import * as _ from 'lodash'; // TODO: remove this, import only needed module from lodash
import PrintProvider, {Print, NoPrint} from 'react-easy-print';
import {black} from "material-ui/styles/colors";
import cinnamonSugar from 'cinnamon-sugar';
import ButterToast from 'butter-toast';
import 'material-design-icons/iconfont/material-icons.css';
import {grey400, darkBlack, lightBlack} from 'material-ui/styles/colors';
import {getMobileOperatingSystem} from '../../stores/firebase';
import Alert from "../../components/Alert";
import EmptyComponent from '../EmptyComponent';
import NumberFormat from 'react-number-format';
import faker from 'faker';
import { Route as RouteDOM } from 'react-router-dom'
faker.locale = 'id_ID';
@inject("appstate")
@observer
export default class App extends React.Component {
constructor(props) {
super(props);
this.props = props;
this.state = {
scriptTawkto: false,
redirect: false,
open: (window.innerWidth < 600) ? false : true,
openSecondary: false,
value: '',
additionalData: {},
valueMultiple: [''],
valueSingle: '',
visible: false,
selectedMenu: this.props.location.pathname,
projectId: 'project-id',
breadcrumbs: this
.props
.location
.pathname
.split('/')
.map(path => startcase(path))
};
this.defaultState = Object.assign({}, this.state);
this.user = props.appstate.user;
this.authStore = props.appstate.auth;
this.globalUI = props.appstate.globalUI;
this.http = props.appstate.http;
this.appstate = props.appstate;
this.settingStore = props.appstate.setting;
this.transactionStore = props.appstate.transaction;
this.dashboardStore = props.appstate.dashboard;
this.taskStore = props.appstate.task;
this.appStore = props.appstate.app;
this.profileStore = props.appstate.profile;
this.notificationStore = props.appstate.notification;
//
// if (getMobileOperatingSystem() !== 'iOS') {
// this.messaging = firebase.messaging();
// this.notification();
// }
}
openNotification(type, title, content, icon) {
if (type) {
notification[type]({
message: (title) ? title : 'Title',
description: (content) ? content :
This is the content of the notification. This is the content of the notification.
This is the content of the notification.
,
icon:
});
notification.open();
} else {
notification.open({
message: (title) ? title : 'Title',
description: (content) ? {content}
:
This is the content of the notification. This is the content of the notification.
This is the content of the notification.
,
icon:
});
}
};
notification = () => {
console.log('called again?');
this.messaging.onMessage((payload) => {
console.log("Message received cok.", payload);
// alert(payload.notification.body);
const toast = cinnamonSugar({
kind: 'crisp',
theme: 'info',
// picture: 'http://lorempixel.com/150/150/people',
title: {payload.notification.title}, // you can also add jsx code here!
// message: JSON.stringify(payload), // you can also add jsx code here!
message: payload.notification.body, // you can also add jsx code here!
toastTimeout: 4000,
icon: 'bell' // literally any font awesome 4.7 icon
// you may also add here regular butter-toast options, such as toastTimeout,
// name, sticky, etc..
});
ButterToast.raise(toast)
});
};
showModal = () => {
this.setState({
visible: true,
});
};
handleOk = (e) => {
console.log(e);
this.setState({
visible: false,
});
};
handleCancel = (e) => {
console.log(e);
this.setState({
visible: false,
});
};
componentDidMount() {
// this.checkIsLogin();
// this.settingStore.getAll();
// this.authStore.getProfile();
// this.user.getUserGeolocation();
// this.appStore.getAppType();
// this.profileStore.getProfile();
// this.notificationStore.getList()
notification.config({
placement: 'bottomRight',
duration: 10,
style: {
width: 350,
color: "black"
},
});
}
componentWillMount() {
}
componentWillReceiveProps(nextProps) {
// will be true
// const locationChanged = nextProps.location !== this.props.location;
//
// this.checkIsLogin();
}
checkIsLogin() {
// if (!this.authStore.isLoggedIn ) { console.log(this.props.history);
// this.props.history.replace(LINKS.LOGIN); }
}
willLogout() {
// Modal.confirm({
// title: 'Log out the system?',
// content: 'Are sure sure you want to log out the system?',
// okText: 'Confirm',
// cancelText: 'Cancel',
// visible: this.state.visible,
// zIndex: 3000,
// onOk: () => {
// this.authStore.logout();
// this.setState({
// visible: false,
// redirect: true
// });
// },
// onCancel: () => {
// this.setState({
// visible: false,
// });
// }
// });
}
openCreateProjectDialog() {
}
handleToggleIcon = () => this.setState({open: !this.state.open});
handleToggleIconSecondary = () => this.setState({openSecondary: !this.state.openSecondary});
handleClose = () => this.setState({open: false});
handleChangeSingle = (event, value) => {
this.setState({
valueSingle: value,
});
};
handleChangeMultiple = (event, value) => {
this.setState({
valueMultiple: value,
});
};
handleOpenMenu = () => {
this.setState({
openMenu: true,
});
}
handleOnRequestChange = (value) => {
this.setState({
openMenu: value,
});
}
handleChange = (event, index, value) => this.setState({value});
changeRoute = (path) => {
this.setState({selectedMenu: path});
if (window.innerWidth < 600) {
this.handleClose()
}
}
toggle = () => {
this.setState({
collapsed: !this.state.collapsed
});
};
toggleDrawer = () => {
this.setState({
open: !this.state.open
});
};
render() {
const {redirect} = this.state;
if (redirect) {
this.props.history.replace(LINKS.LOGIN);
// return
}
const styles = {
Paper: {
height: 38,
width: 38,
background: '#fff',
marginRight: 16,
padding: 4
},
ImageRounded: {
display: 'block',
borderRadius: '50%',
maxWidth: '100%',
marginTop: '0px'
}
};
// ROLE dan Menu
// agent, ga ada setting, member, task
// if (window && !window.Tawk_API) {
// const script = document.createElement("script");
// (this.settingStore.setting.tawkto_siteid && !this.state.scriptTawkto && this.appstate.userData.role === 'agent') ? (() => {
// const scriptText = document.createTextNode(`
// var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
// (function(){
// var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
// s1.async=true;
// s1.src='https://embed.tawk.to/${this.settingStore.setting.tawkto_siteid}/default';
// s1.charset='UTF-8';
// s1.setAttribute('crossorigin','*');
// s0.parentNode.insertBefore(s1,s0);
// })();`);
// script.appendChild(scriptText);
// script.async = true;
// document.body.appendChild(script);
// this.setState({scriptTawkto: true})
// })() : '';
// }
const {userData} = this.appstate;
// const applicationIcon = (this.settingStore.isIconEmpty) ? "/assets/images/bankbtn.png" : this.http.appendImagePath(this.settingStore.setting.icon);
const applicationIcon = "/assets/images/bankbtn.png";
let onNotifRowClick = (record) => {
// if(record.notification.type == 'order_seller' && _.get(record,'notification.additional_data.user_order_store_id',false) != false){
// return `${LINKS.ORDER}/${record.notification.additional_data.user_order_store_id}`;
// }
// else if(record.notification.type == 'order_seller' && _.get(record,'notification.additional_data.user_order_store_id',false) == false){
// return `${LINKS.ORDER}`;
// }
return `${LINKS.ORDER}`;
}
return (
BTN
this.toggleDrawer()}>
{/* */}
{/* this.toggleDrawer()}>*/}
{/**/}
{/**/}
{/*
*/}
}
className={(this.state.selectedMenu === '/app/dashboard') ? "menuAkunItem active" : 'menuAkunItem'}>Dashboard
}
className={(this.state.selectedMenu === '/app/flight') ? "menuAkunItem active" : 'menuAkunItem'}>Flight
}
className={(this.state.selectedMenu === '/app/hotel') ? "menuAkunItem active" : 'menuAkunItem'}>Hotel
}
className={(this.state.selectedMenu === '/app/car') ? "menuAkunItem active" : 'menuAkunItem'}>Car
}
className={(this.state.selectedMenu === '/app/shop') ? "menuAkunItem active" : 'menuAkunItem'}>Shop
}
className={(this.state.selectedMenu === '/app/vouchers') ? "menuAkunItem active" : 'menuAkunItem'}>Vouchers
{/*
*/}
Voucher
(
history.push(LINKS.WALLET)} className={'textVoucher'}>
)} />
Points
(
history.push(LINKS.WALLET)} className={'textPoints'}>
)} />
this.notificationStore.readAll()}
iconButtonElement={
{userData.role === 'admin' ? (
{this.notificationStore.unread_notif === 0 ?
:
}
) : (
{this.notificationStore.unread_notif === 0 ?
:
}
)}
}
>
{
(this.notificationStore.list.length) ?
this.notificationStore.list.slice(0, 5).map((item, index) => {
return (
}
primaryText={item.notification.title}
secondaryText={
{item.notification.description.substr(0, 40)}{(item.notification.description.length > 40) ? '...' : ""}
{moment(item.created_at).fromNow()}
}
secondaryTextLines={2}
/>
);
}) :
}
View All
}
/>
this.notificationStore.readAll()}
iconButtonElement={
{userData.role === 'admin' ? (
{this.notificationStore.unread_notif === 0 ?
:
}
) : (
{this.notificationStore.unread_notif === 0 ?
:
}
)}
}
>
{
(this.notificationStore.list.length) ?
this.notificationStore.list.slice(0, 5).map((item, index) => {
return (
}
primaryText={item.notification.title}
secondaryText={
{item.notification.description.substr(0, 40)}{(item.notification.description.length > 40) ? '...' : ""}
{moment(item.created_at).fromNow()}
}
secondaryTextLines={2}
/>
);
}) :
}
View All
}
/>
{!!this.profileStore.userProfile.photo ?
:
}
}
>
{this.authStore.userProfile.username || 'Username'}}
secondaryText={{_.capitalize(this.authStore.userProfile.role) || 'role'}
}
/>
);
}
}