-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue #3308] View Saved Opportunities on Saved grants page #3992
Changes from all commits
776a037
c747922
adb1081
7743452
f1cae0a
c60ccde
a1d23d8
f8e0afa
d8edb4d
318103d
56b5d0d
6a578c6
05ba3a9
7113ea5
af304b8
419c549
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
"server-only"; | ||
|
||
import { getSession } from "src/services/auth/session"; | ||
import { userSavedOpportunity } from "src/services/fetch/fetchers/fetchers"; | ||
import { SavedOpportunity } from "src/types/saved-opportunity/savedOpportunityResponseTypes"; | ||
|
||
|
@@ -69,3 +72,22 @@ export const getSavedOpportunity = async ( | |
); | ||
return savedOpportunity ?? null; | ||
}; | ||
|
||
export const fetchSavedOpportunities = async (): Promise< | ||
SavedOpportunity[] | ||
> => { | ||
try { | ||
const session = await getSession(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be overkill, but since the session will only be available on the server side (until now it's only been used in route handlers) maybe we should put a "server only" on this file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The client component would immediately break with a notice if you tried to import the file, so doesn't seem like a risk that someone would use this incorrectly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree there's no big risk here since this would break if we tried to use it in the client, but potentially would add some dev time if someone didn't realize that. If we pop "server-only" in here, since it's a utilities file rather than anything react specific, I think we'd gain the ability to break faster and provide an annotation for devs so that the use case for the file is immediately clear. https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#keeping-server-only-code-out-of-the-client-environment Not entirely necessary, but worth maybe discussing further and thinking about documenting as we make a decision one way or another about how we want to use these designations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was conflating |
||
if (!session || !session.token) { | ||
return []; | ||
} | ||
const savedOpportunities = await getSavedOpportunities( | ||
session.token, | ||
session.user_id as string, | ||
); | ||
return savedOpportunities; | ||
} catch (e) { | ||
console.error("Error fetching saved opportunities:", e); | ||
return []; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Opportunity } from "src/types/search/searchResponseTypes"; | ||
|
||
export const mockOpportunity: Opportunity = { | ||
opportunity_id: 12345, | ||
opportunity_title: "Test Opportunity", | ||
opportunity_status: "posted", | ||
summary: { | ||
archive_date: "2023-01-01", | ||
close_date: "2023-02-01", | ||
post_date: "2023-01-15", | ||
agency_name: "Test Agency", | ||
award_ceiling: 50000, | ||
award_floor: 10000, | ||
}, | ||
opportunity_number: "OPP-12345", | ||
} as Opportunity; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[a note for later] is there a way we could move this complexity to the API side so that we don't have to make so many round trips here, or will caching make that more or less a moot point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be ideal if the saved opportunity returned enough detail to create the results summary. Since that is changing with the new design we shouldn't make a change there right now.