diff --git a/src/components/validated_form.rs b/src/components/validated_form.rs index 4420ccb..c4314f0 100644 --- a/src/components/validated_form.rs +++ b/src/components/validated_form.rs @@ -111,6 +111,8 @@ pub fn ValidatedForm( #[prop(into)] title: Signal, /// The description for the included header. #[prop(optional, into)] description: Signal, + /// A `Signal` that determines when the submit button should be disabled. + #[prop(optional, into)] disabled: Signal, ) -> impl IntoView { let validators = RwSignal::new(vec![]); @@ -154,6 +156,7 @@ pub fn ValidatedForm(
{children()} impl IntoView { - let controller = use_student_form("academics"); + let controller = use_student_form("academics", true); view! { @@ -20,9 +20,11 @@ pub fn StudentAcademicsPage() -> impl IntoView { title="Academic Information" description="This information will allow you to be eligible for any scholarships that have specific academic/grade requirements." on_submit=controller.submit_action + disabled=controller.submit_pending > impl IntoView { /> impl IntoView { /> impl IntoView { /> impl IntoView { /> impl IntoView { - let controller = use_student_form("athletics"); + let controller = use_student_form("athletics", true); view! { @@ -15,6 +15,7 @@ pub fn StudentAthleticsPage() -> impl IntoView { title="Athletics Information" description="This information will allow you to be eligible for any scholarships that have specific sports requirements." on_submit=controller.submit_action + disabled=controller.submit_pending > impl IntoView { // I'm going to test out creating this form without using a panel - we'll just use the page as // it is with a specially spaced invisible div instead of a shaded container. - let controller = use_student_form("demographics"); + let controller = use_student_form("demographics", true); view! { @@ -19,9 +19,11 @@ pub fn StudentDemographicsPage() -> impl IntoView { title="Student Demographic Form" description="Here you'll set up some basic information about yourself." on_submit=controller.submit_action + disabled=controller.submit_pending > impl IntoView { /> impl IntoView { /> impl IntoView { /> impl IntoView { - let controller = use_student_form("demographics"); + let controller = use_student_form("demographics", true); view! { @@ -15,10 +15,12 @@ pub fn StudentExtracurricularsPage() -> impl IntoView { title="Extracurricular Information" description="This information will allow you to be eligible for any scholarships that have specific extracurricular requirements." on_submit=controller.submit_action + disabled=controller.submit_pending > // Inputs here. impl IntoView { - let controller = use_student_form("family"); + let controller = use_student_form("family", true); view! { @@ -14,10 +14,12 @@ pub fn StudentFamilyPage() -> impl IntoView { title="Family Information" description="General family information. You must fill out information about at least one parent." on_submit=controller.submit_action + disabled=controller.submit_pending > // Inputs here. impl IntoView { /> impl IntoView { /> impl IntoView { // TODO Could this be a select dropdown? impl IntoView { // TODO Get a better example impl IntoView { /> impl IntoView { impl IntoView { /> impl IntoView { /> impl IntoView { /> >, pub submit_action: Callback<()>, pub refresh_trigger: Trigger, - pub data_resource: Resource, ServerFnError>> + pub data_resource: Resource, ServerFnError>>, + pub submit_pending: Memo, } pub fn use_student_form( - form_type: impl Into> + form_type: impl Into>, + enable_toasts: bool, ) -> StudentFormInfo { let form_type = form_type.into(); @@ -53,11 +57,39 @@ pub fn use_student_form( }); }; + if enable_toasts { + let mut toasts = expect_context::(); + Effect::watch( + move || submit_action.value().get(), + move |value, _, _| { + let Some(result) = value else { + return; + }; + + let toast = match result { + Ok(_) => Toast::new() + .id(Uuid::new_v4()) + .header("Submission Successful") + .msg("You may continue editing or fill out another form."), + Err(e) => Toast::new() + .id(Uuid::new_v4()) + .header("Submission Failed") + .msg(e.to_string()) + }; + + toasts.toast(toast); + untrack(move || submit_action.clear()); + }, + false + ); + } + StudentFormInfo { data_map, refresh_trigger, data_resource, user_id, submit_action: on_submit.into(), + submit_pending: submit_action.pending() } } \ No newline at end of file diff --git a/src/pages/student/specific_requirements_page.rs b/src/pages/student/specific_requirements_page.rs index d923fe5..e10b969 100644 --- a/src/pages/student/specific_requirements_page.rs +++ b/src/pages/student/specific_requirements_page.rs @@ -4,7 +4,7 @@ use leptos::prelude::*; #[component] pub fn StudentSpecificRequirementsPage() -> impl IntoView { - let controller = use_student_form("specifics"); + let controller = use_student_form("specifics", true); view! { @@ -20,9 +20,11 @@ pub fn StudentSpecificRequirementsPage() -> impl IntoView { title="Scholarship-Specific Eligibility Requirements" description="These questions are specific to some scholarships. Indicate yes or no for each question." on_submit=controller.submit_action + disabled=controller.submit_pending > impl IntoView { /> impl IntoView { /> impl IntoView { /> impl IntoView { /> impl IntoView { /> impl IntoView { /> impl IntoView { - let controller = use_student_form("university"); + let controller = use_student_form("university", true); // college name, state, city, zip // major, study field, intended career, college_acceptance @@ -17,10 +17,12 @@ pub fn StudentUniversityPage() -> impl IntoView { title="University Information" description="Here you may fill out general information about the university you plan to attend." on_submit=controller.submit_action + disabled=controller.submit_pending > // Inputs here. impl IntoView { /> impl IntoView { /> impl IntoView { /> impl IntoView { /> impl IntoView { /> impl IntoView { - let controller = use_student_form("workexp"); + let controller = use_student_form("workexp", true); view! { @@ -15,6 +15,7 @@ pub fn StudentWorkExperiencePage() -> impl IntoView { title="Student Work Experience" description="Here you may add information about your past/current workplace." on_submit=controller.submit_action + disabled=controller.submit_pending >