more refactor complete

This commit is contained in:
Timur Gordon 2025-06-29 12:43:40 +02:00
parent ddbc9d3a75
commit 77e602bf16
2 changed files with 22 additions and 4 deletions

View File

@ -227,7 +227,7 @@ impl Component for MultiStepResidentWizard {
DigitalResidentFormData::default() DigitalResidentFormData::default()
}; };
// Create steps // Create initial steps (will be updated dynamically)
let steps: Vec<Rc<dyn FormStep<DigitalResidentFormData>>> = vec![ let steps: Vec<Rc<dyn FormStep<DigitalResidentFormData>>> = vec![
Rc::new(PersonalInfoStep), Rc::new(PersonalInfoStep),
Rc::new(PaymentStep::new()), Rc::new(PaymentStep::new()),
@ -251,6 +251,14 @@ impl Component for MultiStepResidentWizard {
match msg { match msg {
MultiStepResidentWizardMsg::FormDataChanged(new_data) => { MultiStepResidentWizardMsg::FormDataChanged(new_data) => {
self.form_data = new_data; self.form_data = new_data;
// If we don't have a client secret yet and the form has enough data for payment,
// automatically create the payment intent
if self.client_secret.is_none() && !self.form_data.full_name.is_empty() && !self.form_data.email.is_empty() {
console::log_1(&"🔧 Form data updated with valid info, creating payment intent...".into());
ctx.link().send_message(MultiStepResidentWizardMsg::CreatePaymentIntent);
}
true true
} }
MultiStepResidentWizardMsg::FormCompleted(final_data) => { MultiStepResidentWizardMsg::FormCompleted(final_data) => {
@ -335,7 +343,7 @@ impl Component for MultiStepResidentWizard {
on_form_change={on_form_change} on_form_change={on_form_change}
on_complete={on_complete} on_complete={on_complete}
on_cancel={Some(on_cancel)} on_cancel={Some(on_cancel)}
steps={self.steps.clone()} steps={self.create_steps_with_client_secret()}
validators={self.validators.clone()} validators={self.validators.clone()}
show_progress={true} show_progress={true}
allow_skip_validation={false} allow_skip_validation={false}
@ -364,6 +372,16 @@ impl Component for MultiStepResidentWizard {
} }
impl MultiStepResidentWizard { impl MultiStepResidentWizard {
fn create_steps_with_client_secret(&self) -> Vec<Rc<dyn FormStep<DigitalResidentFormData>>> {
let mut payment_step = PaymentStep::new();
payment_step.set_client_secret(self.client_secret.clone());
vec![
Rc::new(PersonalInfoStep),
Rc::new(payment_step),
]
}
fn create_payment_intent(&self, ctx: &Context<Self>) { fn create_payment_intent(&self, ctx: &Context<Self>) {
let link = ctx.link().clone(); let link = ctx.link().clone();
let form_data = self.form_data.clone(); let form_data = self.form_data.clone();

View File

@ -1,7 +1,7 @@
use yew::prelude::*; use yew::prelude::*;
use web_sys::HtmlInputElement; use web_sys::HtmlInputElement;
use crate::models::company::{DigitalResidentFormData, DigitalResident}; use crate::models::company::{DigitalResidentFormData, DigitalResident};
use crate::components::entities::resident_registration::SimpleResidentWizard; use crate::components::entities::resident_registration::MultiStepResidentWizard;
#[derive(Properties, PartialEq)] #[derive(Properties, PartialEq)]
pub struct ResidentLandingOverlayProps { pub struct ResidentLandingOverlayProps {
@ -344,7 +344,7 @@ impl ResidentLandingOverlay {
// Registration wizard content with fade-in animation // Registration wizard content with fade-in animation
<div class="flex-grow-1 overflow-auto" <div class="flex-grow-1 overflow-auto"
style="opacity: 0; animation: fadeIn 0.5s ease-in-out 0.25s forwards;"> style="opacity: 0; animation: fadeIn 0.5s ease-in-out 0.25s forwards;">
<SimpleResidentWizard <MultiStepResidentWizard
on_registration_complete={link.callback(ResidentLandingMsg::RegistrationComplete)} on_registration_complete={link.callback(ResidentLandingMsg::RegistrationComplete)}
on_back_to_parent={link.callback(|_| ResidentLandingMsg::BackToLanding)} on_back_to_parent={link.callback(|_| ResidentLandingMsg::BackToLanding)}
success_resident_id={None} success_resident_id={None}