Notes lifecycle events added to job details.

This commit is contained in:
Patrick Fic
2020-01-21 15:11:04 -08:00
parent 26745f2e62
commit 4bac820887
14 changed files with 546 additions and 90 deletions

View File

@@ -0,0 +1,75 @@
import { notification } from "antd";
import React, { useEffect, useState } from "react";
import { useMutation } from "react-apollo";
import { useTranslation } from "react-i18next";
import { INSERT_NEW_NOTE, UPDATE_NOTE } from "../../graphql/notes.queries";
import NoteUpsertModalComponent from "./note-upsert-modal.component";
export default function NoteUpsertModalContainer({
jobId,
visible,
changeVisibility,
refetch,
existingNote
}) {
const { t } = useTranslation();
const [insertNote] = useMutation(INSERT_NEW_NOTE);
const [updateNote] = useMutation(UPDATE_NOTE);
const [noteState, setNoteState] = useState({
private: false,
critical: false,
text: ""
});
useEffect(() => {
//Required to prevent infinite looping.
if (existingNote) {
setNoteState(existingNote);
}
}, [existingNote]);
const insertNewNote = () => {
insertNote({
variables: {
noteInput: [
{ ...noteState, jobid: jobId, created_by: "patrick@bodyshop.app" } //TODO: Fix the created by.
]
}
}).then(r => {
notification["success"]({
message: t("notes.successes.create")
});
});
refetch();
changeVisibility(!visible);
};
const updateExistingNote = () => {
//Required, otherwise unable to spread in new note prop.
delete noteState.__typename;
updateNote({
variables: {
noteId: noteState.id,
note: noteState
}
}).then(r => {
notification["success"]({
message: t("notes.successes.updated")
});
});
refetch();
changeVisibility(!visible);
};
return (
<NoteUpsertModalComponent
visible={visible}
changeVisibility={changeVisibility}
updateExistingNote={updateExistingNote}
insertNewNote={insertNewNote}
noteState={noteState}
setNoteState={setNoteState}
/>
);
}