-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteBoxField.js
More file actions
78 lines (66 loc) · 2.3 KB
/
NoteBoxField.js
File metadata and controls
78 lines (66 loc) · 2.3 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from 'react'
import tw, { styled } from "twin.macro";
import MuiPaper from "@material-ui/core/Paper";
import {NOTE} from "../../constants/apiObjects";
import CardHeader from "@material-ui/core/CardHeader";
import CardContent from "@material-ui/core/CardContent";
import BasicTag from "../Basic/BasicTag";
import {DeleteButton} from 'react-admin';
const CardRoot = styled.div`
flex-grow: 1;
margin: 15px;
`
const Paper = styled(MuiPaper)`
${tw`rounded-xl h-64 w-56 shadow-cardLight`}
padding: 7px;
margin: auto;
`;
const Tags = styled.div`
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-around;
`
const MAX_TITLE_LENGTH = 25;
const MAX_BODY_LENGTH = 30;
const NoteBoxField = ({ record, studentId, onDelete }) => {
const id = record[NOTE.ID];
const title = record[NOTE.TITLE];
const body = record[NOTE.BODY];
const tags = record[NOTE.TAGS];
const date = new Date(record[NOTE.DATE]).toLocaleDateString();
function truncate(str, n){
return (str.length > n) ? str.substr(0, n-1) + '…' : str;
}
return (
<CardRoot>
<Paper>
<CardHeader
action={
<div>
<DeleteButton label="" onClick={onDelete} basePath={`/students/${studentId}/details`} record={record} resource="notes" />
</div>
}
title={truncate(title, MAX_TITLE_LENGTH)}
subheader={date}
/>
<CardContent>
<p>
{truncate(body, MAX_BODY_LENGTH)}
</p>
<Tags>
{tags.map((tag, ind) => {
if (ind < 2) {
return <BasicTag text={tag}/>;
} else {
const more = `${tags.length - 2} more`
return <BasicTag text={more} />
}
})}
</Tags>
</CardContent>
</Paper>
</CardRoot>
)
}
export default NoteBoxField;