Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 5 | Rev 406 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5 stevensc 1
import React from 'react'
2
import { Avatar, Card } from '@mui/material'
3
import { useSelector } from 'react-redux'
4
import { useHistory } from 'react-router-dom'
5
import styled from 'styled-components'
6
 
7
import OpenInNewIcon from '@mui/icons-material/OpenInNew'
8
import EditIcon from '@mui/icons-material/Edit'
9
import DeleteIcon from '@mui/icons-material/Delete'
10
import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew'
11
 
12
export const StyledQuestionCard = styled(Card)`
13
  background: var(--bg-color);
14
  border: 1px solid var(--border-primary);
15
  border-radius: var(--border-radius);
16
  height: fit-content;
17
  padding: 1rem 0;
18
  & > * {
19
    padding-right: 1rem;
20
    padding-left: 1rem;
21
  }
22
  & > h2 {
23
    font-size: 2rem;
24
    line-height: 1.2;
25
  }
26
  p {
27
    color: var(--font-color);
28
    font-size: 1rem;
29
    font-weight: 400;
30
    text-align: justify;
31
    margin-bottom: 0.5rem;
32
  }
33
  span {
34
    color: var(--subtitle-color);
35
    font-weight: 600;
36
    font-size: 0.9rem;
37
  }
38
`
39
 
40
export const QuestionDetails = styled.div`
41
  display: flex;
42
  align-items: center;
43
  flex-wrap: wrap;
44
  gap: 1rem;
45
  justify-content: space-between;
46
  margin-bottom: 0.5rem;
47
  padding-bottom: 0.5rem;
48
  border-bottom: 1px solid var(--border-primary);
49
`
50
 
51
export const QuestionUserInfo = styled.div`
52
  align-items: center;
53
  border-radius: var(--border-radius);
54
  color: var(--font-color);
55
  display: inline-flex;
56
  font-weight: 600;
57
  gap: 0.5rem;
58
  padding: 0.5rem;
59
  width: fit-content;
60
`
61
 
62
export const QuestionActions = styled.div`
63
  display: flex;
64
  align-items: center;
65
  gap: 0.5rem;
66
  justify-content: space-around;
67
  padding-top: 0.5rem;
68
  border-top: 1px solid var(--border-primary);
69
  & > * {
70
    flex-grow: 1;
71
  }
72
  .btn {
73
    color: var(--icons-color);
74
    font-size: 1rem !important;
75
    border: 1px solid var(--border-primary) !important;
76
    border-radius: var(--border-radius) !important;
77
    padding: 5px !important;
78
    position: relative;
79
  }
80
`
81
 
82
export const QuestionStats = styled.div`
83
  display: flex;
84
  align-items: center;
85
  gap: 0.5rem;
86
`
87
 
88
export const QuestionCategories = styled.ul`
89
  align-items: center;
90
  display: flex;
91
  gap: 0.5rem;
92
  flex-wrap: wrap;
93
  max-width: 200px;
94
  li {
404 stevensc 95
    background: #c6d1f0;
5 stevensc 96
    border-radius: var(--border-radius);
97
    color: var(--font-color);
98
    padding: 0.4rem 0.6rem;
99
    font-size: 0.9rem;
100
    font-weight: 600;
101
  }
102
`
103
 
104
const QuestionCard = ({
105
  last_answer_on = '',
106
  added_on = '',
107
  user_name = '',
108
  user_image = '',
109
  title = '',
110
  description = '',
111
  categories = [],
112
  views = 0,
113
  answers = 0,
114
  reactions = 0,
115
  comments = 0,
116
  link_view = '',
117
  link_edit = '',
118
  link_delete = '',
119
  link_answers_add = '',
120
  link_answers = '',
121
  onDelete = () => null,
122
  onEdit = () => null,
123
  onReply = () => null,
124
}) => {
125
  const labels = useSelector(({ intl }) => intl.labels)
126
  const history = useHistory()
127
 
128
  const onView = (url = '') => {
129
    history.replace(url)
130
  }
131
 
132
  const goBack = () => {
133
    history.replace('/my-coach')
134
  }
135
 
136
  return (
137
    <StyledQuestionCard>
138
      <QuestionDetails>
139
        <QuestionUserInfo>
140
          <Avatar
141
            src={user_image}
142
            alt={`${user_name} profile image`}
143
            sx={{ width: '50px', height: '50px' }}
144
          />
145
          <p>{user_name}</p>
146
        </QuestionUserInfo>
147
        <QuestionCategories>
148
          {categories.map(({ category }) => (
149
            <li key={category}>{category}</li>
150
          ))}
151
        </QuestionCategories>
152
      </QuestionDetails>
153
 
154
      <h2>{title}</h2>
155
      <span>{`${labels.my_coach_question} ${added_on}`}</span>
156
      {last_answer_on && (
157
        <span>{`${labels.my_coach_last_answer} ${last_answer_on}`}</span>
158
      )}
159
      <p className="my-3">{description}</p>
160
 
161
      <QuestionStats className="mb-2">
162
        <span>{`${answers} ${labels.my_coach_answers}`}</span>
163
        <span>{`${reactions} ${labels.my_coach_reactions}`}</span>
164
        <span>{`${views} ${labels.my_coach_views}`}</span>
165
        <span>{`${comments} ${labels.comments}`}</span>
166
      </QuestionStats>
167
 
168
      <QuestionActions>
169
        {link_answers && (
170
          <button className="btn feed__share-option" onClick={goBack}>
171
            <ArrowBackIosNewIcon />
172
            {labels.back}
173
          </button>
174
        )}
175
        {link_view && (
176
          <button
177
            className="btn feed__share-option"
178
            onClick={() => onView(link_view)}
179
          >
180
            <OpenInNewIcon />
181
            {labels.view}
182
          </button>
183
        )}
184
        {link_edit && (
185
          <button
186
            className="btn feed__share-option"
187
            onClick={() => onEdit(link_edit)}
188
          >
189
            <EditIcon />
190
            {labels.edit}
191
          </button>
192
        )}
193
        {link_answers_add && (
194
          <button
195
            className="btn feed__share-option"
196
            onClick={() => onReply(link_edit)}
197
          >
198
            <EditIcon />
199
            {labels.reply}
200
          </button>
201
        )}
202
        {link_delete && (
203
          <button
204
            className="btn feed__share-option"
205
            onClick={() => onDelete(link_delete)}
206
          >
207
            <DeleteIcon />
208
            {labels.delete}
209
          </button>
210
        )}
211
      </QuestionActions>
212
    </StyledQuestionCard>
213
  )
214
}
215
 
216
export default QuestionCard