React-admin: showNotification function not working, no errors reported

Created on 11 Jul 2019  路  6Comments  路  Source: marmelab/react-admin

Expecting a success or warning message appear at the bottom of the screen when I call
showNotification('My Message');

But instead, nothing is occurring, not even an error message. The "done approving" or "done rejecting" console logs appear in the console right before showNotification is called.

import React, {Fragment, Component} from 'react';
import { Responsive, List, SimpleList, Datagrid, TextField, DateField, EditButton, ImageField, Pagination} from 'react-admin';
import { CardActions, ExportButton, RefreshButton, Button } from 'react-admin';
import MainTitle from './MainTitle';
import { withStyles } from '@material-ui/core/styles';
import { Edit, SimpleForm, Toolbar, UPDATE } from 'react-admin';
import Breadcrumbs from "./Breadcrumbs";
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { showNotification } from 'react-admin';
import { push as pushAction } from 'react-router-redux';
import dataProvider from './GoTribeDataProvider';
//import { put } from 'redux-saga/effects';
import { showNotification } from 'react-admin';

class ApproveButton extends Component {
    handleClick = () => {
      const { push, record, showNotification } = this.props;
      dataProvider(UPDATE, 'nutrition', { id: record.id, data: {is_approved: 'true'} })
          .then((test) => {
              console.log("done approving ", test.data.message);
              showNotification(test.data.message);
              window.location = "/#/nutrition";
          })
          .catch((e) => {
            console.log("e ", e);
            //alert("Internal Exception rejecting nutrition item");
            showNotification(test.data.message);
            window.location = "/#/nutrition";
          });
    }
    render() {
        return <Button variant="raised" label='Approve' onClick={this.handleClick} />;
    }
}
class RejectButton extends Component {
    handleClick = () => {
      const { push, record, showNotification } = this.props;
      dataProvider(UPDATE, 'nutrition', { id: record.id, data: {is_approved: 'false'} })
          .then((test) => {
              console.log("done rejecting ", test);
              showNotification('Nutrition rejected');
              window.location = "/#/nutrition";
          })
          .catch((e) => {
            showNotification("Internal Exception rejecting nutrition item")
            window.location = "/#/nutrition";
          });
    }
    render() {
        return <Button variant="flat" label='Reject' onClick={this.handleClick} />;
    }
}
const NutritionEditToolbar = props => (
    <Toolbar {...props} >
        <ApproveButton/>
        <RejectButton/>
    </Toolbar>
);
export const NutritionEdit = props => (
    <Edit actions={<NutritionEditActions />} title={<EditTitle />}  {...props} >
        <SimpleForm style={{width: "95%"}}  toolbar={<NutritionEditToolbar />} >
            <Breadcrumbs />
            <TextField source="name" />
            <TextField source="tags" />
            <ImageTextFieldInput style={{width: "95%"}} source="imageUrl" />
        </SimpleForm>
    </Edit>
);
ApproveButton.propTypes = {
    push: PropTypes.func,
    record: PropTypes.object,
    showNotification: PropTypes.func,
};
RejectButton.propTypes = {
    push: PropTypes.func,
    record: PropTypes.object,
    showNotification: PropTypes.func,
};
export default connect(null, {
    showNotification: showNotification,
    push: pushAction,
})(ApproveButton, RejectButton);

Other information:
I omitted the NutritionEditActions, EditTitle, imageEditStyles, and ImageTextFieldInput.

Environment

  • React-admin version: ^2.9.4
  • React version: ^16.7.0
  • Browser: chrome
needs more info

Most helpful comment

I found that I missed to render <Notification/> component inside my custom <AppLayout/>.

All 6 comments

Unable to reproduce the error, please fork the react-admin codesandbox to provide a use case that triggers the bug. That being said, I suspect it's a problem on your side - connect only allows to wrap one component.

The same issue for me. It works good on custom LoginPage, but don't work on any another page created with react-admin.

I found that I missed to render <Notification/> component inside my custom <AppLayout/>.

I still have the same issue.
https://codesandbox.io/s/simple-6nzp0
please see /src/posts/postEdit.js line 73.
no notification show.

Could you add a working code on the sandbox?
@djhi @fzaninotto

Please ask questions on StackOverflow

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fzaninotto picture fzaninotto  路  3Comments

ilaif picture ilaif  路  3Comments

mbj36 picture mbj36  路  3Comments

phacks picture phacks  路  3Comments

ericwb picture ericwb  路  3Comments