84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import { ViewModel } from "../../contracts/view-models/ViewModel";
|
|
import type { ResetPasswordFormState, ResetPasswordUIState } from "./ResetPasswordInterfaces";
|
|
|
|
/**
|
|
* Reset Password ViewModel
|
|
*
|
|
* Client-side state management for reset password flow.
|
|
* Immutable, class-based, contains only UI state.
|
|
*/
|
|
export class ResetPasswordViewModel extends ViewModel {
|
|
constructor(
|
|
public readonly token: string,
|
|
public readonly returnTo: string,
|
|
public readonly formState: ResetPasswordFormState,
|
|
public readonly uiState: ResetPasswordUIState,
|
|
public readonly showSuccess: boolean = false,
|
|
public readonly successMessage: string | null = null,
|
|
public readonly mutationPending: boolean = false,
|
|
public readonly mutationError: string | null = null
|
|
) {
|
|
super();
|
|
}
|
|
|
|
withFormState(formState: ResetPasswordFormState): ResetPasswordViewModel {
|
|
return new ResetPasswordViewModel(
|
|
this.token,
|
|
this.returnTo,
|
|
formState,
|
|
this.uiState,
|
|
this.showSuccess,
|
|
this.successMessage,
|
|
this.mutationPending,
|
|
this.mutationError
|
|
);
|
|
}
|
|
|
|
withUIState(uiState: ResetPasswordUIState): ResetPasswordViewModel {
|
|
return new ResetPasswordViewModel(
|
|
this.token,
|
|
this.returnTo,
|
|
this.formState,
|
|
uiState,
|
|
this.showSuccess,
|
|
this.successMessage,
|
|
this.mutationPending,
|
|
this.mutationError
|
|
);
|
|
}
|
|
|
|
withSuccess(successMessage: string): ResetPasswordViewModel {
|
|
return new ResetPasswordViewModel(
|
|
this.token,
|
|
this.returnTo,
|
|
this.formState,
|
|
this.uiState,
|
|
true,
|
|
successMessage,
|
|
false,
|
|
null
|
|
);
|
|
}
|
|
|
|
withMutationState(pending: boolean, error: string | null): ResetPasswordViewModel {
|
|
return new ResetPasswordViewModel(
|
|
this.token,
|
|
this.returnTo,
|
|
this.formState,
|
|
this.uiState,
|
|
this.showSuccess,
|
|
this.successMessage,
|
|
pending,
|
|
error
|
|
);
|
|
}
|
|
|
|
get isSubmitting(): boolean {
|
|
return this.formState.isSubmitting || this.mutationPending;
|
|
}
|
|
|
|
get submitError(): string | undefined {
|
|
return this.formState.submitError || this.mutationError || undefined;
|
|
}
|
|
}
|