<commit_before>import React, { Component, PropTypes } from 'react'
import { Link } from 'react-router'
import { submit } from 'redux-form'
import { connect } from 'react-redux'

import { tryApplyToTeam, cancelApplyToTeam } from 'actions/player'

import { withAllFixtures } from 'components/connectors/WithFixtures'
import { withOwnPlayer } from 'components/connectors/WithOwnPlayer'
import { Label, Button, Modal } from 'react-bootstrap'
import { FixtureDisplay, Loading } from 'utils'
import { CaptainIcon, RegionIcon, PositionIcon, PlayersIcon, SkillBracketIcon } from 'utils/components/icons'
import TeamApplicationForm from 'components/forms/TeamApplicationForm'

class TeamSearchResult extends Component {

    static propTypes = {
        available_positions: PropTypes.array,
        name: PropTypes.string.isRequired
    }

    renderApplyToTeamConfirmModal() {
        const { cancelApplyToTeam, id, player: { teamApplyingTo } } = this.props
        return (
            <Modal show={teamApplyingTo === id}>
                <Modal.Header>
                    <Modal.Title>Confirm Apply to Team</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    <p>Select the position you want to apply for.</p>
                    <TeamApplicationForm initialValues={{ team : this.props.id }} />
                </Modal.Body>
                <Modal.Footer>
                    <Button onClick={cancelApplyToTeam} bsStyle='link' >
                        Cancel</Button>
                    <Button bsStyle='success' onClick={() => this.props.submit('application')}>Apply</Button>
                </Modal.Footer>
            </Modal>
        )
    }

    render() {
        const { available_positions, captain, id, name, regions, skill_bracket, team_members, fixtures, tryApplyToTeam,
            player: { teamApplyingTo } } = this.props
        const isLoading = Object.keys(fixtures).some(fixture => fixtures[fixture].isLoading)
        const lastUpdated = Object.keys(fixtures).every(fixture => fixtures[fixture].lastUpdated)

        return(
            <div className='team-search-result' style={{ border: '1px solid #DDD', padding: '2rem', marginBottom: '2rem' }}>
                {isLoading ? <Loading /> : (
                    lastUpdated ? (
                        <div>
                            {teamApplyingTo && this.renderApplyToTeamConfirmModal()}
                            <div style={{ marginBottom: '1rem' }}>
                                <Link to={`teams/${id}`}>
                                    <strong>{name}</strong>
                                </Link>
                                <span className='pull-right'>
                                    <i className={`fa fa-${available_positions.length > 0 ? 'check-square-o' : 'square-o'}`}/>
                                    &nbsp;Recruiting
                                </span><commit_msg>Require sign in before applying to team<commit_after>import React, { Component, PropTypes } from 'react'
import { Link } from 'react-router'
import { submit } from 'redux-form'
import { connect } from 'react-redux'

import { tryApplyToTeam, cancelApplyToTeam } from 'actions/player'

import { withAllFixtures } from 'components/connectors/WithFixtures'
import { withOwnPlayer } from 'components/connectors/WithOwnPlayer'
import { Label, Button, Modal } from 'react-bootstrap'
import { FixtureDisplay, Loading } from 'utils'
import { CaptainIcon, RegionIcon, PositionIcon, PlayersIcon, SkillBracketIcon } from 'utils/components/icons'
import TeamApplicationForm from 'components/forms/TeamApplicationForm'

class TeamSearchResult extends Component {

    static propTypes = {
        available_positions: PropTypes.array,
        name: PropTypes.string.isRequired
    }

    renderApplyToTeamConfirmModal() {
        const { cancelApplyToTeam, id, player: { teamApplyingTo, lastUpdated } } = this.props
        if (!lastUpdated) {
            return this.renderSignInRequiredModal()
        }
        return (
            <Modal show={teamApplyingTo === id}>
                <Modal.Header>
                    <Modal.Title>Confirm Apply to Team</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    <p>Select the position you want to apply for.</p>
                    <TeamApplicationForm initialValues={{ team : this.props.id }} />
                </Modal.Body>
                <Modal.Footer>
                    <Button onClick={cancelApplyToTeam} bsStyle='link' >
                        Cancel</Button>
                    <Button bsStyle='success' onClick={() => this.props.submit('application')}>Apply</Button>
                </Modal.Footer>
            </Modal>
        )
    }

    renderSignInRequiredModal() {
        const { cancelApplyToTeam, id, player: { teamApplyingTo } } = this.props
        return (
            <Modal show={teamApplyingTo === id}>
                <Modal.Header>
                    <Modal.Title>Sign In Required</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    <p>
                        You need to sign in and create a profile before you can apply to teams.
                    </p>
                    <p>
                        <Link to='signup'>Sign up</Link> or <Link to='login'>Log in</Link>
                    </p>
                    <p>
                        <i>Steam Sign In is coming soon!</i>
                    </p>
                </Modal.Body>
                <Modal.Footer>
                    <Button onClick={cancelApplyToTeam} bsStyle='link' >
                        Close
                    </Button>
                </Modal.Footer>
            </Modal>
        )
    }

    render() {
        const { available_positions, captain, id, name, regions, skill_bracket, team_members, fixtures, tryApplyToTeam,
            player: { teamApplyingTo } } = this.props
        const isLoading = Object.keys(fixtures).some(fixture => fixtures[fixture].isLoading)
        const lastUpdated = Object.keys(fixtures).every(fixture => fixtures[fixture].lastUpdated)

        return(
            <div className='team-search-result' style={{ border: '1px solid #DDD', padding: '2rem', marginBottom: '2rem' }}>
                {isLoading ? <Loading /> : (
                    lastUpdated ? (
                        <div>
                            {teamApplyingTo && this.renderApplyToTeamConfirmModal()}
                            <div style={{ marginBottom: '1rem' }}>
                                <Link to={`teams/${id}`}>
                                    <strong>{name}</strong>
                                </Link>
                                <span className='pull-right'>
                                    <i className={`fa fa-${available_positions.length > 0 ? 'check-square-o' : 'square-o'}`}/>
                                    &nbsp;Recruiting
                                </span>
{'fraction_non_alphanumeric': 0.11131831874910343, 'fraction_numerical': 0.0014345144168698895, 'mean_word_length': 1.7096774193548387, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6333562', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1733, 'n_words': 398}