import { useEffect } from "react";
import { connect } from "react-redux";

import { appActions } from "@ax/containers/App";
import type { ILogoutAction } from "@ax/containers/App/interfaces";

const Logout = (props: IProps) => {
	const { logout, setHistoryPush } = props;

	useEffect(() => {
		logout();
		setHistoryPush("/login");
	}, [logout, setHistoryPush]);

	return <></>;
};

interface IProps {
	logout(): ILogoutAction;
	setHistoryPush(path: string, isEditor?: boolean): Promise<void>;
}

const mapDispatchToProps = {
	logout: appActions.logout,
	setHistoryPush: appActions.setHistoryPush,
};

export default connect(null, mapDispatchToProps)(Logout);
