diff --git a/packages/tdb-dashboard/src/components/Messages.js b/packages/tdb-dashboard/src/components/Messages.js index 9325536a..724e3779 100644 --- a/packages/tdb-dashboard/src/components/Messages.js +++ b/packages/tdb-dashboard/src/components/Messages.js @@ -51,7 +51,7 @@ export const MessageBox = ({ setMessage, message }) => { // displays textarea to write comments & button to save comments export const MessageComponent = ({setKey}) => { const { currentCRObject, setCurrentCRObject }= WOQLClientObj() - const { updateChangeRequestStatus, loading } = ChangeRequest() + const { addNewMessage, loading } = ChangeRequest() const [comment, setComment]=useState("") const { id } = useParams() @@ -59,7 +59,7 @@ export const MessageComponent = ({setKey}) => { async function handleMessage(comment) { let id=extractID(currentCRObject["@id"]) // this call return the changeRequestObj Updated - let res=await updateChangeRequestStatus(comment, currentCRObject.status, id) + let res=await addNewMessage(comment, id) // we'll see if add need rebase check every time res.needRebase = currentCRObject.needRebase setCurrentCRObject(res) diff --git a/packages/tdb-dashboard/src/hooks/ChangeRequest.js b/packages/tdb-dashboard/src/hooks/ChangeRequest.js index 29ad21e3..48a7f650 100644 --- a/packages/tdb-dashboard/src/hooks/ChangeRequest.js +++ b/packages/tdb-dashboard/src/hooks/ChangeRequest.js @@ -37,6 +37,22 @@ export function ChangeRequest(){ } } + const addNewMessage = async(message, crID = false) =>{ + try{ + setLoading(true) + const payload = {message} + const currentCR = crID + const changeRequestDoc = await woqlClient.sendCustomRequest("POST", `${getUrl()}/${currentCR}/messages`,payload) + return changeRequestDoc + }catch(err){ + const errMessage = formatErrorMessage(err) + setError(errMessage) + return false + }finally{ + setLoading(false) + } + } + const updateChangeRequestStatus = async(message, status="Submitted", crID = false) =>{ try{ setLoading(true) @@ -116,6 +132,7 @@ export function ChangeRequest(){ errorMessage, changeRequestList, createChangeRequest, + addNewMessage, getChangeRequestList, updateChangeRequestStatus, getChangeRequestByID,