2021-03-18 05:52:36 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useFileTreeCreateForm } from '../../contexts/file-tree-create-form'
|
|
|
|
import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
|
2022-01-10 10:47:01 -05:00
|
|
|
import { useFileTreeData } from '../../../../shared/context/file-tree-data-context'
|
2021-03-18 05:52:36 -04:00
|
|
|
import PropTypes from 'prop-types'
|
2024-09-25 09:46:02 -04:00
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
|
|
|
import OLNotification from '@/features/ui/components/ol/ol-notification'
|
2021-03-18 05:52:36 -04:00
|
|
|
|
|
|
|
export default function FileTreeModalCreateFileFooter() {
|
|
|
|
const { valid } = useFileTreeCreateForm()
|
|
|
|
const { newFileCreateMode, inFlight, cancel } = useFileTreeActionable()
|
2022-01-10 10:47:01 -05:00
|
|
|
const { fileCount } = useFileTreeData()
|
2021-03-18 05:52:36 -04:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FileTreeModalCreateFileFooterContent
|
|
|
|
valid={valid}
|
|
|
|
cancel={cancel}
|
|
|
|
newFileCreateMode={newFileCreateMode}
|
|
|
|
inFlight={inFlight}
|
|
|
|
fileCount={fileCount}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function FileTreeModalCreateFileFooterContent({
|
|
|
|
valid,
|
|
|
|
fileCount,
|
|
|
|
inFlight,
|
|
|
|
newFileCreateMode,
|
2021-04-27 03:52:58 -04:00
|
|
|
cancel,
|
2021-03-18 05:52:36 -04:00
|
|
|
}) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{fileCount.status === 'warning' && (
|
|
|
|
<div className="modal-footer-left approaching-file-limit">
|
|
|
|
{t('project_approaching_file_limit')} ({fileCount.value}/
|
|
|
|
{fileCount.limit})
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{fileCount.status === 'error' && (
|
2024-09-25 09:46:02 -04:00
|
|
|
<OLNotification
|
|
|
|
type="error"
|
|
|
|
className="at-file-limit"
|
|
|
|
content={t('project_has_too_many_files')}
|
|
|
|
>
|
2021-03-18 05:52:36 -04:00
|
|
|
{/* TODO: add parameter for fileCount.limit */}
|
2024-09-25 09:46:02 -04:00
|
|
|
</OLNotification>
|
2021-03-18 05:52:36 -04:00
|
|
|
)}
|
|
|
|
|
2024-09-25 09:46:02 -04:00
|
|
|
<OLButton
|
|
|
|
variant="secondary"
|
2021-03-18 05:52:36 -04:00
|
|
|
type="button"
|
|
|
|
disabled={inFlight}
|
|
|
|
onClick={cancel}
|
|
|
|
>
|
|
|
|
{t('cancel')}
|
2024-09-25 09:46:02 -04:00
|
|
|
</OLButton>
|
2021-03-18 05:52:36 -04:00
|
|
|
|
|
|
|
{newFileCreateMode !== 'upload' && (
|
2024-09-25 09:46:02 -04:00
|
|
|
<OLButton
|
|
|
|
variant="primary"
|
2021-03-18 05:52:36 -04:00
|
|
|
type="submit"
|
|
|
|
form="create-file"
|
|
|
|
disabled={inFlight || !valid}
|
2024-09-25 09:46:02 -04:00
|
|
|
isLoading={inFlight}
|
|
|
|
bs3Props={{ loading: inFlight ? `${t('creating')}…` : t('create') }}
|
2021-03-18 05:52:36 -04:00
|
|
|
>
|
2024-09-25 09:46:02 -04:00
|
|
|
{t('create')}
|
|
|
|
</OLButton>
|
2021-03-18 05:52:36 -04:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
FileTreeModalCreateFileFooterContent.propTypes = {
|
|
|
|
cancel: PropTypes.func.isRequired,
|
|
|
|
fileCount: PropTypes.shape({
|
|
|
|
limit: PropTypes.number.isRequired,
|
|
|
|
status: PropTypes.string.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
value: PropTypes.number.isRequired,
|
2021-03-18 05:52:36 -04:00
|
|
|
}).isRequired,
|
|
|
|
inFlight: PropTypes.bool.isRequired,
|
|
|
|
newFileCreateMode: PropTypes.string,
|
2021-04-27 03:52:58 -04:00
|
|
|
valid: PropTypes.bool.isRequired,
|
2021-03-18 05:52:36 -04:00
|
|
|
}
|