| @@ -118,7 +118,7 @@ const hasErrorsInTab = ( | |||||
| const CreateProject: React.FC<Props> = ({ | const CreateProject: React.FC<Props> = ({ | ||||
| isEditMode, | isEditMode, | ||||
| isCopyMode, | isCopyMode, | ||||
| draftId, | |||||
| draftId: initDraftId, | |||||
| isSubProject, | isSubProject, | ||||
| mainProjects, | mainProjects, | ||||
| defaultInputs, | defaultInputs, | ||||
| @@ -139,6 +139,7 @@ const CreateProject: React.FC<Props> = ({ | |||||
| customerTypes, | customerTypes, | ||||
| abilities, | abilities, | ||||
| }) => { | }) => { | ||||
| const [draftId, setDraftId] = useState(initDraftId) | |||||
| const [serverError, setServerError] = useState(""); | const [serverError, setServerError] = useState(""); | ||||
| const [tabIndex, setTabIndex] = useState(0); | const [tabIndex, setTabIndex] = useState(0); | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| @@ -562,9 +563,17 @@ const CreateProject: React.FC<Props> = ({ | |||||
| formProps.reset(draftInputs); | formProps.reset(draftInputs); | ||||
| }, [draftId, formProps]); | }, [draftId, formProps]); | ||||
| const saveDraft = useCallback(() => { | |||||
| saveToLocalStorage(draftId || Date.now(), formProps.getValues()); | |||||
| router.replace("/projects"); | |||||
| const saveDraft = useCallback(async () => { | |||||
| const currentTimestamp = Date.now() | |||||
| saveToLocalStorage(draftId || currentTimestamp, formProps.getValues()); | |||||
| const success = await successDialog("Save Success", t) | |||||
| if (success && !draftId) { | |||||
| setDraftId(currentTimestamp) | |||||
| } | |||||
| // router.replace("/projects"); | |||||
| }, [draftId, formProps, router]); | }, [draftId, formProps, router]); | ||||
| const handleDeleteDraft = useCallback(() => { | const handleDeleteDraft = useCallback(() => { | ||||
| @@ -757,7 +766,7 @@ const CreateProject: React.FC<Props> = ({ | |||||
| > | > | ||||
| {t("Save Draft")} | {t("Save Draft")} | ||||
| </Button> | </Button> | ||||
| {draftId && | |||||
| {draftId && | |||||
| <Button | <Button | ||||
| variant="outlined" | variant="outlined" | ||||
| color="error" | color="error" | ||||