Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 404 | Rev 407 | 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
  display: inline-flex;
54
  gap: 0.5rem;
55
  width: fit-content;
406 stevensc 56
  span {
57
    color: var(--subtitle-color);
58
    font-weight: 600;
59
    font-size: 1rem;
60
  }
5 stevensc 61
`
62
 
63
export const QuestionActions = styled.div`
64
  display: flex;
65
  align-items: center;
66
  gap: 0.5rem;
67
  justify-content: space-around;
68
  padding-top: 0.5rem;
69
  border-top: 1px solid var(--border-primary);
70
  & > * {
71
    flex-grow: 1;
72
  }
73
  .btn {
74
    color: var(--icons-color);
75
    font-size: 1rem !important;
76
    border: 1px solid var(--border-primary) !important;
77
    border-radius: var(--border-radius) !important;
78
    padding: 5px !important;
79
    position: relative;
80
  }
81
`
82
 
83
export const QuestionStats = styled.div`
84
  display: flex;
85
  align-items: center;
86
  gap: 0.5rem;
87
`
88
 
89
export const QuestionCategories = styled.ul`
90
  align-items: center;
91
  display: flex;
92
  gap: 0.5rem;
93
  flex-wrap: wrap;
94
  max-width: 200px;
95
  li {
404 stevensc 96
    background: #c6d1f0;
5 stevensc 97
    border-radius: var(--border-radius);
98
    color: var(--font-color);
99
    padding: 0.4rem 0.6rem;
100
    font-size: 0.9rem;
101
    font-weight: 600;
102
  }
103
`
104
 
105
const QuestionCard = ({
106
  last_answer_on = '',
107
  added_on = '',
108
  user_name = '',
109
  user_image = '',
110
  title = '',
111
  description = '',
112
  categories = [],
113
  views = 0,
114
  answers = 0,
115
  reactions = 0,
116
  comments = 0,
117
  link_view = '',
118
  link_edit = '',
119
  link_delete = '',
120
  link_answers_add = '',
121
  link_answers = '',
122
  onDelete = () => null,
123
  onEdit = () => null,
124
  onReply = () => null,
125
}) => {
126
  const labels = useSelector(({ intl }) => intl.labels)
127
  const history = useHistory()
128
 
129
  const onView = (url = '') => {
130
    history.replace(url)
131
  }
132
 
133
  const goBack = () => {
134
    history.replace('/my-coach')
135
  }
136
 
137
  return (
138
    <StyledQuestionCard>
139
      <QuestionDetails>
140
        <QuestionUserInfo>
141
          <Avatar
142
            src={user_image}
143
            alt={`${user_name} profile image`}
144
            sx={{ width: '50px', height: '50px' }}
145
          />
406 stevensc 146
          <span>{user_name}</span>
5 stevensc 147
        </QuestionUserInfo>
148
        <QuestionCategories>
149
          {categories.map(({ category }) => (
150
            <li key={category}>{category}</li>
151
          ))}
152
        </QuestionCategories>
153
      </QuestionDetails>
154
 
155
      <h2>{title}</h2>
156
      <span>{`${labels.my_coach_question} ${added_on}`}</span>
157
      {last_answer_on && (
158
        <span>{`${labels.my_coach_last_answer} ${last_answer_on}`}</span>
159
      )}
160
      <p className="my-3">{description}</p>
161
 
162
      <QuestionStats className="mb-2">
163
        <span>{`${answers} ${labels.my_coach_answers}`}</span>
164
        <span>{`${reactions} ${labels.my_coach_reactions}`}</span>
165
        <span>{`${views} ${labels.my_coach_views}`}</span>
166
        <span>{`${comments} ${labels.comments}`}</span>
167
      </QuestionStats>
168
 
169
      <QuestionActions>
170
        {link_answers && (
171
          <button className="btn feed__share-option" onClick={goBack}>
172
            <ArrowBackIosNewIcon />
173
            {labels.back}
174
          </button>
175
        )}
176
        {link_view && (
177
          <button
178
            className="btn feed__share-option"
179
            onClick={() => onView(link_view)}
180
          >
181
            <OpenInNewIcon />
182
            {labels.view}
183
          </button>
184
        )}
185
        {link_edit && (
186
          <button
187
            className="btn feed__share-option"
188
            onClick={() => onEdit(link_edit)}
189
          >
190
            <EditIcon />
191
            {labels.edit}
192
          </button>
193
        )}
194
        {link_answers_add && (
195
          <button
196
            className="btn feed__share-option"
197
            onClick={() => onReply(link_edit)}
198
          >
199
            <EditIcon />
200
            {labels.reply}
201
          </button>
202
        )}
203
        {link_delete && (
204
          <button
205
            className="btn feed__share-option"
206
            onClick={() => onDelete(link_delete)}
207
          >
208
            <DeleteIcon />
209
            {labels.delete}
210
          </button>
211
        )}
212
      </QuestionActions>
213
    </StyledQuestionCard>
214
  )
215
}
216
 
217
export default QuestionCard