Answer the question
In order to leave comments, you need to log in
How to remove user from firebase database by uid?
It is necessary that when clicking on 'delete', the user is deleted from the firebase by uid.
import React from 'react';
import { Table,Tag,Spin,Popconfirm } from 'antd';
import { withFirebase } from '../Firebase';
class TableOffice extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: false,
users: [],
};
}
componentDidMount() {
this.setState({ loading: true });
this.props.firebase.users().on('value', snapshot => {
const usersObject = snapshot.val();
const dataSource = Object.keys(usersObject).map(key => ({
...usersObject[key],
uid: key,
}));
this.setState({
users: dataSource,
loading: false,
});
});
}
render(){
const { users, loading } = this.state;
const columns = [
{
title: 'Имя',
dataIndex: 'name',
key: 'name',
},
{
title: 'Фамилия',
dataIndex: 'surname',
key: 'surname',
},
{
title: 'E-mail',
dataIndex: 'email',
key: 'email',
},
{
title: 'Телефон',
dataIndex: 'phone',
key: 'phone',
},
{
title: 'Статус',
key: 'check',
dataIndex: 'check',
render: status => status ? <Tag color = 'green'>На работе</Tag> : <Tag color = 'red'>Отсутствует</Tag>
},
{
title: 'Действие',
dataIndex: 'action',
render: (text, record) =>
this.state.users.length >= 1 ? (
<Popconfirm okText="Да" cancelText= "Отмена" title="Точно удалить?" onConfirm={this.onRemoveMessage}>
<a href='javascript:;'>Удалить</a>
</Popconfirm>
) : null,
},
];
return(
<div>
<Table
columns={columns}
dataSource={users}
/>
</div>
);
}
}
export default withFirebase(TableOffice);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question