fix: redirect user when deleting scholarship
This commit is contained in:
1 parent
1d41d1cbf5
commit
8d90145361
3 files changed
+32
-16
No files matched your search
+9
-8
@@ -1,4 +1,4 @@
|
|||||||
use crate::pages::{AboutPage, HomePage, LoanerPage, ProviderPortal, ScholarshipInfoPage, TestPage};
|
use crate::pages::{AboutPage, HomePage, LoanerPage, ProviderPortal, ComparisonTestPage, ScholarshipInfoPage, TestPage};
|
||||||
use leptos::leptos_dom::log;
|
use leptos::leptos_dom::log;
|
||||||
use leptos::prelude::*;
|
use leptos::prelude::*;
|
||||||
use leptos_meta::{MetaTags, Stylesheet, Title, provide_meta_context};
|
use leptos_meta::{MetaTags, Stylesheet, Title, provide_meta_context};
|
||||||
@@ -96,17 +96,18 @@ pub fn AppWithRoutes() -> impl IntoView {
|
|||||||
|
|
||||||
// sets the document title
|
// sets the document title
|
||||||
<Title text="R15 Scholarship App DEV" />
|
<Title text="R15 Scholarship App DEV" />
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
// TODO Create a 404 page
|
// TODO Create a 404 page
|
||||||
<Routes fallback=|| "Page not found.".into_view()>
|
<Routes fallback=|| "Page not found.".into_view()>
|
||||||
<Route path=path!("") view=HomePage/>
|
<Route path=path!("") view=HomePage/>
|
||||||
<Route path=path!("about") view=AboutPage/>
|
<Route path=path!("/about") view=AboutPage/>
|
||||||
<Route path=path!("test_page") view=TestPage/>
|
<Route path=path!("/test_page") view=TestPage/>
|
||||||
<Route path=path!("comparison") view=ComparisonTestPage />
|
<Route path=path!("/comparison") view=ComparisonTestPage />
|
||||||
<ParentRoute path=path!("providers/scholarships") view=ScholarshipInfoPage>
|
<Route path=path!("/providers") view=ProviderPortal/>
|
||||||
<Route path=path!(":id") view=ScholarshipInfoPage />
|
<ParentRoute path=path!("/providers/scholarships") view=ScholarshipInfoPage>
|
||||||
<Route path=path!("") view=ScholarshipInfoPage />
|
<Route path=path!(":id") view=ScholarshipInfoPage/>
|
||||||
|
<Route path=path!("") view=ScholarshipInfoPage/>
|
||||||
</ParentRoute>
|
</ParentRoute>
|
||||||
<ParentRoute path=path!("loaners") view=LoanerPage>
|
<ParentRoute path=path!("loaners") view=LoanerPage>
|
||||||
<Route path=path!("") view=LoanerPage />
|
<Route path=path!("") view=LoanerPage />
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ pub fn ProviderPortal() -> impl IntoView {
|
|||||||
title="Create Scholarship"
|
title="Create Scholarship"
|
||||||
description="Navigate to Scholarship Creation Page"
|
description="Navigate to Scholarship Creation Page"
|
||||||
icon="/Create_Black.png"
|
icon="/Create_Black.png"
|
||||||
path="/"
|
path="/providers/scholarships"
|
||||||
/>
|
/>
|
||||||
<DashboardButton
|
<DashboardButton
|
||||||
title="Applicants"
|
title="Applicants"
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ pub fn ScholarshipInfoPage() -> impl IntoView {
|
|||||||
|
|
||||||
let create_test_comps = ServerAction::<CreateTestComparisons>::new();
|
let create_test_comps = ServerAction::<CreateTestComparisons>::new();
|
||||||
|
|
||||||
|
let on_delete = move || {
|
||||||
|
let navigate = use_navigate();
|
||||||
|
navigate("/providers/scholarships", Default::default());
|
||||||
|
};
|
||||||
|
|
||||||
// Remember that we only want to show the page after we've got authentication information
|
// Remember that we only want to show the page after we've got authentication information
|
||||||
// and if there's data for us to use.
|
// and if there's data for us to use.
|
||||||
view! {
|
view! {
|
||||||
@@ -45,7 +50,10 @@ pub fn ScholarshipInfoPage() -> impl IntoView {
|
|||||||
<Authenticated unauthenticated=UnauthenticatedPage>
|
<Authenticated unauthenticated=UnauthenticatedPage>
|
||||||
<div class="flex flex-row align-top items-start">
|
<div class="flex flex-row align-top items-start">
|
||||||
<div class="flex flex-col flex-1" />
|
<div class="flex flex-col flex-1" />
|
||||||
<ScholarshipList refresh_token=list_refresh/>
|
<ScholarshipList
|
||||||
|
refresh_token=list_refresh
|
||||||
|
on_delete=on_delete
|
||||||
|
/>
|
||||||
<Transition fallback=Loading>
|
<Transition fallback=Loading>
|
||||||
<ScholarshipForm
|
<ScholarshipForm
|
||||||
scholarship_id=scholarship_id
|
scholarship_id=scholarship_id
|
||||||
@@ -67,22 +75,28 @@ pub fn ScholarshipInfoPage() -> impl IntoView {
|
|||||||
/// is authenticated, this component will get all the scholarships that this provider owns and
|
/// 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.
|
/// 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:
|
/// Example usage:
|
||||||
/// ```
|
/// ```
|
||||||
|
/// let refresh = RwSignal::new(0);
|
||||||
|
///
|
||||||
/// view! {
|
/// view! {
|
||||||
/// <AuthLoaded>
|
/// <AuthLoaded>
|
||||||
/// <Authenticated>
|
/// <Authenticated>
|
||||||
/// <ScholarshipList />
|
/// <ScholarshipList
|
||||||
|
/// refresh_token=refresh
|
||||||
|
/// on_delete=move || log!("This is run when an item is deleted on the server.")
|
||||||
|
/// />
|
||||||
/// </Authenticated>
|
/// </Authenticated>
|
||||||
/// </AuthLoaded>
|
/// </AuthLoaded>
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[component]
|
#[component]
|
||||||
fn ScholarshipList(
|
fn ScholarshipList(
|
||||||
|
/// A signal that refreshes the list when changed. Most times, we don't need to worry about the
|
||||||
|
/// user reloading our page 2 billion times.
|
||||||
#[prop()] refresh_token: RwSignal<i32>,
|
#[prop()] refresh_token: RwSignal<i32>,
|
||||||
|
/// A callback that is run on successful server-side deletion of an item.
|
||||||
|
#[prop(into)] on_delete: Callback<()>
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
// List state
|
// List state
|
||||||
let pending_delete = RwSignal::new(None::<ExpandableInfo>);
|
let pending_delete = RwSignal::new(None::<ExpandableInfo>);
|
||||||
@@ -125,7 +139,7 @@ fn ScholarshipList(
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let on_delete = move |s| {
|
let on_item_delete = move |s| {
|
||||||
pending_delete.set(Some(s));
|
pending_delete.set(Some(s));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -149,6 +163,7 @@ fn ScholarshipList(
|
|||||||
scholarships.refetch();
|
scholarships.refetch();
|
||||||
pending_delete.set(None);
|
pending_delete.set(None);
|
||||||
delete_action.clear();
|
delete_action.clear();
|
||||||
|
on_delete.run(());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -213,7 +228,7 @@ fn ScholarshipList(
|
|||||||
let views = list.iter().map(|entry| {
|
let views = list.iter().map(|entry| {
|
||||||
view! {
|
view! {
|
||||||
<ScholarshipListEntry scholarship=entry.clone()
|
<ScholarshipListEntry scholarship=entry.clone()
|
||||||
on_delete=Callback::new(on_delete)/>
|
on_delete=Callback::new(on_item_delete)/>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Either::Left(views.collect_view())
|
Either::Left(views.collect_view())
|
||||||
|
|||||||
Reference in new issue
Block a user