forked from RiseUP/riseup-squad23
Funcionalidade de delete e botão de opções
This commit is contained in:
parent
5b63fa26ef
commit
06ff7d5324
Binary file not shown.
@ -3,7 +3,47 @@ import React, { useState, useEffect } from 'react';
|
||||
|
||||
function Table() {
|
||||
|
||||
// Usamos useState para guardar os dados, o que é uma boa prática
|
||||
|
||||
// Função para excluir paciente
|
||||
const deletePatient = async (id) => {
|
||||
|
||||
const requestOptionsDelete = {method: 'DELETE',redirect:'follow' };
|
||||
|
||||
|
||||
|
||||
if (!window.confirm('Tem certeza que deseja excluir este paciente?')) return;
|
||||
|
||||
const response = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`, requestOptionsDelete)
|
||||
.then(response => response.text())
|
||||
.then(mensage => console.log(mensage))
|
||||
.catch(error => console.log('Deu problema', error))
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
const onChange = (e, id) => {
|
||||
let value = e.target.value
|
||||
|
||||
console.log(e.target.value)
|
||||
|
||||
if(value === 'verdetalhes'){}
|
||||
|
||||
if(value === 'editar')
|
||||
{}
|
||||
|
||||
if(value === 'excluir'){
|
||||
console.log(`Excluir ${id}`)
|
||||
deletePatient(id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//const [resposta, setResposta] = useState(dadosEstáticos);
|
||||
|
||||
//const { data: pacientes, pagination } = resposta;
|
||||
@ -46,6 +86,7 @@ useEffect(() => {
|
||||
<th>Email</th>
|
||||
<th>Telefone</th>
|
||||
<th>Status</th>
|
||||
<th>Opções</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -61,6 +102,15 @@ useEffect(() => {
|
||||
{paciente.status}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<select name="" id="" onChange={(e) => onChange(e,paciente.id)}>
|
||||
<option value="">:</option>
|
||||
<option value="verdetalhes">Ver detalhes</option>
|
||||
<option value="editar">Editar</option>
|
||||
<option value="excluir">Excluir</option>
|
||||
</select></td>
|
||||
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user