Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15192 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 15192 Rev 16793
Línea 6... Línea 6...
6
import PaginationComponent from '../../shared/PaginationComponent'
6
import PaginationComponent from '../../shared/PaginationComponent'
7
import ContentTitle from '../../shared/ContentTitle'
7
import ContentTitle from '../../shared/ContentTitle'
8
import Spinner from '../../shared/Spinner'
8
import Spinner from '../../shared/Spinner'
Línea 9... Línea 9...
9
 
9
 
-
 
10
const Followers = ({ backendVars }) => {
Línea 10... Línea 11...
10
const Followers = ({ backendVars }) => {
11
  let axiosThrottle = null
Línea 11... Línea -...
11
 
-
 
12
	let axiosThrottle = null
-
 
13
 
12
 
14
	const { table_link, allowDelete } = backendVars
13
  const { table_link, allowDelete } = backendVars
15
 
14
 
16
	const [followers, setFollowers] = useState([])
15
  const [followers, setFollowers] = useState([])
17
	const [loading, setLoading] = useState(true)
16
  const [loading, setLoading] = useState(true)
18
	const [pages] = useState(1)
17
  const [pages] = useState(1)
19
	const [currentPage, setCurrentPage] = useState(1)
18
  const [currentPage, setCurrentPage] = useState(1)
20
 
19
 
21
	const { register, watch } = useForm()
20
  const { register, watch } = useForm()
22
 
21
 
23
	useEffect(() => {
22
  useEffect(() => {
24
		fetchFollowers()
23
    fetchFollowers()
25
		return () => clearTimeout(axiosThrottle)
24
    return () => clearTimeout(axiosThrottle)
26
	}, [currentPage])
25
  }, [currentPage])
27
 
26
 
28
	const fetchFollowers = async () => {
27
  const fetchFollowers = async () => {
29
		setLoading(true)
28
    setLoading(true)
30
		let params = {
29
    let params = {
31
			params: {
30
      params: {
32
				page: currentPage,
31
        page: currentPage
33
			},
32
      }
34
		}
33
    }
35
		if (watch('search')) {
34
    if (watch('search')) {
36
			params = { params: { ...params.params, search: watch('search') } }
-
 
37
		}
35
      params = { params: { ...params.params, search: watch('search') } }
38
		await axios.get(table_link, params)
36
    }
39
			.then(({ data }) => {
37
    await axios.get(table_link, params).then(({ data }) => {
40
				if (data.success) {
38
      if (data.success) {
41
					setFollowers(data.data.items)
39
        setFollowers(data.data.items)
42
				}
40
      }
43
			})
41
    })
44
		setLoading(false)
42
    setLoading(false)
45
	}
43
  }
46
 
44
 
47
	const handleSearch = () => {
45
  const handleSearch = () => {
48
		clearTimeout(axiosThrottle)
46
    clearTimeout(axiosThrottle)
49
		axiosThrottle = setTimeout(() => {
47
    axiosThrottle = setTimeout(() => {
50
			fetchFollowers()
48
      fetchFollowers()
51
		}, 500)
49
    }, 500)
52
	}
50
  }
53
 
51
 
54
	const deleteFollower = (email) => {
52
  const deleteFollower = (email) => {
55
		setFollowers(followers.filter((follower) => follower.email !== email))
53
    setFollowers(followers.filter((follower) => follower.email !== email))
56
	}
54
  }
57
 
55
 
58
	const handleChangePage = (newPage) => {
56
  const handleChangePage = (newPage) => {
59
		setCurrentPage(newPage)
57
    setCurrentPage(newPage)
60
	}
58
  }
61
 
59
 
62
	return (
60
  return (
63
		<ContentTitle title="Seguidores">
61
    <ContentTitle title="Seguidores">
64
			<div className="company-title">
62
      <div className="company-title">
65
				<div className="section_admin_title_buttons">
63
        <div className="section_admin_title_buttons">
66
					<form
64
          <form
67
						name="form-connection-search"
65
            name="form-connection-search"
68
						id="form-connection-search"
66
            id="form-connection-search"
69
						onSubmit={(event) => event.preventDefault()}
67
            onSubmit={(event) => event.preventDefault()}
70
					>
68
          >
71
						<div className="form-group">
69
            <div className="form-group">
72
							<input
70
              <input
73
								type="text"
71
                type="text"
74
								name="search"
72
                name="search"
75
								id="search"
73
                id="search"
76
								className="form-control"
74
                className="form-control"
77
								placeholder="Buscar"
75
                placeholder="Buscar"
78
								ref={register}
76
                ref={register}
79
								onChange={handleSearch}
77
                onChange={handleSearch}
80
							/>
78
              />
81
						</div>
79
            </div>
82
					</form>
80
          </form>
83
				</div>
81
        </div>
84
			</div>
-
 
85
 
-
 
86
			<div className="companies-list">
-
 
87
				<div
-
 
88
					className="row"
-
 
89
					id="profiles-container"
-
 
90
					style={{
-
 
91
						position: 'relative',
-
 
92
					}}
82
      </div>
93
				>
83
 
94
					{
84
      <div className="row position-relative">
95
						loading
85
        {loading ? (
96
							? <Spinner />
86
          <Spinner />
97
							:
87
        ) : (
98
							followers.map(({ first_name, last_name, email, actions }, index) => (
88
          followers.map(({ first_name, last_name, email, actions }, index) => (
99
								<Follower
89
            <Follower
100
									key={index}
90
              key={index}
101
									first_name={first_name}
91
              first_name={first_name}
102
									last_name={last_name}
92
              last_name={last_name}
103
									email={email}
93
              email={email}
104
									actions={actions}
94
              actions={actions}
-
 
95
              allowDelete={allowDelete}
105
									allowDelete={allowDelete}
96
              deleteFollower={deleteFollower}
106
									deleteFollower={deleteFollower}
97
            />
107
								/>
98
          ))
108
							))}
99
        )}
109
					<PaginationComponent
100
        <PaginationComponent
110
						pages={pages}
101
          pages={pages}
111
						currentPage={currentPage}
102
          currentPage={currentPage}
112
						onChangePage={handleChangePage}
-
 
113
					/>
103
          onChangePage={handleChangePage}
114
				</div>
104
        />
115
			</div>
105
      </div>
Línea 116... Línea -...
116
		</ContentTitle>
-
 
117
	)
106
    </ContentTitle>
-
 
107
  )