diff --git a/portal/src/components/entities/resident_registration/mod.rs b/portal/src/components/entities/resident_registration/mod.rs index ae3937c..376ac90 100644 --- a/portal/src/components/entities/resident_registration/mod.rs +++ b/portal/src/components/entities/resident_registration/mod.rs @@ -2,8 +2,10 @@ pub mod step_payment_stripe; pub mod simple_resident_wizard; pub mod simple_step_info; pub mod residence_card; +pub mod refactored_resident_wizard; pub use step_payment_stripe::*; pub use simple_resident_wizard::*; pub use simple_step_info::*; -pub use residence_card::*; \ No newline at end of file +pub use residence_card::*; +pub use refactored_resident_wizard::*; \ No newline at end of file diff --git a/portal/src/components/entities/resident_registration/refactored_resident_wizard.rs b/portal/src/components/entities/resident_registration/refactored_resident_wizard.rs new file mode 100644 index 0000000..7cb04b7 --- /dev/null +++ b/portal/src/components/entities/resident_registration/refactored_resident_wizard.rs @@ -0,0 +1,294 @@ +use yew::prelude::*; +use crate::models::company::{DigitalResidentFormData, DigitalResident}; +use crate::services::ResidentService; +use crate::components::common::ui::progress_indicator::{ProgressIndicator, ProgressVariant, ProgressColor, ProgressSize}; +use crate::components::common::ui::loading_spinner::LoadingSpinner; +use super::{SimpleStepInfo, StepPaymentStripe, ResidenceCard}; +use web_sys::console; + +#[derive(Properties, PartialEq)] +pub struct RefactoredResidentWizardProps { + pub on_registration_complete: Callback, + pub on_back_to_parent: Callback<()>, + #[prop_or_default] + pub success_resident_id: Option, + #[prop_or_default] + pub show_failure: bool, +} + +pub enum RefactoredResidentWizardMsg { + NextStep, + PrevStep, + UpdateFormData(DigitalResidentFormData), + RegistrationComplete(DigitalResident), + RegistrationError(String), +} + +pub struct RefactoredResidentWizard { + current_step: usize, + form_data: DigitalResidentFormData, + validation_errors: Vec, +} + +impl Component for RefactoredResidentWizard { + type Message = RefactoredResidentWizardMsg; + type Properties = RefactoredResidentWizardProps; + + fn create(ctx: &Context) -> Self { + let current_step = if ctx.props().success_resident_id.is_some() { + 2 // Success step + } else if ctx.props().show_failure { + 1 // Payment step + } else { + 0 // Start from beginning + }; + + Self { + current_step, + form_data: DigitalResidentFormData::default(), + validation_errors: Vec::new(), + } + } + + fn update(&mut self, ctx: &Context, msg: Self::Message) -> bool { + match msg { + RefactoredResidentWizardMsg::NextStep => { + // Simple validation for demo + if self.current_step == 0 { + if self.form_data.full_name.trim().is_empty() || self.form_data.email.trim().is_empty() { + self.validation_errors = vec!["Please fill in all required fields".to_string()]; + return true; + } + } + + self.validation_errors.clear(); + if self.current_step < 2 { + self.current_step += 1; + } + true + } + RefactoredResidentWizardMsg::PrevStep => { + if self.current_step > 0 { + self.current_step -= 1; + } + true + } + RefactoredResidentWizardMsg::UpdateFormData(new_data) => { + self.form_data = new_data; + true + } + RefactoredResidentWizardMsg::RegistrationComplete(resident) => { + self.current_step = 2; // Move to success step + ctx.props().on_registration_complete.emit(resident); + true + } + RefactoredResidentWizardMsg::RegistrationError(error) => { + self.validation_errors = vec![error]; + true + } + } + } + + fn view(&self, ctx: &Context) -> Html { + let link = ctx.link(); + + html! { +
+ {if self.current_step < 2 { + html! { + <> + // Progress indicator using our generic component + + + // Step content +
+ {self.render_current_step(ctx)} +
+ + // Navigation footer + {if self.current_step < 2 { + self.render_navigation_footer(ctx) + } else { + html! {} + }} + + // Validation errors + {if !self.validation_errors.is_empty() { + html! { +
+
    + {for self.validation_errors.iter().map(|error| { + html! {
  • {error}
  • } + })} +
+
+ } + } else { + html! {} + }} + + } + } else { + // Success step + html! { +
+ {self.render_success_step(ctx)} +
+ } + }} +
+ } + } +} + +impl RefactoredResidentWizard { + fn render_current_step(&self, ctx: &Context) -> Html { + let link = ctx.link(); + let on_form_update = link.callback(RefactoredResidentWizardMsg::UpdateFormData); + + match self.current_step { + 0 => html! { + + }, + 1 => html! { + ::None} + processing_payment={false} + on_process_payment={link.callback(|_| RefactoredResidentWizardMsg::NextStep)} + on_payment_complete={link.callback(RefactoredResidentWizardMsg::RegistrationComplete)} + on_payment_error={link.callback(RefactoredResidentWizardMsg::RegistrationError)} + on_payment_plan_change={link.callback(|_| RefactoredResidentWizardMsg::NextStep)} + on_confirmation_change={link.callback(|_| RefactoredResidentWizardMsg::NextStep)} + /> + }, + _ => html! {
{"Invalid step"}
} + } + } + + fn render_navigation_footer(&self, ctx: &Context) -> Html { + let link = ctx.link(); + + html! { + + } + } + + fn render_success_step(&self, ctx: &Context) -> Html { + html! { +
+
+ +
+ +

{"Registration Successful!"}

+

+ {"Your digital resident registration has been successfully submitted and is now pending approval."} +

+ +
+
+
+
+
+ {"What happens next?"} +
+
+
+
+ {"1"} +
+
+ {"Identity Verification"} +

{"Our team will verify your identity and submitted documents."}

+
+
+ +
+
+ {"2"} +
+
+ {"Background Check"} +

{"We'll conduct necessary background checks and compliance verification."}

+
+
+ +
+
+ {"3"} +
+
+ {"Approval & Activation"} +

{"Once approved, your digital resident status will be activated and you'll gain access to selected services."}

+
+
+
+
+
+
+
+ +
+ +
+ +
+
+ + {"You will receive email updates about your registration status. The approval process typically takes 3-5 business days."} +
+
+
+ } + } +} \ No newline at end of file