{"size": 1505, "ext": "js", "max_stars_repo_path": "src/components/AnchorForCommentsOnly/AnchorWithAuthToken.js", "max_stars_repo_name": "dean-goodman/expense.cash", "max_stars_repo_stars_event_min_datetime": "2021-06-18T13:11:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T13:11:53.000Z", "max_issues_repo_path": "src/components/AnchorForCommentsOnly/AnchorWithAuthToken.js", "max_issues_repo_name": "rasata/Expensify.cash", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/AnchorForCommentsOnly/AnchorWithAuthToken.js", "max_forks_repo_name": "rasata/Expensify.cash", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.5098039216, "max_line_length": 68, "alphanum_fraction": 0.7162790698}
import _ from 'underscore';
import React from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import ONYXKEYS from '../../ONYXKEYS';
import {
    propTypes as anchorForCommentsOnlyPropTypes,
    defaultProps as anchorForCommentsOnlyDefaultProps,
} from './anchorForCommentsOnlyPropTypes';
import BaseAnchorForCommentsOnly from './BaseAnchorForCommentsOnly';
import addAuthTokenToURL from '../../libs/addAuthTokenToURL';

const propTypes = {
    /** Session info for the currently logged in user. */
    session: PropTypes.shape({
        /** Currently logged in user authToken */
        authToken: PropTypes.string,
    }),

    ...anchorForCommentsOnlyPropTypes,
};

const defaultProps = {
    session: {
        authToken: null,
    },
    ...anchorForCommentsOnlyDefaultProps,
};

const AnchorWithAuthToken = (props) => {
    const urlWithAuthToken = addAuthTokenToURL({
        url: props.href,
        authToken: props.session.authToken,
    });
    const propsToPass = _.omit(props, 'session');
    propsToPass.href = urlWithAuthToken;
    propsToPass.shouldDownloadFile = true;
    // eslint-disable-next-line react/jsx-props-no-spreading
    return <BaseAnchorForCommentsOnly {...propsToPass} />;
};

AnchorWithAuthToken.propTypes = propTypes;
AnchorWithAuthToken.defaultProps = defaultProps;
AnchorWithAuthToken.displayName = 'AnchorWithAuthToken';

export default withOnyx({
    session: {
        key: ONYXKEYS.SESSION,
    },
})(AnchorWithAuthToken);
