Fix: auto refreshing on requesting member number in some cards in prod.

This commit is contained in:
Jose
2026-01-31 14:25:33 +01:00
parent f426b8e34e
commit 3c7de7e71d
5 changed files with 116 additions and 102 deletions

View File

@@ -54,11 +54,11 @@ function App() {
<Balance />
</ProtectedRoute>
} />
<Route path="/documentacion" element={
{/*<Route path="/documentacion" element={
<ProtectedRoute>
<Documentacion />
</ProtectedRoute>
} />
} />*/}
<Route path="/anuncios" element={
<ProtectedRoute>
<Anuncios />

View File

@@ -55,6 +55,7 @@ const NavBar = () => {
return (
<>
<Navbar expand="lg" sticky="top" expanded={expanded} onToggle={() => setExpanded(!expanded)}>
<Container fluid>
<Navbar.Toggle aria-controls="navbar" className="custom-toggler">
@@ -103,17 +104,20 @@ const NavBar = () => {
>
<FontAwesomeIcon icon={faBullhorn} className="me-2" />Anuncios
</Nav.Link>
</IfAuthenticated>
<Nav.Link
as={Link}
to="/documentacion"
to="#" // /documentacion
title="Documentación"
className={`text-truncate ${expanded ? "mt-3" : ""}`}
onClick={() => setExpanded(false)}
onClick={() => {
window.open("https://miarma.net/files/huertos/", "_blank");
setExpanded(false);
}}
>
<FontAwesomeIcon icon={faFile} className="me-2" />Documentación
</Nav.Link>
</IfAuthenticated>
<IfRole roles={[CONSTANTS.ROLE_ADMIN, CONSTANTS.ROLE_DEV]}>
<NavGestion onNavigate={() => setExpanded(false)} externalExpanded={expanded} />
@@ -163,6 +167,7 @@ const NavBar = () => {
</Nav>
</Container>
</Navbar>
</>
);
};

View File

@@ -145,7 +145,9 @@ const SocioCard = ({ identity, isNew = false, onCreate, onUpdate, onDelete, onCa
try {
if (!(createMode || editMode)) return;
const latestNumber = await getData("http://localhost:8081/v2/huertos/users/latest-number", {}, false);
const latestNumber = import.meta.env.MODE === 'production' ?
await getData("https://api.miarma.net/v2/huertos/users/latest-number", {}, false)
: await getData("http://localhost:8081/v2/huertos/users/latest-number", {}, false);
const nuevoNumero = latestNumber + 1;
setLatestNumber(nuevoNumero);

View File

@@ -27,7 +27,9 @@ const NewUserForm = ({ onSubmit, userType, plotNumber, fieldErrors }) => {
fetchedOnce.current = true;
try {
const latestNumber = await getData("http://localhost:8081/v2/huertos/users/latest-number", {}, false);
const latestNumber = import.meta.env.MODE === 'production' ?
await getData("https://api.miarma.net/v2/huertos/users/latest-number", {}, false)
: await getData("http://localhost:8081/v2/huertos/users/latest-number", {}, false);
setForm((prev) => ({
...prev,
memberNumber: latestNumber + 1

View File

@@ -13,13 +13,17 @@ export const useData = (config, onError) => {
}
}, [config]);
const getAuthHeaders = () => {
const getAuthHeaders = (isFormData = false) => {
const token = localStorage.getItem("token");
if (!token) return { "Content-Type": "application/json" };
return {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
};
const headers = {};
if (token) headers.Authorization = `Bearer ${token}`;
if (!isFormData) {
headers["Content-Type"] = "application/json";
}
return headers;
};
const handleAxiosError = (err) => {
@@ -90,7 +94,8 @@ export const useData = (config, onError) => {
const requestWrapper = async (method, endpoint, payload = null, refresh = false) => {
try {
const headers = getAuthHeaders();
const isFormData = payload instanceof FormData;
const headers = getAuthHeaders(isFormData);
const cfg = { headers };
let response;