register form now has optional field role
This commit is contained in:
@@ -39,7 +39,7 @@ pub fn render_register(
|
|||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Length(6), // Form (4 fields + padding)
|
Constraint::Length(7), // Form (5 fields + padding)
|
||||||
Constraint::Length(1), // Error message
|
Constraint::Length(1), // Error message
|
||||||
Constraint::Length(3), // Buttons
|
Constraint::Length(3), // Buttons
|
||||||
])
|
])
|
||||||
@@ -55,6 +55,7 @@ pub fn render_register(
|
|||||||
"Email (Optional)",
|
"Email (Optional)",
|
||||||
"Password (Optional)",
|
"Password (Optional)",
|
||||||
"Confirm Password",
|
"Confirm Password",
|
||||||
|
"Role (Optional)",
|
||||||
],
|
],
|
||||||
&state.current_field,
|
&state.current_field,
|
||||||
&[ // Update values from RegisterState
|
&[ // Update values from RegisterState
|
||||||
@@ -62,6 +63,7 @@ pub fn render_register(
|
|||||||
&state.email,
|
&state.email,
|
||||||
&state.password,
|
&state.password,
|
||||||
&state.password_confirmation,
|
&state.password_confirmation,
|
||||||
|
&state.role,
|
||||||
],
|
],
|
||||||
theme,
|
theme,
|
||||||
is_edit_mode,
|
is_edit_mode,
|
||||||
|
|||||||
@@ -28,14 +28,16 @@ impl AuthClient {
|
|||||||
&mut self,
|
&mut self,
|
||||||
username: String,
|
username: String,
|
||||||
email: String,
|
email: String,
|
||||||
password: Option<String>, // Use Option for optional fields
|
password: Option<String>,
|
||||||
password_confirmation: Option<String>, // Use Option for optional fields
|
password_confirmation: Option<String>,
|
||||||
|
role: Option<String>,
|
||||||
) -> Result<AuthResponse, Box<dyn std::error::Error>> {
|
) -> Result<AuthResponse, Box<dyn std::error::Error>> {
|
||||||
let request = tonic::Request::new(RegisterRequest {
|
let request = tonic::Request::new(RegisterRequest {
|
||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
password: password.unwrap_or_default(), // Send empty string if None
|
password: password.unwrap_or_default(),
|
||||||
password_confirmation: password_confirmation.unwrap_or_default(), // Send empty string if None
|
password_confirmation: password_confirmation.unwrap_or_default(),
|
||||||
|
role: role.unwrap_or_default(),
|
||||||
});
|
});
|
||||||
let response = self.client.register(request).await?.into_inner();
|
let response = self.client.register(request).await?.into_inner();
|
||||||
Ok(response)
|
Ok(response)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ pub struct RegisterState {
|
|||||||
pub email: String,
|
pub email: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
pub password_confirmation: String,
|
pub password_confirmation: String,
|
||||||
|
pub role: String,
|
||||||
pub error_message: Option<String>,
|
pub error_message: Option<String>,
|
||||||
pub current_field: usize,
|
pub current_field: usize,
|
||||||
pub current_cursor_pos: usize,
|
pub current_cursor_pos: usize,
|
||||||
@@ -51,6 +52,7 @@ impl RegisterState {
|
|||||||
email: String::new(),
|
email: String::new(),
|
||||||
password: String::new(),
|
password: String::new(),
|
||||||
password_confirmation: String::new(),
|
password_confirmation: String::new(),
|
||||||
|
role: String::new(),
|
||||||
error_message: None,
|
error_message: None,
|
||||||
current_field: 0,
|
current_field: 0,
|
||||||
current_cursor_pos: 0,
|
current_cursor_pos: 0,
|
||||||
@@ -141,6 +143,7 @@ impl CanvasState for RegisterState {
|
|||||||
1 => self.email.len(),
|
1 => self.email.len(),
|
||||||
2 => self.password.len(),
|
2 => self.password.len(),
|
||||||
3 => self.password_confirmation.len(),
|
3 => self.password_confirmation.len(),
|
||||||
|
4 => self.role.len(),
|
||||||
_ => 0,
|
_ => 0,
|
||||||
};
|
};
|
||||||
self.current_cursor_pos.min(len)
|
self.current_cursor_pos.min(len)
|
||||||
@@ -156,6 +159,7 @@ impl CanvasState for RegisterState {
|
|||||||
&self.email,
|
&self.email,
|
||||||
&self.password,
|
&self.password,
|
||||||
&self.password_confirmation,
|
&self.password_confirmation,
|
||||||
|
&self.role,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +169,7 @@ impl CanvasState for RegisterState {
|
|||||||
1 => &self.email,
|
1 => &self.email,
|
||||||
2 => &self.password,
|
2 => &self.password,
|
||||||
3 => &self.password_confirmation,
|
3 => &self.password_confirmation,
|
||||||
|
4 => &self.role,
|
||||||
_ => "",
|
_ => "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,6 +180,7 @@ impl CanvasState for RegisterState {
|
|||||||
1 => &mut self.email,
|
1 => &mut self.email,
|
||||||
2 => &mut self.password,
|
2 => &mut self.password,
|
||||||
3 => &mut self.password_confirmation,
|
3 => &mut self.password_confirmation,
|
||||||
|
4 => &mut self.role,
|
||||||
_ => panic!("Invalid current_field index in RegisterState"),
|
_ => panic!("Invalid current_field index in RegisterState"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,17 +191,19 @@ impl CanvasState for RegisterState {
|
|||||||
"Email (Optional)",
|
"Email (Optional)",
|
||||||
"Password (Optional)",
|
"Password (Optional)",
|
||||||
"Confirm Password",
|
"Confirm Password",
|
||||||
|
"Role (Oprional)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_current_field(&mut self, index: usize) {
|
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;
|
self.current_field = index;
|
||||||
let len = match self.current_field {
|
let len = match self.current_field {
|
||||||
0 => self.username.len(),
|
0 => self.username.len(),
|
||||||
1 => self.email.len(),
|
1 => self.email.len(),
|
||||||
2 => self.password.len(),
|
2 => self.password.len(),
|
||||||
3 => self.password_confirmation.len(),
|
3 => self.password_confirmation.len(),
|
||||||
|
4 => self.role.len(),
|
||||||
_ => 0,
|
_ => 0,
|
||||||
};
|
};
|
||||||
self.current_cursor_pos = self.current_cursor_pos.min(len);
|
self.current_cursor_pos = self.current_cursor_pos.min(len);
|
||||||
@@ -208,6 +216,7 @@ impl CanvasState for RegisterState {
|
|||||||
1 => self.email.len(),
|
1 => self.email.len(),
|
||||||
2 => self.password.len(),
|
2 => self.password.len(),
|
||||||
3 => self.password_confirmation.len(),
|
3 => self.password_confirmation.len(),
|
||||||
|
4 => self.role.len(),
|
||||||
_ => 0,
|
_ => 0,
|
||||||
};
|
};
|
||||||
self.current_cursor_pos = pos.min(len);
|
self.current_cursor_pos = pos.min(len);
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ pub async fn save(
|
|||||||
} else {
|
} else {
|
||||||
Some(register_state.password_confirmation.clone())
|
Some(register_state.password_confirmation.clone())
|
||||||
};
|
};
|
||||||
|
let role = if register_state.role.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(register_state.role.clone())
|
||||||
|
};
|
||||||
|
|
||||||
// Basic client-side validation (example)
|
// Basic client-side validation (example)
|
||||||
if username.is_empty() {
|
if username.is_empty() {
|
||||||
@@ -59,7 +64,7 @@ pub async fn save(
|
|||||||
app_state.hide_dialog();
|
app_state.hide_dialog();
|
||||||
|
|
||||||
// Call the gRPC register method
|
// Call the gRPC register method
|
||||||
match auth_client.register(username, email, password, password_confirmation).await {
|
match auth_client.register(username, email, password, password_confirmation, role).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
// Clear fields on success? Optional, maybe wait for dialog confirmation.
|
// Clear fields on success? Optional, maybe wait for dialog confirmation.
|
||||||
// register_state.username.clear();
|
// register_state.username.clear();
|
||||||
@@ -117,6 +122,7 @@ pub async fn revert(
|
|||||||
register_state.email.clear();
|
register_state.email.clear();
|
||||||
register_state.password.clear();
|
register_state.password.clear();
|
||||||
register_state.password_confirmation.clear();
|
register_state.password_confirmation.clear();
|
||||||
|
register_state.role.clear();
|
||||||
register_state.error_message = None;
|
register_state.error_message = None;
|
||||||
register_state.set_has_unsaved_changes(false);
|
register_state.set_has_unsaved_changes(false);
|
||||||
register_state.current_field = 0; // Reset focus to first field
|
register_state.current_field = 0; // Reset focus to first field
|
||||||
|
|||||||
Reference in New Issue
Block a user