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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { useTranslation } from 'react-i18next'
  2. import { Alert, Button } from 'react-bootstrap'
  3. import { useFileTreeCreateForm } from '../../contexts/file-tree-create-form'
  4. import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
  5. import { useFileTreeData } from '../../../../shared/context/file-tree-data-context'
  6. import PropTypes from 'prop-types'
  7. export default function FileTreeModalCreateFileFooter() {
  8. const { valid } = useFileTreeCreateForm()
  9. const { newFileCreateMode, inFlight, cancel } = useFileTreeActionable()
  10. const { fileCount } = useFileTreeData()
  11. return (
  12. <FileTreeModalCreateFileFooterContent
  13. valid={valid}
  14. cancel={cancel}
  15. newFileCreateMode={newFileCreateMode}
  16. inFlight={inFlight}
  17. fileCount={fileCount}
  18. />
  19. )
  20. }
  21. export function FileTreeModalCreateFileFooterContent({
  22. valid,
  23. fileCount,
  24. inFlight,
  25. newFileCreateMode,
  26. cancel,
  27. }) {
  28. const { t } = useTranslation()
  29. return (
  30. <>
  31. {fileCount.status === 'warning' && (
  32. <div className="modal-footer-left approaching-file-limit">
  33. {t('project_approaching_file_limit')} ({fileCount.value}/
  34. {fileCount.limit})
  35. </div>
  36. )}
  37. {fileCount.status === 'error' && (
  38. <Alert bsStyle="warning" className="at-file-limit">
  39. {/* TODO: add parameter for fileCount.limit */}
  40. {t('project_has_too_many_files')}
  41. </Alert>
  42. )}
  43. <Button
  44. bsStyle={null}
  45. className="btn-secondary"
  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. }