Proyectos de Subversion LeadersLinked - SPA

Rev

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