[13f1472] | 1 | import React, {useEffect, useState} from 'react';
|
---|
| 2 | import {Checkbox, Input, List} from "antd";
|
---|
| 3 | import moment from "moment";
|
---|
| 4 | import axios from "axios";
|
---|
| 5 | import env from "../env";
|
---|
| 6 |
|
---|
| 7 | const Vip = (props) =>{
|
---|
| 8 |
|
---|
| 9 | const [loading,setLoading] = useState(true);
|
---|
| 10 | const [users,setUsers] = useState([]);
|
---|
| 11 |
|
---|
| 12 | const getData = () =>{
|
---|
| 13 | axios.get(env.api + 'Users', {
|
---|
| 14 | headers: {Authorization: localStorage.getItem('Auth')}
|
---|
| 15 | }).then(res => {
|
---|
| 16 | console.log(res.data)
|
---|
| 17 | setUsers(res.data.sort(x => x.id));
|
---|
| 18 | setLoading(false);
|
---|
| 19 | });
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | useEffect(()=>{
|
---|
| 23 | getData()
|
---|
| 24 | },[])
|
---|
| 25 |
|
---|
| 26 | const updateVip = (id, val) => {
|
---|
| 27 | console.log(val.target.checked)
|
---|
| 28 | setLoading(true)
|
---|
| 29 | axios.post(env.api + 'Users/'+id+'/vip', {},{
|
---|
| 30 | params: {newStatus: val.target.checked},
|
---|
| 31 | headers: {Authorization: localStorage.getItem('Auth')}
|
---|
| 32 | }).then(res => {
|
---|
| 33 | getData()
|
---|
| 34 | setLoading(false);
|
---|
| 35 | });
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | return(
|
---|
| 40 | <div style={{padding:'20px'}}>
|
---|
| 41 | <div style={{
|
---|
| 42 | width: '100%',
|
---|
| 43 | height:'75px',
|
---|
| 44 | backgroundColor: 'white',
|
---|
| 45 | padding: '20px',
|
---|
| 46 | border: '1px solid lightgray'
|
---|
| 47 | }} >
|
---|
| 48 | <h2 style={{float: 'left'}}>VIP корисници</h2>
|
---|
| 49 | </div>
|
---|
| 50 | <div style={{backgroundColor:'white'}}>
|
---|
| 51 | <List loading={loading} dataSource={users} itemLayout={'horizontal'} locale={{emptyText:'Нема корисници'}}
|
---|
| 52 | renderItem={item => (
|
---|
| 53 | <List.Item
|
---|
| 54 | actions={[<Checkbox checked={item.isVip} onChange={(val)=>updateVip(item.id,val)}>Вип корисник</Checkbox>]}>
|
---|
| 55 | <div style={{display:'flex',flexDirection:'row',justifyContent:'space-between',width:'100%', padding:'10px'}}>
|
---|
| 56 | <span>{item.id}</span>
|
---|
| 57 | <span>{item.email}</span>
|
---|
| 58 | </div>
|
---|
| 59 | </List.Item>
|
---|
| 60 | )}/>
|
---|
| 61 | </div>
|
---|
| 62 | </div>
|
---|
| 63 | )
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | export default Vip; |
---|