Ongoing adaptation to new backend structure

This commit is contained in:
Jose
2026-01-25 23:43:25 +01:00
parent 5f5d54d642
commit 59efb7d81f
31 changed files with 505 additions and 514 deletions

View File

@@ -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 : <strong>{usuario.member_number}</strong> | Huerto : <strong>{usuario.plot_number}</strong>
<FontAwesomeIcon icon={faHashtag} className="me-2" />Socio : <strong>{identity.metadata.memberNumber}</strong> | Huerto : <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({