Fix: auto refreshing on requesting member number in some cards in prod.
This commit is contained in:
@@ -54,11 +54,11 @@ function App() {
|
|||||||
<Balance />
|
<Balance />
|
||||||
</ProtectedRoute>
|
</ProtectedRoute>
|
||||||
} />
|
} />
|
||||||
<Route path="/documentacion" element={
|
{/*<Route path="/documentacion" element={
|
||||||
<ProtectedRoute>
|
<ProtectedRoute>
|
||||||
<Documentacion />
|
<Documentacion />
|
||||||
</ProtectedRoute>
|
</ProtectedRoute>
|
||||||
} />
|
} />*/}
|
||||||
<Route path="/anuncios" element={
|
<Route path="/anuncios" element={
|
||||||
<ProtectedRoute>
|
<ProtectedRoute>
|
||||||
<Anuncios />
|
<Anuncios />
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ const NavBar = () => {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<Navbar expand="lg" sticky="top" expanded={expanded} onToggle={() => setExpanded(!expanded)}>
|
<Navbar expand="lg" sticky="top" expanded={expanded} onToggle={() => setExpanded(!expanded)}>
|
||||||
<Container fluid>
|
<Container fluid>
|
||||||
<Navbar.Toggle aria-controls="navbar" className="custom-toggler">
|
<Navbar.Toggle aria-controls="navbar" className="custom-toggler">
|
||||||
@@ -103,17 +104,20 @@ const NavBar = () => {
|
|||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faBullhorn} className="me-2" />Anuncios
|
<FontAwesomeIcon icon={faBullhorn} className="me-2" />Anuncios
|
||||||
</Nav.Link>
|
</Nav.Link>
|
||||||
|
</IfAuthenticated>
|
||||||
|
|
||||||
<Nav.Link
|
<Nav.Link
|
||||||
as={Link}
|
as={Link}
|
||||||
to="/documentacion"
|
to="#" // /documentacion
|
||||||
title="Documentación"
|
title="Documentación"
|
||||||
className={`text-truncate ${expanded ? "mt-3" : ""}`}
|
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
|
<FontAwesomeIcon icon={faFile} className="me-2" />Documentación
|
||||||
</Nav.Link>
|
</Nav.Link>
|
||||||
</IfAuthenticated>
|
|
||||||
|
|
||||||
<IfRole roles={[CONSTANTS.ROLE_ADMIN, CONSTANTS.ROLE_DEV]}>
|
<IfRole roles={[CONSTANTS.ROLE_ADMIN, CONSTANTS.ROLE_DEV]}>
|
||||||
<NavGestion onNavigate={() => setExpanded(false)} externalExpanded={expanded} />
|
<NavGestion onNavigate={() => setExpanded(false)} externalExpanded={expanded} />
|
||||||
@@ -163,6 +167,7 @@ const NavBar = () => {
|
|||||||
</Nav>
|
</Nav>
|
||||||
</Container>
|
</Container>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,9 @@ const SocioCard = ({ identity, isNew = false, onCreate, onUpdate, onDelete, onCa
|
|||||||
try {
|
try {
|
||||||
if (!(createMode || editMode)) return;
|
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;
|
const nuevoNumero = latestNumber + 1;
|
||||||
setLatestNumber(nuevoNumero);
|
setLatestNumber(nuevoNumero);
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ const NewUserForm = ({ onSubmit, userType, plotNumber, fieldErrors }) => {
|
|||||||
fetchedOnce.current = true;
|
fetchedOnce.current = true;
|
||||||
|
|
||||||
try {
|
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) => ({
|
setForm((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
memberNumber: latestNumber + 1
|
memberNumber: latestNumber + 1
|
||||||
|
|||||||
@@ -13,13 +13,17 @@ export const useData = (config, onError) => {
|
|||||||
}
|
}
|
||||||
}, [config]);
|
}, [config]);
|
||||||
|
|
||||||
const getAuthHeaders = () => {
|
const getAuthHeaders = (isFormData = false) => {
|
||||||
const token = localStorage.getItem("token");
|
const token = localStorage.getItem("token");
|
||||||
if (!token) return { "Content-Type": "application/json" };
|
|
||||||
return {
|
const headers = {};
|
||||||
"Content-Type": "application/json",
|
if (token) headers.Authorization = `Bearer ${token}`;
|
||||||
"Authorization": `Bearer ${token}`,
|
|
||||||
};
|
if (!isFormData) {
|
||||||
|
headers["Content-Type"] = "application/json";
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAxiosError = (err) => {
|
const handleAxiosError = (err) => {
|
||||||
@@ -90,7 +94,8 @@ export const useData = (config, onError) => {
|
|||||||
|
|
||||||
const requestWrapper = async (method, endpoint, payload = null, refresh = false) => {
|
const requestWrapper = async (method, endpoint, payload = null, refresh = false) => {
|
||||||
try {
|
try {
|
||||||
const headers = getAuthHeaders();
|
const isFormData = payload instanceof FormData;
|
||||||
|
const headers = getAuthHeaders(isFormData);
|
||||||
const cfg = { headers };
|
const cfg = { headers };
|
||||||
let response;
|
let response;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user