Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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