-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteListField.js
More file actions
64 lines (56 loc) · 1.6 KB
/
NoteListField.js
File metadata and controls
64 lines (56 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React from "react";
import { useDispatch } from "react-redux";
import { setNotesModal } from "../../redux/actions";
import { useQuery, Loading, Error } from "react-admin";
import tw, { styled } from "twin.macro";
import NoteField from "./NoteField";
import IconButton from "@material-ui/core/IconButton";
import AddCircleOutlineOutlinedIcon from '@material-ui/icons/AddCircleOutlineOutlined';
import NoteIcon from "../Basic/NoteIcon";
const Label = styled.h1`
${tw`fontStyle-6 font-medium inline-flex`}
font-size: 1.3em;
color: black;
font-weight: bold;
`;
const Notes = styled.div`
margin-top: 12px;
`;
const NoteListField = ({ record = {}, source }) => {
const { data, loading, error } = useQuery({
type: "getManyReference",
resource: "notes",
payload: {
target: "student",
id: record[source],
pagination: {
page: 1,
perPage: 10 // TODO: how many per page?
},
sort: {
field: "", // TODO: Backend doesn't currently handle sorting for notes
order: ""
}
}
});
const dispatch = useDispatch();
function addNote() {
dispatch(setNotesModal({ isOpen: true }))
}
if (loading) return <Loading />;
if (error) return <Error />;
if (!data) return null;
return (
<Notes>
<Label>Recent Notes</Label>
<IconButton onClick={addNote}>
<NoteIcon src={AddCircleOutlineOutlinedIcon} size="small" isPrimary="primary" />
</IconButton>
{data.map((note, ind) => {
return <NoteField source='id' record={note} key={ind}/>
})
}
</Notes>
);
};
export default NoteListField;