How to use the react-admin.useNotify function in react-admin

To help you get started, we’ve selected a few react-admin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sony / nmos-js / Development / src / components / ActiveField.js View on Github external
const ActiveField = ({ className, source, record = {}, resource, ...rest }) => {
    const notify = useNotify();
    const [checked, setChecked] = React.useState(
        get(record, 'subscription.active')
    );

    const handleChange = (record, resource) => {
        toggleMasterEnable(record, resource)
            .then(({ data }) => setChecked(get(data, 'master_enable')))
            .catch(error => notify(error.toString(), 'warning'));
    };

    // When the page refresh button is pressed, the ActiveField will receive a
    // new record prop. When this happens we should update the state of the
    // switch to reflect the newest IS-04 data
    useEffect(() => {
        setChecked(get(record, 'subscription.active'));
    }, [record]);
github navidrome / navidrome / ui / src / common / BatchPlayButton.js View on Github external
export const BatchPlayButton = ({
  resource,
  selectedIds,
  action,
  label,
  icon,
  className,
}) => {
  const dispatch = useDispatch()
  const translate = useTranslate()
  const dataProvider = useDataProvider()
  const unselectAll = useUnselectAll()
  const notify = useNotify()

  const addToQueue = () => {
    dataProvider
      .getMany(resource, { ids: selectedIds })
      .then((response) => {
        // Add tracks to a map for easy lookup by ID, needed for the next step
        const tracks = response.data.reduce(
          (acc, cur) => ({ ...acc, [cur.id]: cur }),
          {}
        )
        // Add the tracks to the queue in the selection order
        dispatch(action(tracks, selectedIds))
      })
      .catch(() => {
        notify('ra.page.error', 'warning')
      })
github navidrome / navidrome / ui / src / playlist / PlaylistList.js View on Github external
const TogglePublicInput = ({ permissions, resource, record = {}, source }) => {
  const notify = useNotify()
  const [togglePublic] = useUpdate(
    resource,
    record.id,
    {
      ...record,
      public: !record.public,
    },
    {
      undoable: false,
      onFailure: (error) => {
        console.log(error)
        notify('ra.page.error', 'warning')
      },
    }
  )
github navidrome / navidrome / ui / src / user / UserEdit.js View on Github external
const UserEdit = (props) => {
  const { permissions } = props
  const translate = useTranslate()
  const [mutate] = useMutation()
  const notify = useNotify()
  const redirect = useRedirect()
  const refresh = useRefresh()

  const isMyself = props.id === localStorage.getItem('userId')
  const getNameHelperText = () =>
    isMyself && {
      helperText: translate('resources.user.helperTexts.name'),
    }
  const canDelete = permissions === 'admin' && !isMyself

  const save = useCallback(
    async (values) => {
      try {
        await mutate(
          {
            type: 'update',
github navidrome / navidrome / ui / src / common / ShuffleAllButton.js View on Github external
export const ShuffleAllButton = ({ filters }) => {
  const translate = useTranslate()
  const dataProvider = useDataProvider()
  const dispatch = useDispatch()
  const notify = useNotify()

  const handleOnClick = () => {
    dataProvider
      .getList('song', {
        pagination: { page: 1, perPage: 200 },
        sort: { field: 'random', order: 'ASC' },
        filter: filters,
      })
      .then((res) => {
        const data = {}
        res.data.forEach((song) => {
          data[song.id] = song
        })
        dispatch(playTracks(data))
      })
      .catch(() => {
github navidrome / navidrome / ui / src / personal / Personal.js View on Github external
const NotificationsToggle = () => {
  const translate = useTranslate()
  const dispatch = useDispatch()
  const notify = useNotify()
  const currentSetting = useSelector((state) => state.settings.notifications)
  const notAvailable = !('Notification' in window) || !window.isSecureContext

  if (
    (currentSetting && Notification.permission !== 'granted') ||
    notAvailable
  ) {
    dispatch(setNotificationsState(false))
  }

  const toggleNotifications = (event) => {
    if (currentSetting && !event.target.checked) {
      dispatch(setNotificationsState(false))
    } else {
      if (Notification.permission === 'denied') {
        notify(translate('message.notifications_blocked'), 'warning')
github navidrome / navidrome / ui / src / common / ContextMenus.js View on Github external
const ContextMenu = ({
  resource,
  showLove,
  record,
  color,
  className,
  songQueryParams,
}) => {
  const classes = useStyles({ color })
  const dataProvider = useDataProvider()
  const dispatch = useDispatch()
  const translate = useTranslate()
  const notify = useNotify()
  const [anchorEl, setAnchorEl] = useState(null)

  const options = {
    play: {
      enabled: true,
      needData: true,
      label: translate('resources.album.actions.playAll'),
      action: (data, ids) => dispatch(playTracks(data, ids)),
    },
    playNext: {
      enabled: true,
      needData: true,
      label: translate('resources.album.actions.playNext'),
      action: (data, ids) => dispatch(playNext(data, ids)),
    },
    addToQueue: {
github marmelab / react-admin / examples / demo / src / reviews / AcceptButton.js View on Github external
const AcceptButton = ({ record }) => {
    const translate = useTranslate();
    const notify = useNotify();
    const redirect = useRedirect();
    const [approve, { loading }] = useMutation(
        {
            type: 'UPDATE',
            resource: 'reviews',
            payload: { id: record.id, data: { status: 'accepted' } },
        },
        {
            undoable: true,
            onSuccess: () => {
                notify(
                    'resources.reviews.notification.approved_success',
                    'info',
                    {},
                    true
                );
github navidrome / navidrome / ui / src / layout / Login.js View on Github external
const Login = ({ location }) => {
  const [loading, setLoading] = useState(false)
  const translate = useTranslate()
  const notify = useNotify()
  const login = useLogin()
  const dispatch = useDispatch()

  const handleSubmit = useCallback(
    (auth) => {
      setLoading(true)
      dispatch(clearQueue())
      login(auth, location.state ? location.state.nextPathname : '/').catch(
        (error) => {
          setLoading(false)
          notify(
            typeof error === 'string'
              ? error
              : typeof error === 'undefined' || !error.message
              ? 'ra.auth.sign_in_error'
              : error.message,
github marmelab / react-admin / examples / simple / src / posts / ResetViewsButton.js View on Github external
const ResetViewsButton = ({ resource, selectedIds }) => {
    const notify = useNotify();
    const unselectAll = useUnselectAll();
    const refresh = useRefresh();
    const [updateMany, { loading }] = useUpdateMany(
        resource,
        selectedIds,
        { views: 0 },
        {
            onSuccess: () => {
                notify(
                    'ra.notification.updated',
                    'info',
                    { smart_count: selectedIds.length },
                    true
                );
                unselectAll(resource);
                refresh();