diff --git a/src/components/CardTabs/Users/UserElement.jsx b/src/components/CardTabs/Users/UserElement.jsx
index 2a6c2a9c..56db8b88 100644
--- a/src/components/CardTabs/Users/UserElement.jsx
+++ b/src/components/CardTabs/Users/UserElement.jsx
@@ -1,11 +1,49 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import Box from "@mui/material/Box";
import AddUser from "../../../assets/images/add-user.svg";
import CheckUser from "../../../assets/images/square-check-regular.svg";
+import { useFirestore } from "react-redux-firebase";
+import { useSelector } from "react-redux";
+import {
+ isUserFollower,
+ addUserFollower,
+ removeUserFollower
+} from "../../../store/actions";
const UserElement = ({ user, index, useStyles }) => {
const classes = useStyles();
- const [icon, setIcon] = useState(true);
+ const firestore = useFirestore();
+
+ const profileData = user;
+ const currentProfileData = useSelector(
+ ({ firebase: { profile } }) => profile
+ );
+ const followerId = currentProfileData.uid;
+ const followingId = profileData.uid;
+ const [followed, setFollowed] = useState(false);
+
+ const handleFollowToggle = async () => {
+ if (!followed) {
+ await addUserFollower(currentProfileData, profileData, firestore);
+ } else {
+ await removeUserFollower(currentProfileData, profileData, firestore);
+ }
+ setFollowed(!followed);
+ };
+
+ useEffect(() => {
+ const checkIfFollowing = async () => {
+ const isFollowing = await isUserFollower(
+ followerId,
+ followingId,
+ firestore
+ );
+ setFollowed(isFollowing);
+ };
+
+ checkIfFollowing();
+ }, [followerId, followingId, firestore]);
+
return (
{
{
- setIcon(false);
- }}
+ onClick={handleFollowToggle}
data-testId={index == 0 ? "UserAdd" : ""}
- sx={
- icon && {
- cursor: "pointer"
- }
- }
+ sx={{
+ cursor: followed ? "default" : "pointer"
+ }}
>
-
+
);