Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
3432 stevensc 1
import React, { useState, useEffect } from "react";
2
import { Link, useLocation } from "react-router-dom";
3
import { useDispatch, useSelector } from "react-redux";
4
import { Button, Typography } from "@mui/material";
1847 stevensc 5
 
3432 stevensc 6
import { axios, parse } from "@utils";
7
import { addNotification } from "@store/notification/notification.actions";
8
import colors from "@styles/colors";
1847 stevensc 9
 
3432 stevensc 10
import Widget from "@components/UI/Widget";
11
import Cover from "@components/UI/cover/Cover";
12
import ConfirmModal from "@components/modals/ConfirmModal";
13
import ProfileModal from "./ProfileModal";
14
import Avatar from "@components/common/avatar";
15
import Row from "@components/common/Row";
1847 stevensc 16
 
17
const ProfileCard = ({
2905 stevensc 18
  cover,
19
  facebook,
20
  following,
21
  formatted_address: formattedAddress,
2902 stevensc 22
  full_name: fullName,
23
  image,
2905 stevensc 24
  instagram,
25
  link_cancel: linkCancel,
26
  link_inmail: linkInmail,
27
  link_request: linkRequest,
2902 stevensc 28
  overview,
2905 stevensc 29
  request_connection: requestConnection,
30
  show_contact: showContact,
31
  sizes,
32
  total_connections: totalConnections,
1847 stevensc 33
  twitter,
2905 stevensc 34
  user_experiences: userExperiences = [],
2902 stevensc 35
  view_following: viewFollowing,
3032 stevensc 36
  view_total_connections: viewTotalConnections,
3432 stevensc 37
  edit,
1847 stevensc 38
}) => {
3432 stevensc 39
  const [isAdded, setIsAdded] = useState(false);
40
  const [connectionUrl, setConnectionUrl] = useState("");
41
  const [modalToShow, setModalToShow] = useState(null);
42
  const [settedOverview, setSettedOverview] = useState("");
43
  const [isModalShow, setIsModalShow] = useState(false);
44
  const labels = useSelector(({ intl }) => intl.labels);
45
  const { pathname } = useLocation();
46
  const dispatch = useDispatch();
1847 stevensc 47
 
48
  const displayModal = () => {
3432 stevensc 49
    setIsModalShow(!isModalShow);
50
  };
1847 stevensc 51
 
52
  const getProfileData = async () => {
53
    try {
3432 stevensc 54
      const response = await axios.get(pathname);
55
      const { link_request, link_cancel } = response.data;
1847 stevensc 56
 
57
      if (link_request) {
3432 stevensc 58
        setConnectionUrl(link_request);
59
        return;
1847 stevensc 60
      }
61
 
3432 stevensc 62
      setConnectionUrl(link_cancel);
1847 stevensc 63
    } catch (err) {
3432 stevensc 64
      dispatch(addNotification({ style: "danger", msg: err.message }));
1847 stevensc 65
    }
3432 stevensc 66
  };
1847 stevensc 67
 
68
  const connect = async () => {
69
    try {
3432 stevensc 70
      const response = await axios.post(connectionUrl);
71
      const { data, success } = response.data;
1847 stevensc 72
 
73
      if (!success) {
3432 stevensc 74
        return dispatch(addNotification({ style: "danger", msg: data }));
1847 stevensc 75
      }
76
 
77
      if (success && isModalShow) {
3432 stevensc 78
        displayModal();
1847 stevensc 79
      }
80
 
3432 stevensc 81
      await getProfileData();
82
      dispatch(addNotification({ style: "success", msg: data }));
83
      setIsAdded(!isAdded);
1847 stevensc 84
    } catch (error) {
3432 stevensc 85
      dispatch(addNotification({ style: "danger", msg: `Error: ${error}` }));
1847 stevensc 86
    }
3432 stevensc 87
  };
1847 stevensc 88
 
89
  const closeModal = () => {
3432 stevensc 90
    setModalToShow(null);
91
  };
1847 stevensc 92
 
93
  useEffect(() => {
3432 stevensc 94
    setIsAdded(!requestConnection);
95
    setSettedOverview(overview);
96
  }, [requestConnection, overview]);
1847 stevensc 97
 
98
  useEffect(() => {
3432 stevensc 99
    linkRequest ? setConnectionUrl(linkRequest) : setConnectionUrl(linkCancel);
100
  }, [linkRequest, linkCancel]);
1847 stevensc 101
 
102
  return (
2902 stevensc 103
    <Widget>
3032 stevensc 104
      <Cover cover={cover} edit={edit} />
3047 stevensc 105
 
2906 stevensc 106
      <Widget.Body>
2911 stevensc 107
        <Avatar
108
          src={image}
109
          alt={fullName}
3075 stevensc 110
          badgeStyles={{
3432 stevensc 111
            mt: { xs: "-50px", lg: "-75px" },
3075 stevensc 112
          }}
2911 stevensc 113
          styles={{
3432 stevensc 114
            width: { xs: "100px", lg: "150px" },
115
            height: { xs: "100px", lg: "150px" },
116
            border: `1px solid ${colors.border.primary}`,
2911 stevensc 117
          }}
3032 stevensc 118
          edit={edit}
2911 stevensc 119
        />
2906 stevensc 120
 
3432 stevensc 121
        <Typography variant="h2">{fullName}</Typography>
2902 stevensc 122
        <Typography>{parse(settedOverview)}</Typography>
123
 
2909 stevensc 124
        <Row>
2902 stevensc 125
          <Typography>{formattedAddress}</Typography>
3432 stevensc 126
          <Typography variant="overline"> - </Typography>
127
          <Typography variant="overline" onClick={() => setModalToShow("info")}>
2902 stevensc 128
            {labels.personal_info}
2909 stevensc 129
          </Typography>
130
        </Row>
2902 stevensc 131
 
2909 stevensc 132
        <Row>
2912 stevensc 133
          {viewTotalConnections ? (
3432 stevensc 134
            <Link to="/connection/my-connections">
135
              <Typography variant="overline">
2913 stevensc 136
                {`${totalConnections} conexiones`}
2911 stevensc 137
              </Typography>
2902 stevensc 138
            </Link>
2912 stevensc 139
          ) : null}
140
          {viewFollowing ? (
2902 stevensc 141
            <Link onClick={(e) => e.preventDefault()}>
3432 stevensc 142
              <Typography variant="overline">
2913 stevensc 143
                {`${following} siguiendo`}
2911 stevensc 144
              </Typography>
2902 stevensc 145
            </Link>
2912 stevensc 146
          ) : null}
2909 stevensc 147
        </Row>
2902 stevensc 148
 
2909 stevensc 149
        <Row>
150
          {connectionUrl && isAdded && (
3432 stevensc 151
            <Button color="primary" onClick={() => displayModal()}>
2909 stevensc 152
              {labels.cancel}
153
            </Button>
154
          )}
155
          {connectionUrl && !isAdded && (
3432 stevensc 156
            <Button color="primary" onClick={connect}>
2909 stevensc 157
              {labels.connect}
158
            </Button>
159
          )}
160
          {showContact && (
3432 stevensc 161
            <Button to={linkInmail} LinkComponent={Link} color="secondary">
2909 stevensc 162
              {labels.message}
163
            </Button>
164
          )}
165
        </Row>
2902 stevensc 166
      </Widget.Body>
2909 stevensc 167
      {/*  {isEdit && (
168
        <>
169
          <OverviewModal
170
            isOpen={modalToShow === 'overview'}
171
            overview={settedOverview}
172
            id={profileId}
173
            closeModal={() => closeModal()}
174
            onComplete={(newOverview) => setSettedOverview(newOverview)}
175
          />
176
        </>
177
      )} */}
1847 stevensc 178
 
2902 stevensc 179
      <ProfileModal
3432 stevensc 180
        show={modalToShow === "info"}
1847 stevensc 181
        closeModal={() => closeModal()}
182
        fullName={fullName}
183
        facebook={facebook}
184
        twitter={twitter}
185
        instagram={instagram}
186
        following={following}
187
        formatted_address={formattedAddress}
188
        overview={overview}
189
        total_connections={totalConnections}
2902 stevensc 190
        // follower={follower}
1847 stevensc 191
      />
192
      <ConfirmModal
193
        show={isModalShow}
194
        onClose={() => setIsModalShow(false)}
195
        onAccept={() => connect()}
196
      />
2902 stevensc 197
    </Widget>
3432 stevensc 198
  );
199
};
1847 stevensc 200
 
3432 stevensc 201
export default ProfileCard;