diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a5edd6a..be933e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ with the current semantic version and the next changes should go under a **[Next * Remove unused style tag. ([@nwalters512](https://github.com/nwalters512) in [#259](https://github.com/illinois/queue/pull/259)) * Fix active staff socket errors. ([@nwalters512](https://github.com/nwalters512) in [#262](https://github.com/illinois/queue/pull/262)) * Rewrite queue page with hooks; fix miscellaneous bugs. ([@nwalters512](https://github.com/nwalters512) in [#263](https://github.com/illinois/queue/pull/263)) +* Rewrite queue setting page with hooks to fix bug with admission control "Update" button. ([@nwalters512](https://github.com/nwalters512) in [#264](https://github.com/illinois/queue/pull/264)) ## v1.0.4 diff --git a/src/pages/queueSettings.js b/src/pages/queueSettings.js index fa1d660d..7e7f73aa 100644 --- a/src/pages/queueSettings.js +++ b/src/pages/queueSettings.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useState, useEffect } from 'react' import PropTypes from 'prop-types' import { Container } from 'reactstrap' import { connect } from 'react-redux' @@ -7,8 +7,8 @@ import { Router } from '../routes' import { fetchQueue, fetchQueueRequest, - updateQueue, - deleteQueue, + updateQueue as updateQueueAction, + deleteQueue as deleteQueueAction, } from '../actions/queue' import Error from '../components/Error' import GeneralPanel from '../components/queueSettings/GeneralPanel' @@ -17,61 +17,67 @@ import PageWithUser from '../components/PageWithUser' import DangerPanel from '../components/queueSettings/DangerPanel' import { isUserCourseStaffForQueue, isUserAdmin } from '../selectors' -class QueueSettings extends React.Component { - static async getInitialProps({ isServer, store, query }) { - const queueId = Number.parseInt(query.id, 10) - if (isServer) { - store.dispatch(fetchQueueRequest(queueId)) - } - return { - queueId, - isFetching: isServer, - } - // Nothing to do at the moment - } +const QueueSettings = props => { + const [queueLoading, setQueueLoading] = useState(true) - componentDidMount() { - this.props.fetchQueue(this.props.queueId).then(() => { - if (this.props.pageTransitionReadyToEnter) { - this.props.pageTransitionReadyToEnter() + useEffect(() => { + setQueueLoading(true) + props.fetchQueue(props.queueId).then(() => { + setQueueLoading(false) + if (props.pageTransitionReadyToEnter) { + props.pageTransitionReadyToEnter() } }) - } + }, [props.queueId]) - updateQueue(attributes) { - this.props.updateQueue(this.props.queueId, attributes) + const updateQueue = attributes => { + props.updateQueue(props.queueId, attributes) } - deleteQueue() { - const { id: queueId, courseId } = this.props.queue - this.props.deleteQueue(courseId, queueId).then(() => { + const deleteQueue = () => { + const { id: queueId, courseId } = props.queue + props.deleteQueue(courseId, queueId).then(() => { Router.replaceRoute('index') }) } - render() { - if (!this.props.queue) return null - if (!this.props.isUserAdmin && !this.props.isUserCourseStaffForQueue) { - return - } - return ( - -

Queue Settings

-

{this.props.queue.name}

- this.updateQueue(attributes)} - /> - this.updateQueue(attributes)} - /> - this.deleteQueue()} /> -
- ) + if (queueLoading) return null + + if (!queueLoading && !props.queue) { + return + } + + if (!props.isUserAdmin && !props.isUserCourseStaffForQueue) { + return } + + return ( + +

Queue Settings

+

{props.queue.name}

+ updateQueue(attributes)} + /> + updateQueue(attributes)} + /> + deleteQueue()} /> +
+ ) } +QueueSettings.getInitialProps = async ({ isServer, store, query }) => { + const queueId = Number.parseInt(query.id, 10) + if (isServer) { + store.dispatch(fetchQueueRequest(queueId)) + } + return { queueId } +} + +QueueSettings.pageTransitionDelayEnter = true + QueueSettings.propTypes = { fetchQueue: PropTypes.func.isRequired, updateQueue: PropTypes.func.isRequired, @@ -95,8 +101,6 @@ QueueSettings.defaultProps = { } const mapStateToProps = (state, ownProps) => ({ - isFetching: state.queues.isFetching, - hasQueue: !!state.queues.queues[ownProps.queueId], queue: state.queues.queues[ownProps.queueId], isUserCourseStaffForQueue: isUserCourseStaffForQueue(state, ownProps), isUserAdmin: isUserAdmin(state, ownProps), @@ -106,8 +110,9 @@ const mapStateToProps = (state, ownProps) => ({ const mapDispatchToProps = dispatch => ({ fetchQueue: queueId => dispatch(fetchQueue(queueId)), updateQueue: (queueId, attributes) => - dispatch(updateQueue(queueId, attributes)), - deleteQueue: (courseId, queueId) => dispatch(deleteQueue(courseId, queueId)), + dispatch(updateQueueAction(queueId, attributes)), + deleteQueue: (courseId, queueId) => + dispatch(deleteQueueAction(courseId, queueId)), dispatch, })