FactuGES_ERP/modules/identity/src/web/login/controllers/use-login-controller.ts
david 78bb02f9b0 feat: Implement Sequelize mappers and repository for Proforma V2
- Added SequelizeProformaV2RecipientDomainMapper for mapping recipient data to domain model.
- Introduced SequelizeProformaV2TaxesDomainMapper for handling tax data mapping.
- Created SequelizeProformaV2RecipientSummaryMapper for summarizing recipient information.
- Developed SequelizeProformaV2SummaryMapper for mapping Proforma summary data.
- Implemented SequelizeProformaRepositoryV2 for managing Proforma data persistence.
- Added SequelizeProformaV2NumberGenerator for generating Proforma numbers.
2026-07-10 13:59:44 +02:00

49 lines
1.1 KiB
TypeScript

import { useHookForm } from "@erp/core/hooks";
import { useIdentityAuthSession } from "../../context";
import type { IdentityAuthError } from "../../shared/entities";
import { type LoginForm, LoginFormSchema } from "../entities";
function getLoginErrorMessage(error: unknown) {
const status = (error as IdentityAuthError | undefined)?.status;
if (status === 401) {
return "Email o contraseña no válidos.";
}
if (status === 400) {
return "Revisa los datos introducidos.";
}
return "No se ha podido iniciar sesión. Inténtalo de nuevo.";
}
export function useLoginController() {
const { login } = useIdentityAuthSession();
const form = useHookForm<LoginForm>({
resolverSchema: LoginFormSchema,
initialValues: {
email: "admin@local.test",
password: "password",
},
});
const handleSubmit = form.handleSubmit(async (values) => {
form.clearErrors("root");
try {
await login(values);
} catch (error) {
form.setError("root", {
message: getLoginErrorMessage(error),
});
}
});
return {
form,
handleSubmit,
};
}