Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/api/growerNotes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { handleResponse, handleError, getOrganization } from './apiUtils';
import { session } from '../models/auth';

export default {
getNotes(growerId) {
try {
const query = `${
process.env.REACT_APP_API_ROOT
}/api/${getOrganization()}planter/${growerId}/notes`;

return fetch(query, {
method: 'GET',
headers: {
'content-type': 'application/json',
Authorization: session.token,
},
}).then(handleResponse);
} catch (error) {
handleError(error);
}
},

addNote(growerId, content) {
try {
const query = `${
process.env.REACT_APP_API_ROOT
}/api/${getOrganization()}planter/${growerId}/notes`;

return fetch(query, {
method: 'POST',
headers: {
'content-type': 'application/json',
Authorization: session.token,
},
body: JSON.stringify({ content }),
}).then(handleResponse);
} catch (error) {
handleError(error);
}
},

updateNote(growerId, noteId, content) {
try {
const query = `${
process.env.REACT_APP_API_ROOT
}/api/${getOrganization()}planter/${growerId}/notes/${noteId}`;

return fetch(query, {
method: 'PATCH',
headers: {
'content-type': 'application/json',
Authorization: session.token,
},
body: JSON.stringify({ content }),
}).then(handleResponse);
} catch (error) {
handleError(error);
}
},

deleteNote(growerId, noteId) {
try {
const query = `${
process.env.REACT_APP_API_ROOT
}/api/${getOrganization()}planter/${growerId}/notes/${noteId}`;

return fetch(query, {
method: 'DELETE',
headers: {
'content-type': 'application/json',
Authorization: session.token,
},
}).then(handleResponse);
} catch (error) {
handleError(error);
}
},
};
2 changes: 2 additions & 0 deletions src/components/GrowerDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { AppContext } from '../context/AppContext';
import { GrowerContext } from '../context/GrowerContext';
import { MessagingContext } from 'context/MessagingContext';
import EditGrower from './EditGrower';
import GrowerNotes from './GrowerNotes';
import GrowerOrganization from './GrowerOrganization';
import OptimizedImage from './OptimizedImage';
import LinkToWebmap from './common/LinkToWebmap';
Expand Down Expand Up @@ -559,6 +560,7 @@ const GrowerDetail = ({ open, growerId, onClose }) => {
</table>
)) || <Typography variant="body1">---</Typography>}
</Grid>
<GrowerNotes growerId={grower.id} />
</Grid>
)}
</Grid>
Expand Down
Loading