register form now has optional field role

This commit is contained in:
filipriec
2025-04-11 13:51:05 +02:00
parent 0fd2a589eb
commit cf1aa4fd2a
4 changed files with 26 additions and 7 deletions

View File

@@ -21,6 +21,7 @@ pub struct RegisterState {
pub email: String,
pub password: String,
pub password_confirmation: String,
pub role: String,
pub error_message: Option<String>,
pub current_field: usize,
pub current_cursor_pos: usize,
@@ -51,6 +52,7 @@ impl RegisterState {
email: String::new(),
password: String::new(),
password_confirmation: String::new(),
role: String::new(),
error_message: None,
current_field: 0,
current_cursor_pos: 0,
@@ -141,6 +143,7 @@ impl CanvasState for RegisterState {
1 => self.email.len(),
2 => self.password.len(),
3 => self.password_confirmation.len(),
4 => self.role.len(),
_ => 0,
};
self.current_cursor_pos.min(len)
@@ -156,6 +159,7 @@ impl CanvasState for RegisterState {
&self.email,
&self.password,
&self.password_confirmation,
&self.role,
]
}
@@ -165,6 +169,7 @@ impl CanvasState for RegisterState {
1 => &self.email,
2 => &self.password,
3 => &self.password_confirmation,
4 => &self.role,
_ => "",
}
}
@@ -175,6 +180,7 @@ impl CanvasState for RegisterState {
1 => &mut self.email,
2 => &mut self.password,
3 => &mut self.password_confirmation,
4 => &mut self.role,
_ => panic!("Invalid current_field index in RegisterState"),
}
}
@@ -185,17 +191,19 @@ impl CanvasState for RegisterState {
"Email (Optional)",
"Password (Optional)",
"Confirm Password",
"Role (Oprional)"
]
}
fn set_current_field(&mut self, index: usize) {
if index < 4 { // RegisterState has 4 fields
if index < 5 { // RegisterState has 5 fields
self.current_field = index;
let len = match self.current_field {
0 => self.username.len(),
1 => self.email.len(),
2 => self.password.len(),
3 => self.password_confirmation.len(),
4 => self.role.len(),
_ => 0,
};
self.current_cursor_pos = self.current_cursor_pos.min(len);
@@ -208,6 +216,7 @@ impl CanvasState for RegisterState {
1 => self.email.len(),
2 => self.password.len(),
3 => self.password_confirmation.len(),
4 => self.role.len(),
_ => 0,
};
self.current_cursor_pos = pos.min(len);