<commit_before>import React, { Component, Fragment } from 'react'
import LoadingAnimation from 'components/LoadingAnimation'
import Login from 'components/apply/Login'
import EventForm from 'components/admin/events/EventForm'
import ImageForm from 'components/admin/events/ImageForm'
import ErrorPage from 'components/admin/ErrorPage'
import Nav from 'components/apply/ApplyNav'
import api from 'api'
import search from 'search'
import { Text, Image, BackgroundImage } from '@hackclub/design-system'

export default class extends Component {
  constructor(props) {
    super(props)

    this.state = {
      event: undefined,
      status: 'loading'
    }

    this.updateEvent = this.updateEvent.bind(this)
  }

  updateEvent(updatedEvent) {
    this.setState({
      event: {
        ...this.state.event,
        ...updatedEvent
      }
    })
    if (!search.get('id')) {
      search.set('id', this.state.event.id)
    }
  }

  componentDidMount() {
    const eventId = search.get('id')
    api.get('v1/users/current').then(() => {
      if (eventId) {
        return api
          .get('v1/events')
          .then(events => {
            const event = events.find(event => event.id.toString() === eventId)
            if (event) {
              this.setState({
                event,
                status: 'success'
              })
            } else {
              throw 'Event not found'
            }
          })
          .catch(err => {
            this.setState({
              status: err.status === 401 ? 'needsToAuth' : 'failure'
            })
          })
      } else {
        this.setState({ event: {}, status: 'success' })
      }
    })
  }

  render() {
    const { status, event } = this.state
    switch (status) {
      case 'loading':
        return <LoadingAnimation />
      case 'needsToAuth':
        return <Login userType="admin" />
      case 'success':
        return (
          <Fragment>
            <Nav />
            <ImageForm
              type="logo"
              updateEvent={this.updateEvent}
              image={event && event.logo}
              previewTag={({ imageUrl }) => (
                <Image src={imageUrl} height="60px !important" /><commit_msg>Event edit page shows a login form if user doesn't have admin privileges<commit_after>import React, { Component, Fragment } from 'react'
import LoadingAnimation from 'components/LoadingAnimation'
import Login from 'components/apply/Login'
import EventForm from 'components/admin/events/EventForm'
import ImageForm from 'components/admin/events/ImageForm'
import ErrorPage from 'components/admin/ErrorPage'
import Nav from 'components/apply/ApplyNav'
import api from 'api'
import search from 'search'
import { Text, Image, BackgroundImage } from '@hackclub/design-system'

export default class extends Component {
  constructor(props) {
    super(props)

    this.state = {
      event: undefined,
      status: 'loading'
    }

    this.updateEvent = this.updateEvent.bind(this)
  }

  updateEvent(updatedEvent) {
    this.setState({
      event: {
        ...this.state.event,
        ...updatedEvent
      }
    })
    if (!search.get('id')) {
      search.set('id', this.state.event.id)
    }
  }

  componentDidMount() {
    const eventId = search.get('id')
    api
      .get('v1/users/current')
      .then(() => {
        if (eventId) {
          return api
            .get('v1/events')
            .then(events => {
              const event = events.find(
                event => event.id.toString() === eventId
              )
              if (event) {
                this.setState({
                  event,
                  status: 'success'
                })
              } else {
                throw 'Event not found'
              }
            })
            .catch(err => {
              throw err
            })
        } else {
          this.setState({ event: {}, status: 'success' })
        }
      })
      .catch(err => {
        this.setState({
          status: err.status === 401 ? 'needsToAuth' : 'failure'
        })
      })
  }

  render() {
    const { status, event } = this.state
    switch (status) {
      case 'loading':
        return <LoadingAnimation />
      case 'needsToAuth':
        return <Login userType="admin" />
      case 'success':
        return (
          <Fragment>
            <Nav />
            <ImageForm
              type="logo"
              updateEvent={this.updateEvent}
              image={event && event.logo}
              previewTag={({ imageUrl }) => (
                <Image src={imageUrl} height="60px !important" />
{'fraction_non_alphanumeric': 0.12630208333333334, 'fraction_numerical': 0.0030381944444444445, 'mean_word_length': 1.7933333333333332, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 24, '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': '3805779', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1250, 'n_words': 294}