file-tree-modal-create-file-footer.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { Alert, Button } from 'react-bootstrap'
  4. import { useFileTreeCreateForm } from '../../contexts/file-tree-create-form'
  5. import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
  6. import { useFileTreeMutable } from '../../contexts/file-tree-mutable'
  7. import PropTypes from 'prop-types'
  8. export default function FileTreeModalCreateFileFooter() {
  9. const { valid } = useFileTreeCreateForm()
  10. const { newFileCreateMode, inFlight, cancel } = useFileTreeActionable()
  11. const { fileCount } = useFileTreeMutable()
  12. return (
  13. <FileTreeModalCreateFileFooterContent
  14. valid={valid}
  15. cancel={cancel}
  16. newFileCreateMode={newFileCreateMode}
  17. inFlight={inFlight}
  18. fileCount={fileCount}
  19. />
  20. )
  21. }
  22. export function FileTreeModalCreateFileFooterContent({
  23. valid,
  24. fileCount,
  25. inFlight,
  26. newFileCreateMode,
  27. cancel
  28. }) {
  29. const { t } = useTranslation()
  30. return (
  31. <>
  32. {fileCount.status === 'warning' && (
  33. <div className="modal-footer-left approaching-file-limit">
  34. {t('project_approaching_file_limit')} ({fileCount.value}/
  35. {fileCount.limit})
  36. </div>
  37. )}
  38. {fileCount.status === 'error' && (
  39. <Alert bsStyle="warning" className="at-file-limit">
  40. {/* TODO: add parameter for fileCount.limit */}
  41. {t('project_has_too_many_files')}
  42. </Alert>
  43. )}
  44. <Button
  45. bsStyle="default"
  46. type="button"
  47. disabled={inFlight}
  48. onClick={cancel}
  49. >
  50. {t('cancel')}
  51. </Button>
  52. {newFileCreateMode !== 'upload' && (
  53. <Button
  54. bsStyle="primary"
  55. type="submit"
  56. form="create-file"
  57. disabled={inFlight || !valid}
  58. >
  59. <span>{inFlight ? `${t('creating')}…` : t('create')}</span>
  60. </Button>
  61. )}
  62. </>
  63. )
  64. }
  65. FileTreeModalCreateFileFooterContent.propTypes = {
  66. cancel: PropTypes.func.isRequired,
  67. fileCount: PropTypes.shape({
  68. limit: PropTypes.number.isRequired,
  69. status: PropTypes.string.isRequired,
  70. value: PropTypes.number.isRequired
  71. }).isRequired,
  72. inFlight: PropTypes.bool.isRequired,
  73. newFileCreateMode: PropTypes.string,
  74. valid: PropTypes.bool.isRequired
  75. }