website refactor
This commit is contained in:
61
apps/website/lib/builders/view-data/LoginViewDataBuilder.ts
Normal file
61
apps/website/lib/builders/view-data/LoginViewDataBuilder.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Login View Data Builder
|
||||
*
|
||||
* Transforms LoginPageDTO into ViewData for the login template.
|
||||
* Deterministic, side-effect free, no business logic.
|
||||
*/
|
||||
|
||||
import { LoginPageDTO } from '@/lib/services/auth/types/LoginPageDTO';
|
||||
|
||||
export interface FormFieldState {
|
||||
value: string | boolean;
|
||||
error?: string;
|
||||
touched: boolean;
|
||||
validating: boolean;
|
||||
}
|
||||
|
||||
export interface FormState {
|
||||
fields: {
|
||||
email: FormFieldState;
|
||||
password: FormFieldState;
|
||||
rememberMe: FormFieldState;
|
||||
};
|
||||
isValid: boolean;
|
||||
isSubmitting: boolean;
|
||||
submitError?: string;
|
||||
submitCount: number;
|
||||
}
|
||||
|
||||
export interface LoginViewData {
|
||||
returnTo: string;
|
||||
hasInsufficientPermissions: boolean;
|
||||
showPassword: boolean;
|
||||
showErrorDetails: boolean;
|
||||
formState: FormState;
|
||||
isSubmitting: boolean;
|
||||
submitError?: string;
|
||||
}
|
||||
|
||||
export class LoginViewDataBuilder {
|
||||
static build(data: LoginPageDTO): LoginViewData {
|
||||
return {
|
||||
returnTo: data.returnTo,
|
||||
hasInsufficientPermissions: data.hasInsufficientPermissions,
|
||||
showPassword: false,
|
||||
showErrorDetails: false,
|
||||
formState: {
|
||||
fields: {
|
||||
email: { value: '', error: undefined, touched: false, validating: false },
|
||||
password: { value: '', error: undefined, touched: false, validating: false },
|
||||
rememberMe: { value: false, error: undefined, touched: false, validating: false },
|
||||
},
|
||||
isValid: true,
|
||||
isSubmitting: false,
|
||||
submitError: undefined,
|
||||
submitCount: 0,
|
||||
},
|
||||
isSubmitting: false,
|
||||
submitError: undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user