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 { 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' import WalletComponent from "./WalletComponent"; import { APP_TYPE } from "../../config/app"; //new material ui import AppBar from '@material-ui/core/AppBar'; import Toolbar from '@material-ui/core/Toolbar'; import IconButton from '@material-ui/core/IconButton'; import Typography from '@material-ui/core/Typography'; import InputBase from '@material-ui/core/InputBase'; import Badge from '@material-ui/core/Badge'; import MenuItem from '@material-ui/core/MenuItem'; import Menu from '@material-ui/core/Menu'; import { withStyles } from '@material-ui/core/styles'; import MenuIcon from '@material-ui/icons/Menu'; import SearchIcon from '@material-ui/icons/Search'; import AccountCircle from '@material-ui/icons/AccountCircle'; import CartIcon from '@material-ui/icons/ShoppingCart'; import NotificationsIcon from '@material-ui/icons/Notifications'; import MoreIcon from '@material-ui/icons/MoreVert'; import CancelIcon from '@material-ui/icons/Cancel'; import ListIcon from '@material-ui/icons/FormatListBulleted'; import { styles } from './styles'; import Drawer from '@material-ui/core/Drawer'; // import Button from '@material-ui/core/Button'; import List from '@material-ui/core/List'; import Divider from '@material-ui/core/Divider'; import ListItem from '@material-ui/core/ListItem'; import ListItemIcon from '@material-ui/core/ListItemIcon'; import ListItemText from '@material-ui/core/ListItemText'; import InboxIcon from '@material-ui/icons/MoveToInbox'; import MailIcon from '@material-ui/icons/Mail'; faker.locale = 'id_ID'; @inject("appstate") @observer 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)), anchorEl: null, mobileMoreAnchorEl: null, left: false, }; 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(); setTimeout(() => { console.log(this.authStore.userProfile, 'this.authStore.userProfile this.authStore.userProfile'); }, 2500) // 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, }); } }); } 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 }); }; //new handleProfileMenuOpen = event => { this.setState({ anchorEl: event.currentTarget }); }; handleMenuClose = () => { this.setState({ anchorEl: null }); this.handleMobileMenuClose(); }; handleMobileMenuOpen = event => { this.setState({ mobileMoreAnchorEl: event.currentTarget }); }; handleMobileMenuClose = () => { this.setState({ mobileMoreAnchorEl: null }); }; toggleDrawerNew = (open) => () => { this.setState({ left: open, }); }; render() { const { anchorEl, mobileMoreAnchorEl } = this.state; const { classes } = this.props; 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' } }; const { userData } = this.appstate; // const applicationIcon = (this.settingStore.isIconEmpty) ? "/assets/images/bankbtn.png" : this.http.appendImagePath(this.settingStore.setting.icon); // let applicationIcon = "http://giift.asacreative.com/giift_logo_wide.4d15de72.png"; let applicationIcon = require('../../../../assets/images/logo_new.png'); let applicationName = 'Giift'; if (APP_TYPE === 'btn') { applicationIcon = "https://www.niaga.asia/wp-content/uploads/2021/02/IMG-20210223-WA0025.jpg"; applicationName = "KB Bukopin"; } 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}`; } const isMenuOpen = Boolean(anchorEl); const isMobileMenuOpen = Boolean(mobileMoreAnchorEl); const renderMenu = ( Profile Transaction {/* */} Sign Out {/* */} ); const renderMobileMenu = ( {window.location.pathname.split("/")[2] == "shop" ? (

Cart

) : ""}

Notifications

Profile

Transaction

{/* */}

Sign Out

{/* */}
); const sideList = (
Home {/* Flight Hotel Car Shop Vouchers */}
); return (
{applicationName}
{window.location.pathname.split("/")[2] == "shop" ? ( ) : ""}
{renderMenu} {renderMobileMenu}
{sideList}
{/* this.toggleDrawer()}> this.toggleDrawer()}> Home Flight Hotel Car Shop Vouchers {window.location.pathname.split("/")[2] == "shop" ? ( this.notificationStore.readAll()} iconButtonElement={
} > { (this.notificationStore.list.length) ? this.notificationStore.list.slice(0, 5).map((item, index) => { return (

{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.props.appstate.userData.email|| 'Username'}} secondaryText={

{_.capitalize(this.props.appstate.userData.role) || 'role'}

} />
{ }} style={{ fontSize: 14 }} primaryText="Sign out" />
*/}
); } } export default withStyles(styles)(App);