diff --git a/frontend/src/actions/projectActions.ts b/frontend/src/actions/projectActions.ts index 0dd82fea..b8787915 100644 --- a/frontend/src/actions/projectActions.ts +++ b/frontend/src/actions/projectActions.ts @@ -12,7 +12,7 @@ import {TimesheetCheckAttachmentType} from '../models'; import {authService} from '../components/users/authService'; import {FullProjectMonthModel} from '../components/project/models/FullProjectMonthModel'; -export function saveProject(project: IProjectModel, navigate?: any, after: 'to-list' | 'to-details' = 'to-list') { +export function saveProject(project: IProjectModel, navigate?: any, after: 'to-list' | 'to-details' = 'to-list', triggerCopy?: any) { return (dispatch: Dispatch) => { dispatch(busyToggle()); return request @@ -30,10 +30,7 @@ export function saveProject(project: IProjectModel, navigate?: any, after: 'to-l if (after === 'to-list') { navigate('/projects'); } else { - // First navigate away? - // Workaround for EditProject not reloading the form - // when the url _id changes. Need a hook for this :) - navigate('/projects'); + triggerCopy(response.body._id); navigate(`/projects/${response.body._id}`); } } diff --git a/frontend/src/components/project/CopyProject.tsx b/frontend/src/components/project/CopyProject.tsx index 04c3a37e..1aa2a28a 100644 --- a/frontend/src/components/project/CopyProject.tsx +++ b/frontend/src/components/project/CopyProject.tsx @@ -9,10 +9,11 @@ import {Modal} from '../controls/Modal'; import {saveProject} from '../../actions/projectActions'; import {ArrayInput} from '../controls/form-controls/inputs/ArrayInput'; import {FullFormConfig} from '../../models'; -import { ContractStatus } from '../client/models/ContractModels'; +import {ContractStatus} from '../client/models/ContractModels'; type CopyProjectProps = { projectToCopy: IProjectModel; + triggerCopy: any; } @@ -25,7 +26,7 @@ export const copyProjectProperties: FullFormConfig = [ ]; -export const CopyProject = ({projectToCopy}: CopyProjectProps) => { +export const CopyProject = ({projectToCopy, triggerCopy}: CopyProjectProps) => { const [open, setOpen] = useState(false); const defaultProject = { ...projectToCopy, @@ -45,7 +46,7 @@ export const CopyProject = ({projectToCopy}: CopyProjectProps) => { setOpen(false)} - onConfirm={() => dispatch(saveProject(project, history, 'to-details') as any)} + onConfirm={() => dispatch(saveProject(project, history, 'to-details', triggerCopy) as any)} title={t('project.copy.modalTitle')} >
diff --git a/frontend/src/components/project/EditProject.tsx b/frontend/src/components/project/EditProject.tsx index e058a08f..965859cd 100644 --- a/frontend/src/components/project/EditProject.tsx +++ b/frontend/src/components/project/EditProject.tsx @@ -33,6 +33,7 @@ export const EditProject = () => { const navigate = useNavigate(); const params = useParams(); const model = useSelector((state: ConfacState) => state.projects.find(c => c._id === params.id)); + console.log('retrieved model', model); const consultants = useSelector((state: ConfacState) => state.consultants); const [project, setProject] = useState(model || getNewProject()); const consultant = useSelector((state: ConfacState) => state.consultants.find(x => x._id === project.consultantId) || getNewConsultant()); @@ -40,11 +41,15 @@ export const EditProject = () => { const client = useSelector((state: ConfacState) => state.clients.find(x => x._id === project.client.clientId) || getNewClient()); const hasProjectMonths = useSelector((state: ConfacState) => state.projectsMonth.some(pm => pm.projectId === params.id)); const [needsSync, setNeedsSync] = useState<{consultant: boolean, client: boolean}>({consultant: false, client: false}); + const [copyId, setCopyId] = useState(0); + const useCopy = (id: number) => { + setCopyId(id); + } const docTitle = consultant._id ? 'projectEdit' : 'projectNew'; useDocumentTitle(docTitle, {consultant: consultant.firstName, client: client.name}); - - if (model && !project._id) { + if (model && (!project._id || copyId !== 0)) { + setCopyId(0); //needs to be reset, otherwise page will go into render loop setProject(model); } @@ -131,7 +136,7 @@ export const EditProject = () => { dispatch(deleteProject(project._id, navigate) as any)} variant="danger" title={t('project.deleteConfirm.title')} @@ -140,7 +145,7 @@ export const EditProject = () => { > {t('project.deleteConfirm.content')} - {project.endDate && project._id && } + {project.endDate && project._id && } dispatch(saveProject(project, navigate) as any)} disabled={isButtonDisabled}> {t('save')}