import React, { useEffect } from 'react';
import { Page } from '../Page';
import { useDispatch } from 'react-redux';
import { logout, login, handleOAuth2Callback } from '../../store/actions/auth';

export function OAuth2Page({ match, location, history }) {
  const dispatch = useDispatch();
  const { action } = match.params;

  useEffect(() => {
    switch(action) {
      case 'logout':
        dispatch(logout());
        history.push("/");
        break;
      case 'login':
        dispatch(login());
        break;
      case 'callback':
        dispatch(handleOAuth2Callback(location.search));
        history.push("/");
        break;
    }
  }, [action]);

  return (
    <Page title="Daddy - OAuth2">
      
    </Page>
  );
}
