summaryrefslogtreecommitdiff
path: root/src/components/AssignmentCard/index.js
blob: fc5758b26c490f2fc21be9ba9bf5fda4d19d480e (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import {
  Card,
  CardContent,
  Typography,
  CardActionArea,
  Stack,
  Tooltip,
  Divider,
} from '@mui/material';
import dayjs from 'dayjs';

import { capitalizeFirstLetter } from '../../utils/capitalizeFirstLetter';

import styles from './styles';

function AssignmentCard({
  title,
  classrooms,
  dueDate,
  scores,
  deliveredByStudents,
  reviewed,
  total,
  isAssignmentToReview,
  layoutType,
  onClick,
}) {
  const {
    cardContainer,
    classroomLinesIndicator,
    cardActionArea,
    cardContent,
    typographyTitle,
    stackClassroomNames,
    typographyClassroomNames,
    dividerMiddle,
    typographyDueDate,
  } = styles[layoutType];

  if (layoutType === 'desktop') {
    return (
      <Card sx={cardContainer(classrooms)}>
        {classrooms.length > 1 &&
          classrooms
            .filter((_, i) => i > 0)
            .map(c => <div key={c.id} style={classroomLinesIndicator(c)} />)}
        <CardActionArea onClick={() => onClick()} sx={cardActionArea}>
          <CardContent sx={cardContent}>
            <Tooltip title={title}>
              <Typography
                sx={typographyTitle}
                gutterBottom
                variant="h6"
                component="div"
              >
                {title}
              </Typography>
            </Tooltip>
            <Stack sx={stackClassroomNames}>
              <Typography
                sx={typographyClassroomNames}
                variant="p"
                component="div"
              >
                {classrooms.map(c => c.name).join(', ')}
              </Typography>
              <Divider sx={dividerMiddle} />

              <Typography sx={typographyDueDate} variant="p" component="div">
                <strong>Data de entrega: </strong>{' '}
                {capitalizeFirstLetter(
                  dayjs(dueDate).format('dddd, DD/MM | HH:mm[h]')
                )}
              </Typography>
              {deliveredByStudents >= 0 && total && (
                <Typography variant="p" component="div">
                  <strong>Entregues: </strong>{' '}
                  {`${deliveredByStudents} de ${total}`}
                </Typography>
              )}
              {reviewed >= 0 && total && (
                <Typography variant="p" component="div">
                  <strong>Corrigidas: </strong> {`${reviewed} de ${total}`}
                </Typography>
              )}
              {!isAssignmentToReview && (
                <Typography variant="p" component="div">
                  <strong>Valor: </strong>
                  {scores.map(s => s.value).join(', ')} pts
                </Typography>
              )}
            </Stack>
          </CardContent>
        </CardActionArea>
      </Card>
    );
  } else if (layoutType === 'mobile') {
    return (
      <Card sx={cardContainer(classrooms)}>
        <CardActionArea onClick={() => onClick()} sx={cardActionArea}>
          {classrooms.length > 1 &&
            classrooms
              .filter((_, i) => i > 0)
              .map(c => <div key={c.id} style={classroomLinesIndicator(c)} />)}
          <CardContent sx={cardContent}>
            <Tooltip title={title}>
              <Typography
                sx={typographyTitle}
                gutterBottom
                variant="h6"
                component="div"
              >
                {title}
              </Typography>
            </Tooltip>
            <Stack sx={stackClassroomNames}>
              <Typography
                sx={typographyClassroomNames}
                variant="p"
                component="div"
              >
                {classrooms.map(c => c.name).join(', ')}
              </Typography>
              <Divider sx={dividerMiddle} />
              <Typography sx={typographyDueDate} variant="p" component="div">
                <strong>Data de entrega: </strong>
                {capitalizeFirstLetter(
                  dayjs(dueDate).format('dddd, DD/MM | HH:mm[h]')
                )}
              </Typography>
              {deliveredByStudents >= 0 && total && (
                <Typography variant="p" component="div">
                  <strong>Entregues: </strong>{' '}
                  {`${deliveredByStudents} de ${total}`}
                </Typography>
              )}
              {reviewed >= 0 && total && (
                <Typography variant="p" component="div">
                  <strong>Corrigidas: </strong> {`${reviewed} de ${total}`}
                </Typography>
              )}
              {!isAssignmentToReview && (
                <Typography variant="p" component="div">
                  <strong>Valor: </strong>
                  {scores.map(s => s.value).join(', ')} pts
                </Typography>
              )}
            </Stack>
          </CardContent>
        </CardActionArea>
      </Card>
    );
  }
}

export default AssignmentCard;