"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const React = __importStar(require("react"));
const react_1 = require("react");
// import { withRouter } from 'react-router';
const react_router_dom_1 = require("react-router-dom");
const auth_1 = require("../utils/auth");
const react_apollo_1 = require("react-apollo");
const graphql_tag_1 = __importDefault(require("graphql-tag"));
const signIn = graphql_tag_1.default `
	mutation($workspace_id: String) {
		signIn(workspace_id: "") {
			slack_id
		}
	}
`;
const userQuery = graphql_tag_1.default `
	query {
		viewer {
			slack_id
		}
	}
`;
class Callback extends react_1.Component {
    constructor() {
        super(...arguments);
        this.state = {
            redirectToReferrer: false
        };
        this.createUser = () => {
            const variables = {
                idToken: auth_1.getIdToken()
            };
            this.props
                .signIn({ variables })
                .then((response) => {
                console.log('Response from create user', response);
            })
                .catch((e) => {
                console.error('Error of life ', e);
            });
        };
    }
    componentDidMount() {
        auth_1.getAndStoreParameters();
        this.createUser();
    }
    render() {
        const { from } = this.props.location.state || { from: { pathname: '/' } };
        const { redirectToReferrer } = this.state;
        if (redirectToReferrer) {
            return React.createElement(react_router_dom_1.Redirect, { to: from });
        }
        else {
            return null;
        }
    }
}
exports.default = react_apollo_1.graphql(signIn, { name: 'signIn' })(react_apollo_1.graphql(userQuery, { options: { fetchPolicy: 'network-only' } })(Callback));
//# sourceMappingURL=callback.js.map