-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddButton.js
137 lines (107 loc) · 4.08 KB
/
AddButton.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import React, { Component } from 'react';
// import logo from './logo.svg';
//import './App.css';
import firebase from '../lib/fire'
// import Unsigned from './Unsigned';
import LazyLoad from 'react-lazy-load';
import { Link } from 'react-router-dom'
import $ from "jquery";
import Dropdown from 'react-dropdown'
import 'react-dropdown/style.css'
class AddButton extends Component {
constructor(props){
super(props);
this.state={
val:"",
userExist:false,
options:[]
}
}
// $('.dropdown-button').dropdown({
// inDuration: 300,
// outDuration: 225,
// constrainWidth: false, // Does not change width of dropdown to that of the activator
// hover: true, // Activate on hover
// gutter: 0, // Spacing from edge
// belowOrigin: false, // Displays dropdown below the button
// alignment: 'left', // Displays dropdown with edge aligned to the left of button
// stopPropagation: false // Stops event propagation
// }
// );
func(groupId) {
console.log(groupId)
//alert("you have pressed the add member button")
//console.log(this.state.val)
//add the user with the given email
var opRef = firebase.database().ref('users1');
var callback = function(snapshot) {
var list=[];
var data = snapshot.val();
for (var key in data) {
var op = data[key];
if(op.useremail !=firebase.auth().currentUser.email)
{
var grouplist = [];
grouplist = op.usergroupkeys;
//logic for not adding same user to one group
if(grouplist){
var flag = false;
for(var key in grouplist){
if(key == groupId){
alert("already added in the group");
flag = true;
}
}
if(!flag)list.push(op.username)
}
}
}
this.setState({options:list});
//console.log(exist)
}.bind(this)
opRef.once('value').then(callback);
}
componentDidMount() {
console.log("componentDidMount");
var { groupId } = this.props;
this.func(groupId);
console.log(this.state.userExist)
declare var $: $
// $('.dropdown-button').dropdown({
// inDuration: 300,
// outDuration: 225,
// constrainWidth: false, // Does not change width of dropdown to that of the activator
// hover: false, // Activate on hover
// gutter: 0, // Spacing from edge
// belowOrigin: false, // Displays dropdown below the button
// alignment: 'left', // Displays dropdown with edge aligned to the left of button
// stopPropagation: false // Stops event propagation
// }
// );
}
render() {
var { groupId } = this.props;
console.log("render");
const defaultOption = "Add User";
console.log(groupId);
if(!this.state.options)return(<div className="progress">
<div className="indeterminate"></div>
</div>);
else return(
<span>
<div>
{//this._onSelect
// <Dropdown options={this.state.options}
// onChange={()=>{
// console.log("value")
// }
// }
// value={this.state.val} placeholder="Add an user" />
// </div>
}
</div>
</span>
);
}
}
export default AddButton;