-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2417 from Marilynn-Stone/track-218
TRACK-218 Update Issues Tab so Notes save
- Loading branch information
Showing
7 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,53 @@ | ||
import React from "react"; | ||
import RichTextEditor from "../../shared/richTextEditor"; | ||
import { WorkplanContext } from "../WorkPlanContext"; | ||
import { IssuesContext } from "./IssuesContext"; | ||
import { showNotification } from "../../shared/notificationProvider"; | ||
import debounce from "lodash/debounce"; | ||
import workService from "../../../services/workService/workService"; | ||
|
||
const Notes = () => { | ||
const { work, setWork } = React.useContext(WorkplanContext); | ||
const { workId } = React.useContext(IssuesContext); | ||
const [notes, setNotes] = React.useState(""); | ||
const initialNotes = React.useMemo(() => work?.issue_notes, [work?.id]); | ||
|
||
React.useEffect(() => { | ||
setNotes(work?.issue_notes || ""); | ||
}, [work]); | ||
|
||
const saveIssuesNotes = React.useCallback(async (value: string) => { | ||
const result = await workService.saveNotes( | ||
Number(workId), | ||
value, | ||
"issue_notes" | ||
); | ||
if (result.status === 200) { | ||
setWork(result.data); | ||
showNotification("Notes saved successfully", { | ||
type: "success", | ||
duration: 1000, | ||
}); | ||
} | ||
}, []); | ||
|
||
const debounceSave = React.useMemo(() => { | ||
return debounce(saveIssuesNotes, 1000); | ||
}, [saveIssuesNotes]); | ||
|
||
export const Notes = () => { | ||
const handleNotesChange = (value: string) => { | ||
return null; | ||
if (value !== notes) { | ||
setNotes(value); | ||
debounceSave(value); | ||
} | ||
}; | ||
|
||
return <RichTextEditor handleEditorStateChange={handleNotesChange} />; | ||
return ( | ||
<RichTextEditor | ||
handleEditorStateChange={handleNotesChange} | ||
initialRawEditorState={initialNotes} | ||
/> | ||
); | ||
}; | ||
|
||
export default Notes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters