Ongoing adaptation to new backend structure
This commit is contained in:
@@ -25,9 +25,9 @@ const Anuncios = () => {
|
||||
if (configLoading) return <p><LoadingIcon /></p>;
|
||||
|
||||
const reqConfig = {
|
||||
baseUrl: `${config.apiConfig.baseUrl}${config.apiConfig.endpoints.announces.all}`,
|
||||
baseUrl: `${config.apiConfig.baseUrl}${config.apiConfig.endpoints.announcements.all}`,
|
||||
params: {
|
||||
_sort: 'created_at',
|
||||
_sort: 'createdAt',
|
||||
_order: 'desc',
|
||||
},
|
||||
};
|
||||
@@ -61,7 +61,7 @@ const AnunciosContent = ({ reqConfig }) => {
|
||||
(filters.baja && anuncio.priority === 0) ||
|
||||
(filters.media && anuncio.priority === 1) ||
|
||||
(filters.alta && anuncio.priority === 2);
|
||||
const createdAt = new Date(anuncio.created_at);
|
||||
const createdAt = new Date(anuncio.createdAt);
|
||||
const now = new Date();
|
||||
const matchesFecha =
|
||||
(filters.ultimos7 && (now - createdAt) / (1000 * 60 * 60 * 24) <= 7) ||
|
||||
@@ -74,7 +74,7 @@ const AnunciosContent = ({ reqConfig }) => {
|
||||
const normalized = term.toLowerCase();
|
||||
return (
|
||||
anuncio.body?.toLowerCase().includes(normalized) ||
|
||||
anuncio.published_by_name?.toLowerCase().includes(normalized)
|
||||
anuncio.publishedByName?.toLowerCase().includes(normalized)
|
||||
);
|
||||
},
|
||||
initialFilters: {
|
||||
@@ -90,10 +90,10 @@ const AnunciosContent = ({ reqConfig }) => {
|
||||
const handleCreate = () => {
|
||||
setCreatingAnuncio(true);
|
||||
setTempAnuncio({
|
||||
announce_id: null,
|
||||
body: 'Nuevo anuncio',
|
||||
priority: 1,
|
||||
published_by_name: 'Admin',
|
||||
publishedBy: JSON.parse(localStorage.getItem("identity"))?.user?.displayName,
|
||||
createdAt: Date.now()
|
||||
});
|
||||
document.querySelector('.cards-grid')?.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
};
|
||||
@@ -162,12 +162,12 @@ const AnunciosContent = ({ reqConfig }) => {
|
||||
/>
|
||||
</EditorProvider>
|
||||
)}
|
||||
renderCard={(anuncio) => (
|
||||
renderCard={(anuncio, idx) => (
|
||||
<AnuncioCard
|
||||
key={anuncio.announce_id}
|
||||
anuncio={anuncio}
|
||||
key={anuncio.announceId}
|
||||
anuncio={{...anuncio, idx: idx}}
|
||||
onUpdate={(a, id) => handleEditSubmit(a, id)}
|
||||
onDelete={() => handleDelete(anuncio.announce_id)}
|
||||
onDelete={() => handleDelete(anuncio.announceId)}
|
||||
error={error}
|
||||
onClearError={() => setError(null)}
|
||||
/>
|
||||
|
||||
@@ -19,9 +19,8 @@ const Documentacion = () => {
|
||||
|
||||
const reqConfig = {
|
||||
baseUrl: config.apiConfig.coreUrl + config.apiConfig.endpoints.files.all,
|
||||
uploadUrl: config.apiConfig.coreUrl + config.apiConfig.endpoints.files.upload,
|
||||
params: {
|
||||
_sort: 'uploaded_at',
|
||||
_sort: 'uploadedAt',
|
||||
_order: 'desc'
|
||||
}
|
||||
};
|
||||
@@ -40,22 +39,22 @@ const DocumentacionContent = ({ reqConfig }) => {
|
||||
|
||||
const handleSelectFiles = async (files) => {
|
||||
const file = files[0];
|
||||
if (!file || !reqConfig?.uploadUrl) return;
|
||||
if (!file || !reqConfig?.baseUrl) return;
|
||||
|
||||
const file_name = file.name;
|
||||
const mime_type = file.type || "application/octet-stream";
|
||||
const uploaded_by = JSON.parse(localStorage.getItem("user"))?.user_id;
|
||||
const fileName = file.name;
|
||||
const mimeType = file.type || "application/octet-stream";
|
||||
const uploadedBy = JSON.parse(localStorage.getItem("identity"))?.user?.userId;
|
||||
const context = 1;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("file_name", file_name);
|
||||
formData.append("mime_type", mime_type);
|
||||
formData.append("uploaded_by", uploaded_by);
|
||||
formData.append("fileName", fileName);
|
||||
formData.append("mimeType", mimeType);
|
||||
formData.append("uploadedBy", uploadedBy);
|
||||
formData.append("context", context);
|
||||
|
||||
try {
|
||||
await postData(reqConfig.uploadUrl, formData);
|
||||
await postData(reqConfig.baseUrl, formData);
|
||||
fileUploadRef.current?.resetSelectedFiles();
|
||||
} catch (err) {
|
||||
console.error("Error al subir archivo:", err);
|
||||
@@ -100,8 +99,8 @@ const DocumentacionContent = ({ reqConfig }) => {
|
||||
variant="danger"
|
||||
onClick={async () => {
|
||||
try {
|
||||
await deleteDataWithBody(`${reqConfig.baseUrl}/${deleteTarget.file_id}`, {
|
||||
file_path: deleteTarget.file_path
|
||||
await deleteDataWithBody(`${reqConfig.baseUrl}/${deleteTarget.fileId}`, {
|
||||
filePath: deleteTarget.filePath
|
||||
});
|
||||
setDeleteTarget(null);
|
||||
} catch (err) {
|
||||
|
||||
@@ -30,7 +30,7 @@ const Gastos = () => {
|
||||
const reqConfig = {
|
||||
baseUrl: `${config.apiConfig.baseUrl}${config.apiConfig.endpoints.expenses.all}`,
|
||||
params: {
|
||||
_sort: 'created_at',
|
||||
_sort: 'createdAt',
|
||||
_order: 'desc',
|
||||
},
|
||||
};
|
||||
@@ -84,7 +84,7 @@ const GastosContent = ({ reqConfig }) => {
|
||||
const handleCreate = () => {
|
||||
setCreatingGasto(true);
|
||||
setTempGasto({
|
||||
expense_id: null,
|
||||
expenseId: null,
|
||||
concept: '',
|
||||
amount: 0.0,
|
||||
supplier: '',
|
||||
@@ -160,7 +160,7 @@ const GastosContent = ({ reqConfig }) => {
|
||||
)}
|
||||
renderCard={(gasto) => (
|
||||
<GastoCard
|
||||
key={gasto.expense_id}
|
||||
key={gasto.expenseId}
|
||||
gasto={gasto}
|
||||
onUpdate={handleEditSubmit}
|
||||
onDelete={handleDelete}
|
||||
|
||||
@@ -33,7 +33,7 @@ const Ingresos = () => {
|
||||
rawUrl: config.apiConfig.baseUrl + config.apiConfig.endpoints.incomes.all,
|
||||
membersUrl: config.apiConfig.baseUrl + config.apiConfig.endpoints.members.all,
|
||||
params: {
|
||||
_sort: 'created_at',
|
||||
_sort: 'createdAt',
|
||||
_order: 'desc'
|
||||
}
|
||||
};
|
||||
@@ -98,16 +98,16 @@ const IngresosContent = ({ reqConfig }) => {
|
||||
searchFn: (ingreso, term) => {
|
||||
const normalized = term.toLowerCase();
|
||||
return ingreso.concept?.toLowerCase().includes(normalized) ||
|
||||
String(ingreso.member_number).includes(normalized) ||
|
||||
ingreso.display_name?.toLowerCase().includes(normalized);
|
||||
String(ingreso.memberNumber).includes(normalized) ||
|
||||
ingreso.displayName?.toLowerCase().includes(normalized);
|
||||
}
|
||||
});
|
||||
|
||||
const handleCreate = () => {
|
||||
setCreatingIngreso(true);
|
||||
setTempIngreso({
|
||||
income_id: null,
|
||||
member_number: 0,
|
||||
incomeId: null,
|
||||
memberNumber: 0,
|
||||
concept: '',
|
||||
amount: 0.0,
|
||||
frequency: CONSTANTS.PAYMENT_FREQUENCY_YEARLY,
|
||||
@@ -183,10 +183,10 @@ const IngresosContent = ({ reqConfig }) => {
|
||||
)}
|
||||
renderCard={(income) => (
|
||||
<IngresoCard
|
||||
key={income.income_id}
|
||||
key={income.incomeId}
|
||||
income={income}
|
||||
onUpdate={(data, id) => handleEditSubmit(data, id)}
|
||||
onDelete={() => handleDelete(income.income_id)}
|
||||
onDelete={() => handleDelete(income.incomeId)}
|
||||
error={error}
|
||||
onClearError={() => setError(null)}
|
||||
/>
|
||||
|
||||
@@ -23,10 +23,10 @@ const ListaEspera = () => {
|
||||
if (configLoading) return <p><LoadingIcon /></p>;
|
||||
|
||||
const reqConfig = {
|
||||
baseUrl: config.apiConfig.baseUrl + config.apiConfig.endpoints.members.limitedWaitlist,
|
||||
baseUrl: config.apiConfig.baseUrl + config.apiConfig.endpoints.users.waitlistLimited,
|
||||
requestUrl: config.apiConfig.baseUrl + config.apiConfig.endpoints.requests.all,
|
||||
preUsersUrl: config.apiConfig.baseUrl + config.apiConfig.endpoints.pre_users.all,
|
||||
preUserValidationUrl: config.apiConfig.baseUrl + config.apiConfig.endpoints.pre_users.validation,
|
||||
preUsersUrl: config.apiConfig.baseUrl + config.apiConfig.endpoints.preUsers.all,
|
||||
preUserValidationUrl: config.apiConfig.baseUrl + config.apiConfig.endpoints.preUsers.validate,
|
||||
params: {}
|
||||
};
|
||||
|
||||
@@ -39,7 +39,7 @@ const ListaEspera = () => {
|
||||
|
||||
const ListaEsperaContent = ({ reqConfig }) => {
|
||||
const { authStatus } = useAuth();
|
||||
const { data, dataLoading, dataError, postDataValidated, postData } = useDataContext();
|
||||
const { data, dataLoading, dataError, postData, postDataValidated } = useDataContext();
|
||||
|
||||
const [showWelcomeModal, setShowWelcomeModal] = useState(false);
|
||||
const [showPreUserFormModal, setShowPreUserFormModal] = useState(false);
|
||||
@@ -64,27 +64,30 @@ const ListaEsperaContent = ({ reqConfig }) => {
|
||||
const handleRegisterSubmit = async (formData) => {
|
||||
setValidationErrors({});
|
||||
|
||||
const { _, errors } = await postDataValidated(reqConfig.preUserValidationUrl, formData);
|
||||
const validation = await postDataValidated(
|
||||
reqConfig.preUserValidationUrl,
|
||||
formData
|
||||
);
|
||||
|
||||
if (errors) {
|
||||
setValidationErrors(errors);
|
||||
if (!validation.ok) {
|
||||
setValidationErrors(validation.errors);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const request = await postData(reqConfig.requestUrl, { type: 0, status: 0 });
|
||||
const requestId = request?.request_id;
|
||||
const requestId = request?.requestId;
|
||||
if (!requestId) throw new Error("No se pudo registrar la solicitud.");
|
||||
|
||||
await postData(reqConfig.preUsersUrl, {
|
||||
...formData,
|
||||
request_id: requestId
|
||||
requestId
|
||||
});
|
||||
|
||||
setShowPreUserFormModal(false);
|
||||
setShowConfirmationModal(true);
|
||||
} catch (err) {
|
||||
setValidationErrors({ general: err.message });
|
||||
setValidationErrors({ general: "Error inesperado al enviar la solicitud" });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -94,13 +97,6 @@ const ListaEsperaContent = ({ reqConfig }) => {
|
||||
setShowPreUserFormModal(true);
|
||||
};
|
||||
|
||||
const mapped = [...(data ?? [])]
|
||||
.sort((a, b) => new Date(a.created_at) - new Date(b.created_at))
|
||||
.map((item) => ({
|
||||
...item,
|
||||
created_at: DateParser.timestampToString(item.created_at)
|
||||
}));
|
||||
|
||||
if (dataLoading) return <p className="text-center my-5"><LoadingIcon /></p>;
|
||||
if (dataError) return <p className="text-danger text-center my-5">{dataError}</p>;
|
||||
|
||||
@@ -117,7 +113,7 @@ const ListaEsperaContent = ({ reqConfig }) => {
|
||||
</IfNotAuthenticated>
|
||||
</div>
|
||||
<hr className="section-divider" />
|
||||
<List datos={mapped} config={{ title: 'display_name', subtitle: 'created_at', showIndex: true }} />
|
||||
<List datos={data} config={{ title: 'name', subtitle: '', showIndex: true }} />
|
||||
|
||||
{authStatus === 'unauthenticated' && (
|
||||
<Modal show={showWelcomeModal} onHide={() => setShowWelcomeModal(false)}>
|
||||
|
||||
@@ -66,12 +66,12 @@ const Perfil = () => {
|
||||
};
|
||||
|
||||
const reqConfig = {
|
||||
baseUrl: `${config.apiConfig.baseUrl}${config.apiConfig.endpoints.members.profile}`,
|
||||
myIncomesUrl: buildUrl(config.apiConfig.baseUrl, config.apiConfig.endpoints.incomes.myIncomes),
|
||||
baseUrl: `${config.apiConfig.baseUrl}${config.apiConfig.endpoints.users.me}`,
|
||||
myIncomesUrl: buildUrl(config.apiConfig.baseUrl, config.apiConfig.endpoints.incomes.mine),
|
||||
requestUrl: buildUrl(config.apiConfig.baseUrl, config.apiConfig.endpoints.requests.all),
|
||||
preUsersUrl: buildUrl(config.apiConfig.baseUrl, config.apiConfig.endpoints.pre_users.all),
|
||||
preUserValidationUrl: buildUrl(config.apiConfig.baseUrl, config.apiConfig.endpoints.pre_users.validation),
|
||||
myRequestsUrl: buildUrl(config.apiConfig.baseUrl, config.apiConfig.endpoints.requests.myRequests),
|
||||
preUsersUrl: buildUrl(config.apiConfig.baseUrl, config.apiConfig.endpoints.preUsers.all),
|
||||
preUserValidationUrl: buildUrl(config.apiConfig.baseUrl, config.apiConfig.endpoints.preUsers.validate),
|
||||
myRequestsUrl: buildUrl(config.apiConfig.baseUrl, config.apiConfig.endpoints.requests.mine),
|
||||
changePasswordUrl: buildUrl(config.apiConfig.coreUrl, config.apiConfig.endpoints.auth.changePassword),
|
||||
loginValidateUrl: buildUrl(config.apiConfig.coreUrl, config.apiConfig.endpoints.auth.loginValidate),
|
||||
};
|
||||
@@ -87,13 +87,13 @@ const PerfilContent = ({ config }) => {
|
||||
const { data, dataLoading, dataError, postData, postDataValidated } = useDataContext();
|
||||
const { logout } = useAuth();
|
||||
|
||||
const usuario = data?.member;
|
||||
const identity = JSON.parse(localStorage.getItem("identity"));
|
||||
const myRequests = data?.requests ?? [];
|
||||
const incomes = data?.payments ?? [];
|
||||
const hasCollaborator = data?.hasCollaborator ?? false;
|
||||
const hasCollaboratorRequest = data?.hasCollaboratorRequest ?? false;
|
||||
const hasGreenHouse = data?.hasGreenHouse ?? false;
|
||||
const hasGreenHouseRequest = data?.hasGreenHouseRequest ?? false;
|
||||
const hasGreenHouse = data?.hasGreenhouse ?? false;
|
||||
const hasGreenHouseRequest = data?.hasGreenhouseRequest ?? false;
|
||||
|
||||
const [showAddCollaboratorModal, setShowAddCollaboratorModal] = useState(false);
|
||||
const [showRemoveCollaboratorModal, setShowRemoveCollaboratorModal] = useState(false);
|
||||
@@ -117,7 +117,7 @@ const PerfilContent = ({ config }) => {
|
||||
await postData(config.requestUrl, {
|
||||
type: CONSTANTS.REQUEST_TYPE_UNREGISTER,
|
||||
status: CONSTANTS.REQUEST_PENDING,
|
||||
requested_by: usuario.user_id
|
||||
requestedBy: identity.user.userId
|
||||
});
|
||||
setFeedbackModal({
|
||||
title: 'Solicitud enviada',
|
||||
@@ -140,7 +140,7 @@ const PerfilContent = ({ config }) => {
|
||||
await postData(config.requestUrl, {
|
||||
type: CONSTANTS.REQUEST_TYPE_ADD_GREENHOUSE,
|
||||
status: CONSTANTS.REQUEST_PENDING,
|
||||
requested_by: usuario.user_id
|
||||
requestedBy: identity.user.userId
|
||||
});
|
||||
setFeedbackModal({
|
||||
title: 'Solicitud enviada',
|
||||
@@ -163,7 +163,7 @@ const PerfilContent = ({ config }) => {
|
||||
await postData(config.requestUrl, {
|
||||
type: CONSTANTS.REQUEST_TYPE_REMOVE_GREENHOUSE,
|
||||
status: CONSTANTS.REQUEST_PENDING,
|
||||
requested_by: usuario.user_id
|
||||
requestedBy: identity.user.userId
|
||||
});
|
||||
setFeedbackModal({
|
||||
title: 'Solicitud enviada',
|
||||
@@ -191,7 +191,7 @@ const PerfilContent = ({ config }) => {
|
||||
const handleChangePassword = async () => {
|
||||
try {
|
||||
const validOldPassword = await postData(config.loginValidateUrl, {
|
||||
userId: usuario.user_id,
|
||||
userId: identity.user.userId,
|
||||
password: newPasswordData.currentPassword
|
||||
});
|
||||
if (!validOldPassword.valid) throw new Error("La contraseña actual es incorrecta.");
|
||||
@@ -199,7 +199,7 @@ const PerfilContent = ({ config }) => {
|
||||
if (newPasswordData.newPassword.length < 8) throw new Error("La nueva contraseña debe tener al menos 8 caracteres.");
|
||||
|
||||
const response = await postData(config.changePasswordUrl, {
|
||||
userId: usuario.user_id,
|
||||
userId: identity.user.userId,
|
||||
newPassword: newPasswordData.newPassword
|
||||
});
|
||||
|
||||
@@ -231,9 +231,9 @@ const PerfilContent = ({ config }) => {
|
||||
|
||||
const mappedRequests = myRequests.map(r => ({
|
||||
...r,
|
||||
request_type: r.request_type ?? r.type,
|
||||
request_status: r.request_status ?? r.status,
|
||||
request_created_at: r.request_created_at ?? r.created_at
|
||||
type: r.type ?? r.type,
|
||||
status: r.status ?? r.status,
|
||||
request_createdAt: r.request_createdAt ?? r.createdAt
|
||||
}));
|
||||
|
||||
if (dataLoading) return <p className="text-center my-5"><LoadingIcon /></p>;
|
||||
@@ -247,10 +247,10 @@ const PerfilContent = ({ config }) => {
|
||||
<Card className="shadow-sm rounded-4 perfil-card">
|
||||
<Card.Header className="bg-secondary text-white rounded-top-4 d-flex align-items-center justify-content-between">
|
||||
<div className="d-flex align-items-center">
|
||||
<img src={getPFP(usuario.type)} alt="PFP" width={36} className="me-3" />
|
||||
<img src={getPFP(identity.metadata.type)} alt="PFP" width={36} className="me-3" />
|
||||
<div className="m-0 p-0">
|
||||
<Card.Title className="mb-0">{`@${usuario.user_name}`}</Card.Title>
|
||||
<small>Te uniste el {parseDate(usuario.created_at)}</small>
|
||||
<Card.Title className="mb-0">{`@${identity.account.username}`}</Card.Title>
|
||||
<small>Te uniste el {parseDate(identity.metadata.createdAt)}</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -293,21 +293,21 @@ const PerfilContent = ({ config }) => {
|
||||
|
||||
<Card.Body>
|
||||
<ListGroup variant="flush" className="border rounded-3">
|
||||
<ListGroup.Item><FontAwesomeIcon icon={faUser} className="me-2" />Nombre: <strong>{usuario.display_name}</strong></ListGroup.Item>
|
||||
<ListGroup.Item><FontAwesomeIcon icon={faIdCard} className="me-2" />DNI: <strong>{usuario.dni}</strong></ListGroup.Item>
|
||||
<ListGroup.Item><FontAwesomeIcon icon={faEnvelope} className="me-2" />Email: <strong>{usuario.email}</strong></ListGroup.Item>
|
||||
<ListGroup.Item><FontAwesomeIcon icon={faPhone} className="me-2" />Teléfono: <strong>{usuario.phone}</strong></ListGroup.Item>
|
||||
<ListGroup.Item><FontAwesomeIcon icon={faUser} className="me-2" />Nombre: <strong>{identity.user.displayName}</strong></ListGroup.Item>
|
||||
<ListGroup.Item><FontAwesomeIcon icon={faIdCard} className="me-2" />DNI: <strong>{identity.metadata.dni}</strong></ListGroup.Item>
|
||||
<ListGroup.Item><FontAwesomeIcon icon={faEnvelope} className="me-2" />Email: <strong>{identity.account.email}</strong></ListGroup.Item>
|
||||
<ListGroup.Item><FontAwesomeIcon icon={faPhone} className="me-2" />Teléfono: <strong>{identity.metadata.phone}</strong></ListGroup.Item>
|
||||
<ListGroup.Item>
|
||||
<FontAwesomeIcon icon={faHashtag} className="me-2" />Socio Nº: <strong>{usuario.member_number}</strong> | Huerto Nº: <strong>{usuario.plot_number}</strong>
|
||||
<FontAwesomeIcon icon={faHashtag} className="me-2" />Socio Nº: <strong>{identity.metadata.memberNumber}</strong> | Huerto Nº: <strong>{identity.metadata.plotNumber}</strong>
|
||||
</ListGroup.Item>
|
||||
<ListGroup.Item>
|
||||
<FontAwesomeIcon icon={faSeedling} className="me-2" />Tipo de socio: <strong>{['LISTA DE ESPERA', 'HORTELANO', 'HORTELANO + INVERNADERO', 'COLABORADOR', 'SUBVENCION', 'DESARROLLADOR'][usuario.type]}</strong>
|
||||
<FontAwesomeIcon icon={faSeedling} className="me-2" />Tipo de socio: <strong>{['LISTA DE ESPERA', 'HORTELANO', 'HORTELANO + INVERNADERO', 'COLABORADOR', 'SUBVENCION', 'DESARROLLADOR'][identity.metadata.type]}</strong>
|
||||
</ListGroup.Item>
|
||||
<ListGroup.Item>
|
||||
<FontAwesomeIcon icon={faUserShield} className="me-2" />Rol en huertos: <strong>{['USUARIO', 'ADMIN', 'DESARROLLADOR'][usuario.role]}</strong>
|
||||
<FontAwesomeIcon icon={faUserShield} className="me-2" />Rol en huertos: <strong>{['USUARIO', 'ADMIN', 'DESARROLLADOR'][identity.metadata.role]}</strong>
|
||||
</ListGroup.Item>
|
||||
<ListGroup.Item>
|
||||
<FontAwesomeIcon icon={faCalendar} className="me-2" />Estado: <strong>{usuario.status === 1 ? 'ACTIVO' : 'INACTIVO'}</strong>
|
||||
<FontAwesomeIcon icon={faCalendar} className="me-2" />Estado: <strong>{identity.account.status === 1 ? 'ACTIVO' : 'INACTIVO'}</strong>
|
||||
</ListGroup.Item>
|
||||
</ListGroup>
|
||||
</Card.Body>
|
||||
@@ -321,7 +321,7 @@ const PerfilContent = ({ config }) => {
|
||||
{incomes.length === 0 && <p className="text-center">No hay pagos registrados.</p>}
|
||||
<div className="d-flex flex-wrap gap-3 mb-4">
|
||||
{incomes.map(income => (
|
||||
<IngresoCard key={income.income_id} income={income} editable={false} />
|
||||
<IngresoCard key={income.incomeId} income={income} editable={false} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -331,7 +331,7 @@ const PerfilContent = ({ config }) => {
|
||||
|
||||
<div className="d-flex flex-wrap gap-3 mb-4">
|
||||
{mappedRequests.map(request => (
|
||||
<SolicitudCard key={request.request_id} data={request} editable={false} onProfile={true} />
|
||||
<SolicitudCard key={request.requestId} data={request} editable={false} onProfile={true} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -432,7 +432,7 @@ const PerfilContent = ({ config }) => {
|
||||
>
|
||||
<PreUserForm
|
||||
userType={3}
|
||||
plotNumber={usuario.plot_number}
|
||||
plotNumber={identity.metadata.plotNumber}
|
||||
errors={validationErrors}
|
||||
onSubmit={async (formData) => {
|
||||
setValidationErrors({});
|
||||
@@ -447,15 +447,15 @@ const PerfilContent = ({ config }) => {
|
||||
const request = await postData(config.requestUrl, {
|
||||
type: CONSTANTS.REQUEST_TYPE_ADD_COLLABORATOR,
|
||||
status: CONSTANTS.REQUEST_PENDING,
|
||||
requested_by: usuario.user_id
|
||||
requestedBy: identity.user.userId
|
||||
});
|
||||
|
||||
const requestId = request?.request_id;
|
||||
const requestId = request?.requestId;
|
||||
if (!requestId) throw new Error("No se pudo crear la solicitud.");
|
||||
|
||||
await postData(config.preUsersUrl, {
|
||||
...formData,
|
||||
request_id: requestId
|
||||
requestId: requestId
|
||||
});
|
||||
|
||||
setValidationErrors({});
|
||||
@@ -495,7 +495,7 @@ const PerfilContent = ({ config }) => {
|
||||
await postData(config.requestUrl, {
|
||||
type: CONSTANTS.REQUEST_TYPE_REMOVE_COLLABORATOR,
|
||||
status: CONSTANTS.REQUEST_PENDING,
|
||||
requested_by: usuario.user_id
|
||||
requestedBy: identity.user.userId
|
||||
});
|
||||
|
||||
setFeedbackModal({
|
||||
|
||||
@@ -28,11 +28,11 @@ const Socios = () => {
|
||||
if (configLoading || !config) return <p className="text-center my-5"><LoadingIcon /></p>;
|
||||
|
||||
const reqConfig = {
|
||||
baseUrl: `${config.apiConfig.baseUrl}${config.apiConfig.endpoints.members.all}`,
|
||||
incomesUrl: `${config.apiConfig.baseUrl}${config.apiConfig.endpoints.members.payments}`,
|
||||
baseUrl: `${config.apiConfig.baseUrl}${config.apiConfig.endpoints.users.all}`,
|
||||
incomesUrl: `${config.apiConfig.baseUrl}${config.apiConfig.endpoints.users.payments}`,
|
||||
rawIncomesUrl: `${config.apiConfig.baseUrl}${config.apiConfig.endpoints.incomes.all}`,
|
||||
params: {
|
||||
_sort: "member_number",
|
||||
_sort: "memberNumber",
|
||||
_order: "asc"
|
||||
}
|
||||
};
|
||||
@@ -67,24 +67,24 @@ const SociosContent = ({ reqConfig }) => {
|
||||
} = usePaginatedList({
|
||||
data,
|
||||
pageSize: PAGE_SIZE,
|
||||
filterFn: (socio, filters) => {
|
||||
filterFn: (identity, filters) => {
|
||||
if (filters.todos) return true;
|
||||
if (!filters.inactivos && socio.status === 0) return false;
|
||||
if (!filters.inactivos && identity.account.status === 0) return false;
|
||||
return (
|
||||
(filters.listaEspera && socio.type === 0) ||
|
||||
(filters.hortelanos && socio.type === 1) ||
|
||||
(filters.invernadero && socio.type === 2) ||
|
||||
(filters.colaboradores && socio.type === 3) ||
|
||||
(filters.inactivos && socio.status === 0)
|
||||
(filters.listaEspera && identity.metadata.type === 0) ||
|
||||
(filters.hortelanos && identity.metadata.type === 1) ||
|
||||
(filters.invernadero && identity.metadata.type === 2) ||
|
||||
(filters.colaboradores && identity.metadata.type === 3) ||
|
||||
(filters.inactivos && identity.account.status === 0)
|
||||
);
|
||||
},
|
||||
searchFn: (socio, term) => {
|
||||
searchFn: (identity, term) => {
|
||||
const normalized = term.toLowerCase();
|
||||
return (
|
||||
socio.display_name?.toLowerCase().includes(normalized) ||
|
||||
socio.dni?.toLowerCase().includes(normalized) ||
|
||||
String(socio.member_number).includes(normalized) ||
|
||||
String(socio.plot_number).includes(normalized)
|
||||
identity.user.displayName?.toLowerCase().includes(normalized) ||
|
||||
identity.metadata.dni?.toLowerCase().includes(normalized) ||
|
||||
String(identity.metadata.memberNumber).includes(normalized) ||
|
||||
String(identity.metadata.plotNumber).includes(normalized)
|
||||
);
|
||||
},
|
||||
initialFilters: {
|
||||
@@ -98,20 +98,20 @@ const SociosContent = ({ reqConfig }) => {
|
||||
});
|
||||
|
||||
const listaEsperaOrdenada = data ? data
|
||||
.filter(s => s.type === 0 && s.status !== 0)
|
||||
.sort((a, b) => new Date(a.created_at) - new Date(b.created_at)) : [];
|
||||
.filter(identity => identity.metadata.type === 0 && identity.account.status !== 0)
|
||||
.sort((a, b) => new Date(a.metadata.createdAt) - new Date(b.metadata.createdAt)) : [];
|
||||
|
||||
const handleCreate = () => {
|
||||
setCreatingSocio(true);
|
||||
const socio = {
|
||||
user_id: null,
|
||||
user_name: "nuevo" + Date.now(),
|
||||
userId: null,
|
||||
userName: "nuevo" + Date.now(),
|
||||
email: "",
|
||||
display_name: "Nuevo Socio",
|
||||
displayName: "Nuevo Socio",
|
||||
role: 0,
|
||||
global_status: 1,
|
||||
member_number: "",
|
||||
plot_number: "",
|
||||
globalStatus: 1,
|
||||
memberNumber: "",
|
||||
plotNumber: "",
|
||||
dni: "",
|
||||
phone: "",
|
||||
notes: "",
|
||||
@@ -130,7 +130,7 @@ const SociosContent = ({ reqConfig }) => {
|
||||
|
||||
const handleCreateSubmit = async (newSocio) => {
|
||||
try {
|
||||
newSocio.user_name = newSocio.display_name.split(" ")[0].toLowerCase() + newSocio.member_number;
|
||||
newSocio.userName = newSocio.displayName.split(" ")[0].toLowerCase() + newSocio.memberNumber;
|
||||
await postData(reqConfig.baseUrl, newSocio);
|
||||
setError(null);
|
||||
setCreatingSocio(false);
|
||||
@@ -162,7 +162,7 @@ const SociosContent = ({ reqConfig }) => {
|
||||
setIncomesError(null);
|
||||
|
||||
try {
|
||||
const url = reqConfig.incomesUrl.replace(":member_number", memberNumber);
|
||||
const url = reqConfig.incomesUrl.replace(":memberNumber", memberNumber);
|
||||
const res = await getData(url);
|
||||
setIncomes(res.data);
|
||||
} catch (err) {
|
||||
@@ -174,7 +174,7 @@ const SociosContent = ({ reqConfig }) => {
|
||||
|
||||
const handleIncomeUpdate = async (editado) => {
|
||||
try {
|
||||
await putData(`${reqConfig.rawIncomesUrl}/${editado.income_id}`, editado);
|
||||
await putData(`${reqConfig.rawIncomesUrl}/${editado.incomeId}`, editado);
|
||||
await handleViewIncomes(selectedMemberNumber);
|
||||
} catch (err) {
|
||||
console.error("Error actualizando ingreso:", err);
|
||||
@@ -219,17 +219,17 @@ const SociosContent = ({ reqConfig }) => {
|
||||
)}
|
||||
renderCard={(socio) => {
|
||||
const position = socio.type === 0
|
||||
? listaEsperaOrdenada.findIndex(s => s.user_id === socio.user_id) + 1
|
||||
? listaEsperaOrdenada.findIndex(s => s.userId === socio.userId) + 1
|
||||
: null;
|
||||
|
||||
return (
|
||||
<SocioCard
|
||||
key={socio.user_id}
|
||||
key={socio.userId}
|
||||
socio={socio}
|
||||
onUpdate={handleEditSubmit}
|
||||
onDelete={handleDelete}
|
||||
onCancel={handleCancelCreate}
|
||||
onViewIncomes={() => handleViewIncomes(socio.member_number)}
|
||||
onViewIncomes={() => handleViewIncomes(socio.memberNumber)}
|
||||
error={error}
|
||||
onClearError={() => setError(null)}
|
||||
positionIfWaitlist={position}
|
||||
@@ -256,7 +256,7 @@ const SociosContent = ({ reqConfig }) => {
|
||||
)}
|
||||
<div className="d-flex flex-wrap gap-3 p-3 justify-content-start">
|
||||
{incomes.map((income) => (
|
||||
<IngresoCard key={income.income_id} income={income}
|
||||
<IngresoCard key={income.incomeId} income={income}
|
||||
onUpdate={handleIncomeUpdate} className='from-members' />
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -49,30 +49,28 @@ const SolicitudesContent = ({ reqConfig }) => {
|
||||
searchFn: (entry, term) => {
|
||||
const normalized = term.toLowerCase();
|
||||
return (
|
||||
entry.pre_display_name?.toLowerCase().includes(normalized) ||
|
||||
entry.pre_dni?.toLowerCase().includes(normalized) ||
|
||||
entry.pre_email?.toLowerCase().includes(normalized) ||
|
||||
String(entry.pre_phone).includes(normalized)
|
||||
entry.preDisplayName?.toLowerCase().includes(normalized) ||
|
||||
entry.preDni?.toLowerCase().includes(normalized) ||
|
||||
entry.preEmail?.toLowerCase().includes(normalized) ||
|
||||
String(entry.prePhone).includes(normalized)
|
||||
);
|
||||
},
|
||||
sortFn: (a, b) => a.request_status - b.request_status
|
||||
sortFn: (a, b) => a.status - b.status
|
||||
});
|
||||
|
||||
const handleAccept = async (entry) => {
|
||||
const url = reqConfig.acceptUrl.replace(":request_id", entry.request_id);
|
||||
const url = reqConfig.acceptUrl.replace(":requestId", entry.requestId);
|
||||
try {
|
||||
await putData(url, {});
|
||||
console.log("✅ Solicitud aceptada:", entry.request_id);
|
||||
} catch (err) {
|
||||
console.error("❌ Error al aceptar solicitud:", err.message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleReject = async (entry) => {
|
||||
const url = reqConfig.rejectUrl.replace(":request_id", entry.request_id);
|
||||
const url = reqConfig.rejectUrl.replace(":requestId", entry.requestId);
|
||||
try {
|
||||
await putData(url, {});
|
||||
console.log("🛑 Solicitud rechazada:", entry.request_id);
|
||||
} catch (err) {
|
||||
console.error("❌ Error al rechazar solicitud:", err.message);
|
||||
}
|
||||
@@ -107,7 +105,7 @@ const SolicitudesContent = ({ reqConfig }) => {
|
||||
items={filtered}
|
||||
renderCard={(entry) => (
|
||||
<SolicitudCard
|
||||
key={entry.request_id}
|
||||
key={entry.requestId}
|
||||
data={entry}
|
||||
onAccept={() => handleAccept(entry)}
|
||||
onReject={() => handleReject(entry)}
|
||||
|
||||
Reference in New Issue
Block a user