<commit_before>import React from "react";
import PropTypes from "prop-types";
import I18n from "i18n-js";
import moment from "moment";
import "react-datepicker/dist/react-datepicker.css";

import JoinRequestInfo from "../components/join_request_info";
import ConfirmationDialog from "../components/confirmation_dialog";
import CheckBox from "../components/checkbox";
import {getJoinRequest, getTeamDetail, joinRequest} from "../api";
import {setFlash} from "../utils/flash";
import {goto, isEmpty, stop} from "../utils/utils";


export default class JoinRequest extends React.Component {

    constructor(props, context) {
        super(props, context);
        this.state = {
            team: {},
            joinRequest: {},
            loaded: false,
            approval: true,
            message: "",
            confirmationDialogOpen: false,
            confirmationDialogAction: () => {
                this.setState({confirmationDialogOpen: false});
                this.goBack();
            }
        };
    }

    componentDidMount() {
        const {teamId, id} = this.props.match.params;
        getTeamDetail(teamId).then(team => {
            this.setState({team: team, loaded: isEmpty(id)});
            if (id) {
                getJoinRequest(id).then(joinRequest => this.setState({
                    joinRequest: joinRequest,
                    message: joinRequest.message,
                    loaded: true
                }));
            }
        });
        window.scrollTo(0, 0);
    }

    handleInputChange = attributeName => e => {
        const target = e.target;
        const value = target.type === "checkbox" ? target.checked : target.value;
        this.setState({[attributeName]: value});
    };

    goBack = () => goto("/my-teams", this.props);

    cancel = e => {
        stop(e);
        this.setState({confirmationDialogOpen: true});
    };

    submit = e => {
        stop(e);
        if (this.isValid()) {
            const {message} = this.state;
            const teamId = this.props.match.params.teamId;
            joinRequest({
                teamId,
                message
            }).then(() => {
                setFlash(I18n.t("join_request.flash", {name: this.state.team.name}));
                this.goBack();
            });
        }
    };

    isValid = () => {
        return this.state.approval;
    };

    renderTeam = team => {
        return (
            <section className="team">
                <label >{I18n.t("join_request.team.name")}</label>
                <input type="text" value={team.name} disabled="true"/>
                <label >{I18n.t("join_request.team.description")}</label>
                <input type="text" value={team.description} disabled="true"/>
                <section className="admins">
                    <label>{I18n.t("join_request.team.admins")}</label>
                    {(team.admins || []).map((admin, index) =>
                        <div key={index}>
                            <input type="text" value={admin.name} disabled="true"/>
                        </div>
                    )}
                </section>
            </section>

        );
    };

    renderExistingJoinRequest = joinRequest => {
        if (isEmpty(joinRequest.id)) {
            return null;
        }
        return (
            <section className="form-divider previous-join-request">
                <label>{I18n.t("join_request.previous")}</label>
                <p>{I18n.t("join_request.previous_message", {date: moment.unix(joinRequest.created).format("LLL")})}</p>
            </section>
        );
    };

    renderApproval = approval =>
        <section>
            <CheckBox name="approval" value={approval}
                      onChange={this.handleInputChange("approval")}
                      info={I18n.t("join_request.share_info")}
                      className={approval ? "checkbox" : "checkbox with-error"}/>
            {!approval && <em className="error with-checkbox">{I18n.t("join_request.approval_required")}</em>}
        </section>;<commit_msg>Show admin email on join request<commit_after>import React from "react";
import PropTypes from "prop-types";
import I18n from "i18n-js";
import moment from "moment";
import "react-datepicker/dist/react-datepicker.css";

import JoinRequestInfo from "../components/join_request_info";
import ConfirmationDialog from "../components/confirmation_dialog";
import CheckBox from "../components/checkbox";
import {getJoinRequest, getTeamDetail, joinRequest} from "../api";
import {setFlash} from "../utils/flash";
import {goto, isEmpty, stop} from "../utils/utils";


export default class JoinRequest extends React.Component {

    constructor(props, context) {
        super(props, context);
        this.state = {
            team: {},
            joinRequest: {},
            loaded: false,
            approval: true,
            message: "",
            confirmationDialogOpen: false,
            confirmationDialogAction: () => {
                this.setState({confirmationDialogOpen: false});
                this.goBack();
            }
        };
    }

    componentDidMount() {
        const {teamId, id} = this.props.match.params;
        getTeamDetail(teamId).then(team => {
            this.setState({team: team, loaded: isEmpty(id)});
            if (id) {
                getJoinRequest(id).then(joinRequest => this.setState({
                    joinRequest: joinRequest,
                    message: joinRequest.message,
                    loaded: true
                }));
            }
        });
        window.scrollTo(0, 0);
    }

    handleInputChange = attributeName => e => {
        const target = e.target;
        const value = target.type === "checkbox" ? target.checked : target.value;
        this.setState({[attributeName]: value});
    };

    goBack = () => goto("/my-teams", this.props);

    cancel = e => {
        stop(e);
        this.setState({confirmationDialogOpen: true});
    };

    submit = e => {
        stop(e);
        if (this.isValid()) {
            const {message} = this.state;
            const teamId = this.props.match.params.teamId;
            joinRequest({
                teamId,
                message
            }).then(() => {
                setFlash(I18n.t("join_request.flash", {name: this.state.team.name}));
                this.goBack();
            });
        }
    };

    isValid = () => {
        return this.state.approval;
    };

    renderTeam = team => {
        return (
            <section className="team">
                <label >{I18n.t("join_request.team.name")}</label>
                <input type="text" value={team.name} disabled="true"/>
                <label >{I18n.t("join_request.team.description")}</label>
                <input type="text" value={team.description} disabled="true"/>
                <section className="admins">
                    <label>{I18n.t("join_request.team.admins")}</label>
                    {(team.admins || []).map((admin, index) =>
                        <div key={index}>
                            <input type="text" value={`${admin.name} <${admin.email}>`} disabled="true"/>
                        </div>
                    )}
                </section>
            </section>

        );
    };

    renderExistingJoinRequest = joinRequest => {
        if (isEmpty(joinRequest.id)) {
            return null;
        }
        return (
            <section className="form-divider previous-join-request">
                <label>{I18n.t("join_request.previous")}</label>
                <p>{I18n.t("join_request.previous_message", {date: moment.unix(joinRequest.created).format("LLL")})}</p>
            </section>
        );
    };

    renderApproval = approval =>
        <section>
            <CheckBox name="approval" value={approval}
                      onChange={this.handleInputChange("approval")}
                      info={I18n.t("join_request.share_info")}
                      className={approval ? "checkbox" : "checkbox with-error"}/>
            {!approval && <em className="error with-checkbox">{I18n.t("join_request.approval_required")}</em>}
        </section>;
{'fraction_non_alphanumeric': 0.14508846857840146, 'fraction_numerical': 0.005369127516778523, 'mean_word_length': 1.7934560327198363, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3011263', 'n_tokens_mistral': 2268, 'n_tokens_neox': 2173, 'n_words': 405}