|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useState } from 'react'
|
|
|
|
|
|
|
+import React, { useCallback, useState } from 'react'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
import useAsync from '../../../../shared/hooks/use-async'
|
|
import useAsync from '../../../../shared/hooks/use-async'
|
|
|
import {
|
|
import {
|
|
@@ -19,6 +19,10 @@ import OLButton from '@/shared/components/ol/ol-button'
|
|
|
import OLForm from '@/shared/components/ol/ol-form'
|
|
import OLForm from '@/shared/components/ol/ol-form'
|
|
|
import OLFormLabel from '@/shared/components/ol/ol-form-label'
|
|
import OLFormLabel from '@/shared/components/ol/ol-form-label'
|
|
|
import OLFormGroup from '@/shared/components/ol/ol-form-group'
|
|
import OLFormGroup from '@/shared/components/ol/ol-form-group'
|
|
|
|
|
+import { CloneProjectTag } from '@/features/clone-project-modal/components/clone-project-tag'
|
|
|
|
|
+import { addProjectsToTag } from '@/features/project-list/util/api'
|
|
|
|
|
+import { captureException } from '@/infrastructure/error-reporter'
|
|
|
|
|
+import { Tag } from '../../../../../../app/src/Features/Tags/types'
|
|
|
|
|
|
|
|
type NewProjectData = {
|
|
type NewProjectData = {
|
|
|
project_id: string
|
|
project_id: string
|
|
@@ -34,16 +38,26 @@ type NewProjectData = {
|
|
|
type Props = {
|
|
type Props = {
|
|
|
onCancel: () => void
|
|
onCancel: () => void
|
|
|
template?: string
|
|
template?: string
|
|
|
|
|
+ initialTags?: Tag[]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function ModalContentNewProjectForm({ onCancel, template = 'none' }: Props) {
|
|
|
|
|
|
|
+function ModalContentNewProjectForm({
|
|
|
|
|
+ onCancel,
|
|
|
|
|
+ template = 'none',
|
|
|
|
|
+ initialTags = [],
|
|
|
|
|
+}: Props) {
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
const { autoFocusedRef } = useRefWithAutoFocus<HTMLInputElement>()
|
|
const { autoFocusedRef } = useRefWithAutoFocus<HTMLInputElement>()
|
|
|
const [projectName, setProjectName] = useState('')
|
|
const [projectName, setProjectName] = useState('')
|
|
|
|
|
+ const [projectTags, setProjectTags] = useState<Tag[]>(initialTags)
|
|
|
const [redirecting, setRedirecting] = useState(false)
|
|
const [redirecting, setRedirecting] = useState(false)
|
|
|
const { isLoading, isError, error, runAsync } = useAsync<NewProjectData>()
|
|
const { isLoading, isError, error, runAsync } = useAsync<NewProjectData>()
|
|
|
const location = useLocation()
|
|
const location = useLocation()
|
|
|
|
|
|
|
|
|
|
+ const removeTag = useCallback((tag: Tag) => {
|
|
|
|
|
+ setProjectTags(value => value.filter(item => item._id !== tag._id))
|
|
|
|
|
+ }, [])
|
|
|
|
|
+
|
|
|
const createNewProject = () => {
|
|
const createNewProject = () => {
|
|
|
runAsync(
|
|
runAsync(
|
|
|
postJSON('/project/new', {
|
|
postJSON('/project/new', {
|
|
@@ -53,10 +67,17 @@ function ModalContentNewProjectForm({ onCancel, template = 'none' }: Props) {
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
)
|
|
)
|
|
|
- .then(data => {
|
|
|
|
|
|
|
+ .then(async data => {
|
|
|
if (data.project_id) {
|
|
if (data.project_id) {
|
|
|
// prevents clicking on create again between async load of next page and pending state being finished
|
|
// prevents clicking on create again between async load of next page and pending state being finished
|
|
|
setRedirecting(true)
|
|
setRedirecting(true)
|
|
|
|
|
+ for (const tag of projectTags) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await addProjectsToTag(tag._id, [data.project_id])
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ captureException(err as Error)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
location.assign(`/project/${data.project_id}`)
|
|
location.assign(`/project/${data.project_id}`)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
@@ -97,6 +118,21 @@ function ModalContentNewProjectForm({ onCancel, template = 'none' }: Props) {
|
|
|
value={projectName}
|
|
value={projectName}
|
|
|
/>
|
|
/>
|
|
|
</OLFormGroup>
|
|
</OLFormGroup>
|
|
|
|
|
+
|
|
|
|
|
+ {projectTags.length > 0 && (
|
|
|
|
|
+ <OLFormGroup controlId="new-project-tags-list">
|
|
|
|
|
+ <OLFormLabel>{t('tags')}: </OLFormLabel>
|
|
|
|
|
+ <div role="listbox" id="new-project-tags-list">
|
|
|
|
|
+ {projectTags.map(tag => (
|
|
|
|
|
+ <CloneProjectTag
|
|
|
|
|
+ key={tag._id}
|
|
|
|
|
+ tag={tag}
|
|
|
|
|
+ removeTag={removeTag}
|
|
|
|
|
+ />
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </OLFormGroup>
|
|
|
|
|
+ )}
|
|
|
</OLForm>
|
|
</OLForm>
|
|
|
</OLModalBody>
|
|
</OLModalBody>
|
|
|
|
|
|