mirror of
				https://gitlab.nic.cz/turris/reforis/foris-js.git
				synced 2025-11-03 23:00:31 +01:00 
			
		
		
		
	Use global AlertContext
This commit is contained in:
		@@ -11,8 +11,6 @@ import PropTypes from "prop-types";
 | 
			
		||||
import { Alert, ALERT_TYPES } from "bootstrap/Alert";
 | 
			
		||||
import { Portal } from "utils/Portal";
 | 
			
		||||
 | 
			
		||||
const AlertContext = React.createContext();
 | 
			
		||||
 | 
			
		||||
AlertContextProvider.propTypes = {
 | 
			
		||||
    children: PropTypes.oneOfType([
 | 
			
		||||
        PropTypes.arrayOf(PropTypes.node),
 | 
			
		||||
@@ -21,6 +19,7 @@ AlertContextProvider.propTypes = {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
function AlertContextProvider({ children }) {
 | 
			
		||||
    const { AlertContext } = window;
 | 
			
		||||
    const [alert, setAlert] = useState(null);
 | 
			
		||||
 | 
			
		||||
    const setAlertWrapper = useCallback((message, type = ALERT_TYPES.DANGER) => {
 | 
			
		||||
@@ -46,7 +45,8 @@ function AlertContextProvider({ children }) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function useAlert() {
 | 
			
		||||
    const { AlertContext } = window;
 | 
			
		||||
    return useContext(AlertContext);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export { AlertContext, AlertContextProvider, useAlert };
 | 
			
		||||
export { AlertContextProvider, useAlert };
 | 
			
		||||
 
 | 
			
		||||
@@ -75,4 +75,4 @@ export {
 | 
			
		||||
} from "validations";
 | 
			
		||||
 | 
			
		||||
// Alert context
 | 
			
		||||
export { AlertContext, AlertContextProvider, useAlert } from "alertContext/AlertContext";
 | 
			
		||||
export { AlertContextProvider, useAlert } from "alertContext/AlertContext";
 | 
			
		||||
 
 | 
			
		||||
@@ -7,11 +7,11 @@
 | 
			
		||||
 | 
			
		||||
import React from "react";
 | 
			
		||||
 | 
			
		||||
import { AlertContext } from "../alertContext/AlertContext";
 | 
			
		||||
 | 
			
		||||
const mockSetAlert = jest.fn();
 | 
			
		||||
const mockDismissAlert = jest.fn();
 | 
			
		||||
 | 
			
		||||
window.AlertContext = React.createContext();
 | 
			
		||||
 | 
			
		||||
function AlertContextMock({ children }) {
 | 
			
		||||
    return (
 | 
			
		||||
        <AlertContext.Provider value={[mockSetAlert, mockDismissAlert]}>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user