ConfirmEndTutorialDialog.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2017 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import React from 'react'
  19. import PropTypes from 'prop-types'
  20. import I18n from 'i18n!new_user_tutorial'
  21. import Button from 'instructure-ui/lib/components/Button'
  22. import Heading from 'instructure-ui/lib/components/Heading'
  23. import Modal, { ModalHeader, ModalBody, ModalFooter } from 'instructure-ui/lib/components/Modal'
  24. import axios from 'axios'
  25. class ConfirmEndTutorialDialog extends React.Component {
  26. static propTypes = {
  27. isOpen: PropTypes.bool,
  28. handleRequestClose: PropTypes.func.isRequired
  29. }
  30. static defaultProps = {
  31. isOpen: false
  32. }
  33. handleOkayButtonClick = (e, onSuccessFunc) => {
  34. const API_URL = '/api/v1/users/self/features/flags/new_user_tutorial_on_off';
  35. axios.put(API_URL, {
  36. state: 'off'
  37. }).then(() => {
  38. // Done this way such that onSuccessFunc (reload) gets the proper thisArg
  39. // while still allowing us to easily provide a replacement for tests.
  40. if (onSuccessFunc) {
  41. onSuccessFunc()
  42. } else {
  43. window.location.reload();
  44. }
  45. });
  46. }
  47. render () {
  48. return (
  49. <Modal
  50. open={this.props.isOpen}
  51. size="small"
  52. onDismiss={this.props.handleRequestClose}
  53. label={I18n.t('End Course Set-up Tutorial Dialog')}
  54. closeButtonLabel={I18n.t('Close')}
  55. applicationElement={() => document.getElementById('application')}
  56. >
  57. <ModalHeader>
  58. <Heading>{I18n.t('End Course Set-up Tutorial')}</Heading>
  59. </ModalHeader>
  60. <ModalBody>
  61. {
  62. I18n.t('Turning off this tutorial will remove the tutorial tray from your view ' +
  63. 'for all of your courses. It can be turned back on under Feature Options in your User Settings.')
  64. }
  65. </ModalBody>
  66. <ModalFooter>
  67. <Button
  68. onClick={this.props.handleRequestClose}
  69. >
  70. {I18n.t('Cancel')}
  71. </Button>
  72. &nbsp;
  73. <Button
  74. onClick={this.handleOkayButtonClick}
  75. variant="primary"
  76. >
  77. {I18n.t('Okay')}
  78. </Button>
  79. </ModalFooter>
  80. </Modal>
  81. );
  82. }
  83. }
  84. export default ConfirmEndTutorialDialog