Implement provider scholarship edit form #33
No files matched your search
@@ -32,8 +32,8 @@ pub async fn get_scholarship_info(id: String) -> Result<ExpandableInfo, ServerFn
|
|||||||
log!("Found output from API: {:?}", item);
|
log!("Found output from API: {:?}", item);
|
||||||
Ok(serde_dynamo::from_item(item)?)
|
Ok(serde_dynamo::from_item(item)?)
|
||||||
} else {
|
} else {
|
||||||
log!("Couldn't find any values, returning default struct.");
|
log!("Couldn't find scholarship with ID {:?}", id);
|
||||||
Ok(ExpandableInfo::new(id.clone()))
|
Err(ServerFnError::new("Couldn't find scholarship with given ID."))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
@@ -64,6 +64,25 @@ pub fn ScholarshipInfoPage() -> impl IntoView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Scholarship List Component
|
||||||
|
///
|
||||||
|
/// This component should always be wrapped in an Authenticated component. Assuming that a provider
|
||||||
|
/// is authenticated, this component will get all the scholarships that this provider owns and
|
||||||
|
/// will display them in a list, giving them the option to edit, delete, or create new scholarships.
|
||||||
|
///
|
||||||
|
/// It does not accept any props, and instead pulls the provider's information from the surrounding
|
||||||
|
/// environment.
|
||||||
|
///
|
||||||
|
/// Example usage:
|
||||||
|
/// ```
|
||||||
|
/// view! {
|
||||||
|
/// <AuthLoaded>
|
||||||
|
/// <Authenticated>
|
||||||
|
/// <ScholarshipList />
|
||||||
|
/// </Authenticated>
|
||||||
|
/// </AuthLoaded>
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
#[component]
|
#[component]
|
||||||
fn ScholarshipList() -> impl IntoView {
|
fn ScholarshipList() -> impl IntoView {
|
||||||
// Get scholarship provider information from authentication. This element will not display
|
// Get scholarship provider information from authentication. This element will not display
|
||||||
@@ -158,12 +177,33 @@ fn ScholarshipList() -> impl IntoView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Scholarship List Entry Component
|
||||||
|
///
|
||||||
|
/// Displays a single scholarship within the [`ScholarshipList`] component.
|
||||||
|
///
|
||||||
|
/// Example usage (within the [`ScholarshipList`]):
|
||||||
|
/// ```
|
||||||
|
/// view! {
|
||||||
|
/// <ScholarshipListEntry
|
||||||
|
/// scholarship= /* An ExpandableInfo object containing scholarship info */
|
||||||
|
/// on_delete=move || log!("This is a callback on successful deletion.")
|
||||||
|
/// />
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
#[component]
|
#[component]
|
||||||
fn ScholarshipListEntry(
|
fn ScholarshipListEntry(
|
||||||
|
/// The scholarship information. This element will attempt to get the name of the scholarship
|
||||||
|
/// using its `name` field, and also utilizes the `subject` field.
|
||||||
#[prop()] scholarship: ExpandableInfo,
|
#[prop()] scholarship: ExpandableInfo,
|
||||||
|
/// A [`Callback<()>`] that runs upon successful deletion of the scholarship.
|
||||||
#[prop(into)] on_delete: Callback<()>,
|
#[prop(into)] on_delete: Callback<()>,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
let navigate = use_navigate();
|
let navigate = use_navigate();
|
||||||
|
let user_claims = get_user_claims();
|
||||||
|
let user_id = Memo::new(move |_| {
|
||||||
|
user_claims.get()
|
||||||
|
.map(|info| info.claims.subject.clone())
|
||||||
|
});
|
||||||
|
|
||||||
// Get the values that we need out of the info. We just need the subject and the name of
|
// Get the values that we need out of the info. We just need the subject and the name of
|
||||||
// the scholarship.
|
// the scholarship.
|
||||||
@@ -187,15 +227,17 @@ fn ScholarshipListEntry(
|
|||||||
// Delete the scholarship.
|
// Delete the scholarship.
|
||||||
let subject = subject.clone();
|
let subject = subject.clone();
|
||||||
log!("Deleting scholarship with ID {:?}", subject);
|
log!("Deleting scholarship with ID {:?}", subject);
|
||||||
spawn_local(async move {
|
if let Some(user_id) = user_id.get() {
|
||||||
match delete_provider_scholarship(
|
spawn_local(async move {
|
||||||
subject,
|
match delete_provider_scholarship(
|
||||||
"".to_string()
|
user_id,
|
||||||
).await {
|
subject
|
||||||
Ok(_) => on_delete.run(()),
|
).await {
|
||||||
_ => {}
|
Ok(_) => on_delete.run(()),
|
||||||
}
|
_ => {}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user