Salvamrnto padrao
This commit is contained in:
parent
035b4ff5d0
commit
b29dac619c
91
package-lock.json
generated
91
package-lock.json
generated
@ -27269,6 +27269,27 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/jsdom/node_modules/ws": {
|
||||
"version": "7.5.10",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz",
|
||||
"integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": "^5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/jsesc": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz",
|
||||
@ -30912,23 +30933,6 @@
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "2.8.8",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
||||
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"prettier": "bin-prettier.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/pretty-bytes": {
|
||||
"version": "5.6.0",
|
||||
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz",
|
||||
@ -32030,20 +32034,6 @@
|
||||
"node": ">=14.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-scripts/node_modules/yaml": {
|
||||
"version": "2.8.1",
|
||||
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.1.tgz",
|
||||
"integrity": "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==",
|
||||
"license": "ISC",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"yaml": "bin.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14.6"
|
||||
}
|
||||
},
|
||||
"node_modules/react-transition-group": {
|
||||
"version": "4.4.5",
|
||||
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz",
|
||||
@ -34869,9 +34859,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"version": "4.9.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz",
|
||||
"integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==",
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
@ -34879,7 +34869,7 @@
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
"node": ">=4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/uc.micro": {
|
||||
@ -35930,27 +35920,6 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/webpack-dev-server/node_modules/ws": {
|
||||
"version": "8.18.3",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz",
|
||||
"integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/webpack-manifest-plugin": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/webpack-manifest-plugin/-/webpack-manifest-plugin-4.1.1.tgz",
|
||||
@ -36628,16 +36597,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "7.5.10",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz",
|
||||
"integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==",
|
||||
"version": "8.18.3",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz",
|
||||
"integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8.3.0"
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": "^5.0.2"
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
|
||||
@ -1,15 +1,26 @@
|
||||
import React, { useState, useRef, useCallback } from "react";
|
||||
import { Link, useNavigate, useLocation } from "react-router-dom";
|
||||
import { useAuth } from "../components/utils/AuthProvider";
|
||||
import API_KEY from "../components/utils/apiKeys";
|
||||
import "./DoctorForm.css";
|
||||
import HorariosDisponibilidade from "../doctors/HorariosDisponibilidade";
|
||||
|
||||
const ENDPOINT_AVAILABILITY =
|
||||
"https://mock.apidog.com/m1/1053378-0-default/rest/v1/doctor_availability";
|
||||
"https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/doctor_availability";
|
||||
|
||||
function DoctorForm({ onSave, onCancel, formData, setFormData, isLoading }) {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
const { getAuthorizationHeader } = useAuth();
|
||||
const resolveAuthHeader = () => {
|
||||
try {
|
||||
const h = getAuthorizationHeader();
|
||||
return h || "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
const FormatTelefones = (valor) => {
|
||||
const digits = String(valor).replace(/\D/g, "").slice(0, 11);
|
||||
@ -54,7 +65,6 @@ function DoctorForm({ onSave, onCancel, formData, setFormData, isLoading }) {
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
const [avatarUrl, setAvatarUrl] = useState(null);
|
||||
const [showRequiredModal, setShowRequiredModal] = useState(false);
|
||||
const [emptyFields, setEmptyFields] = useState([]);
|
||||
@ -128,7 +138,9 @@ function DoctorForm({ onSave, onCancel, formData, setFormData, isLoading }) {
|
||||
|
||||
const handleAvailabilityUpdate = useCallback((newAvailability) => {
|
||||
setFormData((prev) => {
|
||||
if (JSON.stringify(prev.availability) !== JSON.stringify(newAvailability)) {
|
||||
if (
|
||||
JSON.stringify(prev.availability) !== JSON.stringify(newAvailability)
|
||||
) {
|
||||
return { ...prev, availability: newAvailability };
|
||||
}
|
||||
return prev;
|
||||
@ -213,23 +225,6 @@ const handleAvailabilityUpdate = useCallback((newAvailability) => {
|
||||
}
|
||||
}, 300);
|
||||
};
|
||||
const handleCreateAvailability = async (newAvailability) => {
|
||||
try {
|
||||
const response = await fetch(ENDPOINT_AVAILABILITY, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(newAvailability),
|
||||
});
|
||||
const data = await response.json();
|
||||
console.log("Disponibilidade criada :", data);
|
||||
alert("Disponibilidade criada com sucesso!");
|
||||
} catch (error) {
|
||||
console.error("Erro ao criar disponibilidade:", error);
|
||||
alert("Erro ao criar disponibilidade.");
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const missingFields = [];
|
||||
@ -270,23 +265,58 @@ const handleAvailabilityUpdate = useCallback((newAvailability) => {
|
||||
}
|
||||
|
||||
try {
|
||||
await onSave({ ...formData });
|
||||
const savedDoctor = await onSave({ ...formData });
|
||||
|
||||
if (formData.availability && formData.availability.length > 0) {
|
||||
const doctorId = savedDoctor?.id || formData.id;
|
||||
|
||||
if (
|
||||
doctorId &&
|
||||
formData.availability &&
|
||||
formData.availability.length > 0
|
||||
) {
|
||||
const availabilityData = formData.availability.map((item) => ({
|
||||
...item,
|
||||
doctor_id: doctorId,
|
||||
}));
|
||||
|
||||
const myHeaders = new Headers();
|
||||
const authHeader = resolveAuthHeader();
|
||||
if (authHeader) myHeaders.append("Authorization", authHeader);
|
||||
myHeaders.append("Content-Type", "application/json");
|
||||
if (API_KEY) myHeaders.append("apikey", API_KEY);
|
||||
|
||||
const availabilityResponse = await fetch(ENDPOINT_AVAILABILITY, {
|
||||
method: "POST",
|
||||
headers: myHeaders,
|
||||
body: JSON.stringify(availabilityData),
|
||||
});
|
||||
|
||||
if (availabilityResponse.ok) {
|
||||
console.log("Disponibilidade Salva/Atualizada com Sucesso.");
|
||||
} else {
|
||||
const errorText = await availabilityResponse.text();
|
||||
console.error(
|
||||
"Erro ao salvar disponibilidade:",
|
||||
availabilityResponse.status,
|
||||
errorText
|
||||
);
|
||||
alert(
|
||||
`Médico salvo, mas erro ao salvar horários de disponibilidade (Status: ${availabilityResponse.status})`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
alert("Médico salvo com sucesso!");
|
||||
} catch (error) {
|
||||
console.error("Erro ao salvar médico:", error);
|
||||
alert("Erro ao salvar médico.");
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const handleModalClose = () => {
|
||||
setShowRequiredModal(false);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Modal de Alerta */}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user