PHP 8.2.30
Preview: notice.js Size: 2.61 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/lib/frontend/components/app/notice.js

import { Box, MessageBox } from '@adminjs/design-system';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { connect } from 'react-redux';
import allowOverride from '../../hoc/allow-override.js';
import { useTranslation } from '../../hooks/index.js';
import { dropNotice } from '../../store/actions/drop-notice.js';
import { setNoticeProgress } from '../../store/actions/set-notice-progress.js';
const TIME_TO_DISAPPEAR = 3;
const NoticeElement = props => {
  const {
    drop,
    notice,
    notifyProgress
  } = props;
  const [progress, setProgress] = useState(0);
  const intervalRef = useRef();
  const {
    tm,
    i18n: {
      language
    }
  } = useTranslation();
  const message = useMemo(() => tm(notice.message, notice.resourceId, notice.options), [notice.id, language]);
  const variant = notice.type === 'error' ? 'danger' : notice.type ?? 'info';
  useEffect(() => {
    intervalRef.current = window.setInterval(() => {
      const _progress = progress + 100 / TIME_TO_DISAPPEAR;
      notifyProgress({
        noticeId: notice.id,
        progress
      });
      setProgress(_progress);
      return _progress;
    }, 1000);
    return () => {
      clearInterval(intervalRef.current);
    };
  }, [notice]);
  useEffect(() => {
    if (progress >= 100) {
      drop();
    }
  }, [drop, progress]);
  return /*#__PURE__*/React.createElement(MessageBox, {
    style: {
      minWidth: '480px'
    },
    message: message,
    variant: variant,
    onCloseClick: drop
  }, notice.body);
};
const NoticeBox = props => {
  const {
    drop,
    notices,
    notifyProgress
  } = props;
  if (!notices.length) return null;
  return /*#__PURE__*/React.createElement(Box, {
    as: "div",
    "data-testid": "notice-wrapper",
    "data-css": "notice-wrapper",
    flex: true,
    flexDirection: "column",
    p: "sm",
    style: {
      gap: 4
    }
  }, notices.map(notice => /*#__PURE__*/React.createElement(NoticeElement, {
    key: notice.id,
    notice: notice,
    drop: () => drop(notice.id),
    notifyProgress: notifyProgress
  })));
};
const mapStateToProps = state => ({
  notices: state.notices
});
const mapDispatchToProps = dispatch => ({
  drop: noticeId => dispatch(dropNotice(noticeId)),
  notifyProgress: ({
    noticeId,
    progress
  }) => dispatch(setNoticeProgress({
    noticeId,
    progress
  }))
});
const ConnectedNoticeBox = connect(mapStateToProps, mapDispatchToProps)(NoticeBox);
const OverridableConnectedNoticeBox = allowOverride(ConnectedNoticeBox, 'NoticeBox');
export { OverridableConnectedNoticeBox as NoticeBox, OverridableConnectedNoticeBox as default, ConnectedNoticeBox as OriginalNoticeBox };

Directory Contents

Dirs: 6 × Files: 17

Name Size Perms Modified Actions
- drwxr-xr-x 2026-02-28 00:31:42
Edit Download
- drwxr-xr-x 2026-02-28 00:31:50
Edit Download
- drwxr-xr-x 2026-02-28 00:31:44
Edit Download
- drwxr-xr-x 2026-02-28 00:31:48
Edit Download
sidebar DIR
- drwxr-xr-x 2026-02-28 00:31:50
Edit Download
utils DIR
- drwxr-xr-x 2026-02-28 00:31:48
Edit Download
335 B lrw-r--r-- 2026-02-28 00:29:12
Edit Download
303 B lrw-r--r-- 2026-02-28 00:31:14
Edit Download
481 B lrw-r--r-- 2026-02-28 00:31:14
Edit Download
2.43 KB lrw-r--r-- 2026-02-28 00:31:14
Edit Download
2.87 KB lrw-r--r-- 2026-02-28 00:31:22
Edit Download
6.16 KB lrw-r--r-- 2026-02-28 00:31:26
Edit Download
3.20 KB lrw-r--r-- 2026-02-28 00:31:28
Edit Download
1.02 KB lrw-r--r-- 2026-02-28 00:31:28
Edit Download
2.15 KB lrw-r--r-- 2026-02-28 00:31:28
Edit Download
3.87 KB lrw-r--r-- 2026-02-28 00:31:30
Edit Download
238 B lrw-r--r-- 2026-02-28 00:31:34
Edit Download
775 B lrw-r--r-- 2026-02-28 00:31:44
Edit Download
971 B lrw-r--r-- 2026-02-28 00:31:46
Edit Download
2.61 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
1.40 KB lrw-r--r-- 2026-02-28 00:31:50
Edit Download
1.72 KB lrw-r--r-- 2026-02-28 00:31:50
Edit Download
1.13 KB lrw-r--r-- 2026-02-28 00:31:52
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).