import React from 'react'
import { useLocation } from 'react-router-dom'

import { Spin } from 'antd'

import { useLogin2p } from './Login2pContext'

const Login2pWechatLanding: React.FC = () => {
  const code = new URLSearchParams(useLocation().search).get('code')
  const next = new URLSearchParams(useLocation().search).get('next')
  console.log(next)
  const login2p = useLogin2p()
  React.useEffect(() => {
    if (code) {
      login2p.loginWechat(code, decodeURIComponent(next ? next : '/')).then(r => console.log(r))
    }
  }, [])

  return <Spin size="large" />
}

export default Login2pWechatLanding
