summaryrefslogtreecommitdiff
path: root/src/screens/Profile/View.js
blob: c351dea2dc7f32c591efe9af78f704ec059f4f7d (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import { Edit } from '@mui/icons-material';
import {
  Avatar,
  Box,
  FormControl,
  InputLabel,
  MenuItem,
  Select,
  Stack,
  TextField,
  Typography,
  Container,
  Button,
  Fab,
} from '@mui/material';
import dayjs from 'dayjs';

import InputMask from '../../components/InputMask';

import { COURSES } from '../../utils/constants';
import { createArrayFrom1ToN } from '../../utils/createArrayFrom1ToN';
import styles from './styles';

function View({
  data,
  onChangeInput,
  onChangeFile,
  hiddenInputImageFileRef,
  layoutType,
}) {
  const {
    profileSummaryBox,
    avatarStack,
    avatar,
    avatarFab,
    profileSummaryStack,
    formBox,
    formField,
    formStack,
    fullNameTypography,
    button,
  } = styles[layoutType];
  const fullName = `${data.firstName} ${data.lastName}`;
  const currentYear = dayjs().year();

  return (
    <Container disableGutters sx={{ display: 'flex', flexDirection: 'column' }}>
      <Box sx={profileSummaryBox}>
        <Stack sx={avatarStack}>
          <Avatar alt={fullName} src={data.avatar} sx={avatar} />
          <input
            type="file"
            name="avatar"
            ref={hiddenInputImageFileRef}
            onChange={onChangeFile}
            style={{ display: 'none' }}
          />
          <Fab
            onClick={() => hiddenInputImageFileRef.current.click()}
            sx={avatarFab}
            size="small"
            color="primary"
            aria-label="add"
          >
            <Edit />
          </Fab>
        </Stack>
        <Stack sx={profileSummaryStack}>
          <Typography sx={fullNameTypography} variant="h4">
            {fullName}
          </Typography>
          <Typography variant="body2">
            Estudante de {COURSES.filter(c => c.value === data.course)[0].name}
          </Typography>
          <Typography variant="body2">Turma de {data.year}</Typography>
          <Typography variant="body2">
            <strong>RA: </strong> {data.ra}
          </Typography>
        </Stack>
      </Box>

      <Box sx={formBox}>
        <Stack {...formStack} component="form">
          <TextField
            id="firstName"
            name="firstName"
            label="Primeiro nome"
            variant="standard"
            type="text"
            sx={formField}
            value={data.firstName}
            onChange={onChangeInput}
          />

          <TextField
            id="lastName"
            name="lastName"
            label="Sobrenome"
            variant="standard"
            type="text"
            sx={formField}
            value={data.lastName}
            onChange={onChangeInput}
          />

          <TextField
            id="phone"
            name="phone"
            label="Telefone"
            variant="standard"
            type="phone"
            value={data.phone}
            onChange={onChangeInput}
            placeholder="(##) #####-####"
            sx={formField}
            InputProps={{
              inputComponent: InputMask,
            }}
          />

          <TextField
            id="email"
            name="email"
            label="E-mail"
            variant="standard"
            type="email"
            value={data.email}
            onChange={onChangeInput}
            sx={formField}
          />

          <TextField
            id="password"
            name="password"
            label="Senha"
            variant="standard"
            type="password"
            value={data.password}
            onChange={onChangeInput}
            sx={formField}
          />

          <FormControl sx={{ ...formField, textAlign: 'start' }} fullWidth>
            <InputLabel variant="standard" id="course">
              Curso
            </InputLabel>
            <Select
              variant="standard"
              labelId="course"
              id="course"
              name="course"
              value={data.course}
              label="Curso"
              onChange={onChangeInput}
            >
              {COURSES.map(course => (
                <MenuItem key={course.value} value={course.value}>
                  {course.name}
                </MenuItem>
              ))}
            </Select>
          </FormControl>
          <FormControl sx={{ ...formField, textAlign: 'start' }} fullWidth>
            <InputLabel variant="standard" id="course">
              Ano da turma
            </InputLabel>
            <Select
              variant="standard"
              labelId="year"
              id="year"
              name="year"
              value={data.year}
              label="Ano da turma"
              onChange={onChangeInput}
            >
              {createArrayFrom1ToN(8).map(i => (
                <MenuItem key={i - 1} value={currentYear - (i - 1)}>
                  {currentYear - (i - 1)}
                </MenuItem>
              ))}
            </Select>
          </FormControl>
          <TextField
            id="ra"
            name="ra"
            label="RA (Registro Acadêmico)"
            variant="standard"
            type="text"
            value={data.ra}
            placeholder="#######"
            disabled
            sx={{ ...formField, cursor: 'no-drop' }}
            InputProps={{
              inputComponent: InputMask,
            }}
          />

          <Button
            sx={button}
            onClick={() => console.log('clicked')}
            variant="contained"
          >
            Salvar alterações
          </Button>
        </Stack>
      </Box>
    </Container>
  );
}

export default View;