fix: hopeful fix for blank IDs in submissions
This commit is contained in:
1 parent
f9d5b25436
commit
1d41b6022e
2 files changed
+52
-50
No files matched your search
@@ -4,7 +4,7 @@ use crate::pages::api::files::list_files;
|
|||||||
use crate::pages::api::students::get_all_student_data;
|
use crate::pages::api::students::get_all_student_data;
|
||||||
use crate::pages::api::{get_all_scholarship_info, get_comparison_info};
|
use crate::pages::api::{get_all_scholarship_info, get_comparison_info};
|
||||||
use crate::utils::get_user_claims;
|
use crate::utils::get_user_claims;
|
||||||
use leptos::logging::{debug_log, debug_error};
|
use leptos::logging::{debug_error, debug_log};
|
||||||
use leptos::prelude::*;
|
use leptos::prelude::*;
|
||||||
use leptos_oidc::AuthSignal;
|
use leptos_oidc::AuthSignal;
|
||||||
|
|
||||||
@@ -23,6 +23,11 @@ pub fn StudentEligibilityPage() -> impl IntoView {
|
|||||||
let auth = expect_context::<AuthSignal>();
|
let auth = expect_context::<AuthSignal>();
|
||||||
let user_claims = get_user_claims();
|
let user_claims = get_user_claims();
|
||||||
let user_id = Memo::new(move |_| user_claims.get().map(|info| info.claims.subject.clone()));
|
let user_id = Memo::new(move |_| user_claims.get().map(|info| info.claims.subject.clone()));
|
||||||
|
let access_token = Memo::new(move |_| auth.get().authenticated().map(|a| a.access_token()));
|
||||||
|
|
||||||
|
Effect::new(move || {
|
||||||
|
debug_log!("User ID was updated: {}", user_id.get().unwrap_or_default());
|
||||||
|
});
|
||||||
|
|
||||||
let form_id = StoredValue::new("scholarship_essays".to_string());
|
let form_id = StoredValue::new("scholarship_essays".to_string());
|
||||||
|
|
||||||
@@ -111,23 +116,23 @@ pub fn StudentEligibilityPage() -> impl IntoView {
|
|||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
list.iter()
|
list.iter()
|
||||||
.any(
|
.any(|requirement| {
|
||||||
|requirement| {
|
let result = requirement.compare(&student_info);
|
||||||
let result = requirement
|
match result.as_ref() {
|
||||||
.compare(&student_info);
|
Ok(status) => {
|
||||||
|
debug_log!(
|
||||||
match result.as_ref() {
|
"Requirement with id {} is Ok({})", requirement.id, status
|
||||||
Ok(status) => {
|
);
|
||||||
debug_log!("Requirement with id {} is Ok({})", requirement.id, status);
|
status.clone()
|
||||||
status.clone()
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
debug_error!("Requirement with id {} failed: {}", requirement.id, e);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
Err(e) => {
|
||||||
)
|
debug_error!(
|
||||||
|
"Requirement with id {} failed: {}", requirement.id, e
|
||||||
|
);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if valid {
|
if valid {
|
||||||
@@ -135,19 +140,15 @@ pub fn StudentEligibilityPage() -> impl IntoView {
|
|||||||
let scholarship_id = StoredValue::new(scholarship.subject.clone());
|
let scholarship_id = StoredValue::new(scholarship.subject.clone());
|
||||||
let resource = Resource::new(
|
let resource = Resource::new(
|
||||||
move || (
|
move || (
|
||||||
auth
|
access_token.get(),
|
||||||
.try_with(|a| a.authenticated().map(|a| a.access_token()))
|
|
||||||
.flatten(),
|
|
||||||
form_id.get_value(),
|
form_id.get_value(),
|
||||||
scholarship_id.get_value(),
|
scholarship_id.get_value(),
|
||||||
),
|
),
|
||||||
async move |(access_token, form_id, scholarship_id)| {
|
async move |(access_token, form_id, scholarship_id)| {
|
||||||
list_files(
|
let Some(access_token) = access_token else {
|
||||||
access_token.unwrap_or_default(),
|
return Ok(Vec::new());
|
||||||
form_id,
|
};
|
||||||
scholarship_id,
|
list_files(access_token, form_id, scholarship_id).await
|
||||||
)
|
|
||||||
.await
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Some((scholarship.clone(), resource))
|
Some((scholarship.clone(), resource))
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use leptos::prelude::*;
|
|
||||||
use uuid::Uuid;
|
|
||||||
use crate::common::ValueType;
|
use crate::common::ValueType;
|
||||||
use crate::components::{Toast, ToastContext};
|
use crate::components::{Toast, ToastContext};
|
||||||
use crate::pages::api::students::{get_student_data, PutStudentData};
|
use crate::pages::api::students::{PutStudentData, get_student_data};
|
||||||
use crate::utils::get_user_claims;
|
use crate::utils::get_user_claims;
|
||||||
|
use leptos::prelude::*;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub struct StudentFormInfo {
|
pub struct StudentFormInfo {
|
||||||
pub data_map: RwSignal<HashMap<String, ValueType>>,
|
pub data_map: RwSignal<HashMap<String, ValueType>>,
|
||||||
@@ -20,22 +20,21 @@ pub fn use_student_form(
|
|||||||
enable_toasts: bool,
|
enable_toasts: bool,
|
||||||
) -> StudentFormInfo {
|
) -> StudentFormInfo {
|
||||||
let form_type = form_type.into();
|
let form_type = form_type.into();
|
||||||
|
|
||||||
let user_claims = get_user_claims();
|
let user_claims = get_user_claims();
|
||||||
let user_id = Memo::new(move |_| {
|
let user_id = Memo::new(move |_| user_claims.get().map(|info| info.claims.subject.clone()));
|
||||||
user_claims.get()
|
|
||||||
.map(|info| info.claims.subject.clone())
|
|
||||||
});
|
|
||||||
|
|
||||||
let data_map = RwSignal::new(HashMap::new());
|
let data_map = RwSignal::new(HashMap::new());
|
||||||
|
|
||||||
let refresh_trigger = Trigger::new();
|
let refresh_trigger = Trigger::new();
|
||||||
let data_resource = Resource::new(
|
let data_resource = Resource::new(
|
||||||
move || (user_id.get().unwrap_or_default(), form_type.get(), refresh_trigger.track()),
|
move || (user_id.get(), form_type.get(), refresh_trigger.track()),
|
||||||
async move |(id, form_type, _)| get_student_data(
|
async move |(id, form_type, _)| {
|
||||||
id,
|
let Some(id) = id else {
|
||||||
form_type,
|
return Ok(HashMap::new());
|
||||||
).await
|
};
|
||||||
|
get_student_data(id, form_type).await
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
Effect::new(move || {
|
Effect::new(move || {
|
||||||
@@ -50,13 +49,15 @@ pub fn use_student_form(
|
|||||||
|
|
||||||
let submit_action = ServerAction::<PutStudentData>::new();
|
let submit_action = ServerAction::<PutStudentData>::new();
|
||||||
let on_submit = move || {
|
let on_submit = move || {
|
||||||
submit_action.dispatch(PutStudentData {
|
if let Some(id) = user_id.get() {
|
||||||
subject: user_id.get().unwrap_or_default(),
|
submit_action.dispatch(PutStudentData {
|
||||||
data_type: form_type.get(),
|
subject: id,
|
||||||
data_map: data_map.get()
|
data_type: form_type.get(),
|
||||||
});
|
data_map: data_map.get(),
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if enable_toasts {
|
if enable_toasts {
|
||||||
let mut toasts = expect_context::<ToastContext>();
|
let mut toasts = expect_context::<ToastContext>();
|
||||||
Effect::watch(
|
Effect::watch(
|
||||||
@@ -74,13 +75,13 @@ pub fn use_student_form(
|
|||||||
Err(e) => Toast::new()
|
Err(e) => Toast::new()
|
||||||
.id(Uuid::new_v4())
|
.id(Uuid::new_v4())
|
||||||
.header("Submission Failed")
|
.header("Submission Failed")
|
||||||
.msg(e.to_string())
|
.msg(e.to_string()),
|
||||||
};
|
};
|
||||||
|
|
||||||
toasts.toast(toast);
|
toasts.toast(toast);
|
||||||
untrack(move || submit_action.clear());
|
untrack(move || submit_action.clear());
|
||||||
},
|
},
|
||||||
false
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +91,6 @@ pub fn use_student_form(
|
|||||||
data_resource,
|
data_resource,
|
||||||
user_id,
|
user_id,
|
||||||
submit_action: on_submit.into(),
|
submit_action: on_submit.into(),
|
||||||
submit_pending: submit_action.pending()
|
submit_pending: submit_action.pending(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user