-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete.jsx
63 lines (58 loc) · 1.87 KB
/
delete.jsx
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
import React, { useState } from 'react';
import axios from 'axios';
import "./delete.css";
import { URL } from './config';
const DeleteDocument = () => {
const [collection, setCollection] = useState('');
const [userId, setUserId] = useState('');
const [message, setMessage] = useState('');
const handleDelete = async () => {
try {
console.log(userId);
const response = await axios.put(`${URL}delete`, {
collection: collection,
searchFieldValue: userId
});
setMessage(response.data.message);
} catch (error) {
setMessage('Error deleting document');
}
};
// const handleDelete = async () => {
// try {
// const response = await axios.delete(`http://localhost:3000/deleteDocument/${collection}/${userId}`);
// console.log(response.data);
// } catch (error) {
// console.error('Error deleting document:', error);
// }
// };
// const handleDelete = async () => {
// try {
// const response = await axios.put('http://localhost:3000/updateDocument', {
// collection: collection,
// searchFieldValue: searchFieldValue,
// });
// console.log(response.data);
// } catch (error) {
// console.error('Error updating document:', error);
// }
// };
return (
<div className="delete-container">
<h1>Delete Document</h1>
<label>
Collection Name:
<input type="text" value={collection} onChange={(e) => setCollection(e.target.value)} />
</label>
<br />
<label>
User ID:
<input type="text" value={userId} onChange={(e) => setUserId(e.target.value)} />
</label>
<br />
<button className='del' onClick={handleDelete}>Delete Document</button>
{message && <p>{message}</p>}
</div>
);
};
export default DeleteDocument;