Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7165 | Rev 7209 | 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
 
10
const StyledQuestionCard = styled(Card)`
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
 
38
const QuestionDetails = styled.div`
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
 
49
const QuestionUserInfo = styled.div`
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
 
7162 stevensc 61
const QuestionActions = styled.div`
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
 
7165 stevensc 80
const QuestionStats = styled.div`
81
  display: flex;
82
  align-items: center;
83
  gap: 0.5rem;
84
`
85
 
7160 stevensc 86
const QuestionCard = ({
7163 stevensc 87
  updated_on = '',
88
  link_add_comment = '',
89
  added_on = '',
7160 stevensc 90
  user_name = '',
91
  user_image = '',
92
  title = '',
93
  description = '',
94
  categories = [],
95
  views = 0,
96
  answers = 0,
97
  reactions = 0,
98
  comments = 0,
99
  link_view = '',
100
  link_edit = '',
101
  link_delete = '',
7163 stevensc 102
  onDelete = () => null,
103
  onEdit = () => null,
7160 stevensc 104
}) => {
105
  const labels = useSelector(({ intl }) => intl.labels)
7163 stevensc 106
  const history = useHistory()
7160 stevensc 107
 
7163 stevensc 108
  const onView = (url = '') => {
109
    history.replace(url)
110
  }
111
 
7160 stevensc 112
  return (
113
    <StyledQuestionCard>
114
      <QuestionDetails>
115
        <QuestionUserInfo>
116
          <Avatar
117
            src={user_image}
118
            alt={`${user_name} profile image`}
119
            sx={{ width: '50px', height: '50px' }}
120
          />
121
          <p>{user_name}</p>
122
        </QuestionUserInfo>
123
        <ul className="question-categories">
7161 stevensc 124
          {categories.map(({ category }) => (
7160 stevensc 125
            <li key={category}>{category}</li>
126
          ))}
127
        </ul>
128
      </QuestionDetails>
129
 
130
      <h2>{title}</h2>
131
      <span>{`${labels.my_coach_question} ${added_on}`}</span>
132
      <p className="my-3">{description}</p>
133
 
7165 stevensc 134
      <QuestionStats className="mb-2">
7160 stevensc 135
        <span>{`${answers} ${labels.my_coach_answers}`}</span>
136
        <span>{`${reactions} ${labels.my_coach_reactions}`}</span>
137
        <span>{`${views} ${labels.my_coach_views}`}</span>
138
        <span>{`${comments} ${labels.comments}`}</span>
7165 stevensc 139
      </QuestionStats>
7160 stevensc 140
 
7162 stevensc 141
      <QuestionActions>
7160 stevensc 142
        {link_view && (
7163 stevensc 143
          <button
144
            className="btn feed__share-option"
145
            onClick={() => onView(link_view)}
146
          >
7160 stevensc 147
            <OpenInNewIcon />
148
            {labels.view}
149
          </button>
150
        )}
151
        {link_edit && (
7163 stevensc 152
          <button
153
            className="btn feed__share-option"
154
            onClick={() => onEdit(link_edit)}
155
          >
7160 stevensc 156
            <EditIcon />
157
            {labels.edit}
158
          </button>
159
        )}
160
        {link_delete && (
7163 stevensc 161
          <button
162
            className="btn feed__share-option"
163
            onClick={() => onDelete(link_delete)}
164
          >
7160 stevensc 165
            <DeleteIcon />
166
            {labels.delete}
167
          </button>
168
        )}
7162 stevensc 169
      </QuestionActions>
7160 stevensc 170
    </StyledQuestionCard>
171
  )
172
}
173
 
174
export default QuestionCard