Skip to content

Forms signup improvements 1#244

Open
hydra wants to merge 10 commits into
khonsulabs:mainfrom
hydra:forms-signup-improvements-1
Open

Forms signup improvements 1#244
hydra wants to merge 10 commits into
khonsulabs:mainfrom
hydra:forms-signup-improvements-1

Conversation

@hydra

@hydra hydra commented Feb 4, 2025

Copy link
Copy Markdown
Contributor

See individual commit messages.

Based on feedback in discord: https://discord.com/channels/578968877866811403/1334602387750518806/1336400179783536651

hydra added 8 commits February 4, 2025 21:48
…entation.

* potentially, you could have a pre-filled sign-up form where `SignupForm::default` wouldn't be used, but the process of building a form should be the same.
… in tuples or individually.

* where variables are frequently/always used together it indicates a structure should be used to hold them.
@hydra
hydra force-pushed the forms-signup-improvements-1 branch from f53bde2 to 04eef7f Compare February 4, 2025 21:24
hydra added 2 commits February 5, 2025 22:43
…ors are always notified.

* If `set` is used, and a newly calculated `mapped_errors` is exactly the same as the last time they were calculated, then subscribers are not notified resulting in incorrect form behavior because `set` uses `PartialEq` on the value before notifying subscribers.  This manifests in a bug where the UI shows no error messages when the API is used.

To re-create the issue, use a value for the username which generates an API error, then in the UI clear the field, then enter the same value again and re-submit, no error was shown on the second submit even though there was an API error.
@hydra

hydra commented Feb 5, 2025

Copy link
Copy Markdown
Contributor Author

Fixed #245 by using force_set from #242, see 4a05ed1

Comment thread Cargo.toml
parking_lot = "0.12.1"
easing-function = "0.1.1"
serde = { version = "1.0.210", features = ["derive"], optional = true }
regex = "1.11.1"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependencies should not be added specifically for examples.

Comment thread examples/forms-signup.rs
.persist();
#[derive(Default)]
struct SignupFormFieldState {
username: Dynamic::<String>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs cargo fmt to be run against it.

Comment thread examples/forms-signup.rs
enum FakeApiResponse {
SignUpFailure(Map<SignupField, String>),
// the API returns numbers, which needs to be mapped to a specific error message
SignUpFailure(Vec<u32>),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would a Rust API use u32's instead of an enum to represent the error? I think by introducing this extra step this is complicating the example more than it needs to.

Comment thread examples/forms-signup.rs
}
if username == "user" {
errors.push(
FakeApiSignupErrorCode::UsernameUnavailable.into(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this extra if statement provide that the existing admin one didn't? Why are we complicating this example with extra arbitrary errors rather than keeping it as simple as possible to minimize confusion.

Comment thread examples/forms-signup.rs
},
Ok(FakeApiSignupErrorCode::UsernameInvalid)
=> {
mapped_errors.insert(SignupFormField::Username, String::from("Username is invalid"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to include this as an example, error messages should contain the information required to pass validation.

Comment thread examples/forms-signup.rs
PasswordInsecure = 69,
}

impl TryFrom<u32> for FakeApiSignupErrorCode {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this instead of using something like Serde?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants