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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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="default"
  45. type="button"
  46. disabled={inFlight}
  47. onClick={cancel}
  48. >
  49. {t('cancel')}
  50. </Button>
  51. {newFileCreateMode !== 'upload' && (
  52. <Button
  53. bsStyle="primary"
  54. type="submit"
  55. form="create-file"
  56. disabled={inFlight || !valid}
  57. >
  58. <span>{inFlight ? `${t('creating')}…` : t('create')}</span>
  59. </Button>
  60. )}
  61. </>
  62. )
  63. }
  64. FileTreeModalCreateFileFooterContent.propTypes = {
  65. cancel: PropTypes.func.isRequired,
  66. fileCount: PropTypes.shape({
  67. limit: PropTypes.number.isRequired,
  68. status: PropTypes.string.isRequired,
  69. value: PropTypes.number.isRequired,
  70. }).isRequired,
  71. inFlight: PropTypes.bool.isRequired,
  72. newFileCreateMode: PropTypes.string,
  73. valid: PropTypes.bool.isRequired,
  74. }