| 11347 |
nelberth |
1 |
import {axios} from "../../../utils";
|
|
|
2 |
import React, { useEffect, useState } from "react";
|
|
|
3 |
import Spinner from "../../../shared/loading-spinner/Spinner";
|
|
|
4 |
|
|
|
5 |
import styles from "./addMember.module.scss";
|
|
|
6 |
|
|
|
7 |
const AddMember = (props) => {
|
|
|
8 |
const {
|
|
|
9 |
url_add_user_to_group,
|
|
|
10 |
url_get_contacts_availables_for_group,
|
|
|
11 |
} = props.group;
|
|
|
12 |
|
|
|
13 |
const [loading, setLoading] = useState(false);
|
|
|
14 |
const [contacts, setContacts] = useState([]);
|
|
|
15 |
|
|
|
16 |
useEffect(() => {
|
|
|
17 |
getContacts();
|
|
|
18 |
}, []);
|
|
|
19 |
|
|
|
20 |
const getContacts = async () => {
|
|
|
21 |
setLoading(true);
|
|
|
22 |
const response = await axios.get(url_get_contacts_availables_for_group);
|
|
|
23 |
const resData = response.data;
|
|
|
24 |
if (!resData.success) {
|
|
|
25 |
return (resData);
|
|
|
26 |
}
|
|
|
27 |
setContacts(resData.data);
|
|
|
28 |
setLoading(false);
|
|
|
29 |
};
|
|
|
30 |
|
|
|
31 |
const handleAddMember = async (id) => {
|
|
|
32 |
setLoading(true);
|
|
|
33 |
const formData = new FormData();
|
|
|
34 |
formData.append("uid", id);
|
|
|
35 |
const response = await axios.post(url_add_user_to_group, formData);
|
|
|
36 |
const resData = response.data;
|
|
|
37 |
if (!resData.success) {
|
|
|
38 |
setLoading(false);
|
|
|
39 |
return (resData);
|
|
|
40 |
}
|
|
|
41 |
await getContacts();
|
|
|
42 |
setLoading(false);
|
|
|
43 |
};
|
|
|
44 |
|
|
|
45 |
return (
|
|
|
46 |
<div className={styles.addMember}>
|
|
|
47 |
{contacts.map(({ id, image, name }) => (
|
|
|
48 |
<li className={styles.entity} onClick={() => handleAddMember(id)}>
|
|
|
49 |
<img src={image} alt="user_image" />
|
|
|
50 |
<span className={styles.entityName}>{name}</span>
|
|
|
51 |
<div className={styles.entityOptions}>
|
|
|
52 |
<i className={`fa fa-plus-circle`}></i>
|
|
|
53 |
</div>
|
|
|
54 |
</li>
|
|
|
55 |
))}
|
|
|
56 |
{loading && (
|
|
|
57 |
<div className="spinner-container">
|
|
|
58 |
<Spinner />
|
|
|
59 |
</div>
|
|
|
60 |
)}
|
|
|
61 |
</div>
|
|
|
62 |
);
|
|
|
63 |
};
|
|
|
64 |
|
|
|
65 |
export default AddMember;
|