Skip to content
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

[#3306] Add save button #3677

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Conversation

acouch
Copy link
Collaborator

@acouch acouch commented Jan 29, 2025

Summary

One part of #3306

Time to review: 45 mins

This adds the save button to the opportunity page.

To Review

Run the API: cd api && make remake-backed

Start the site: cd frontend && npm run dev

Login and save an opportunity.

The button matches pretty well with PixelPerfect

image

@acouch acouch force-pushed the acouch/issue-3306-save-opps-buttons branch 3 times, most recently from 44bf30a to 8b68b3a Compare January 29, 2025 17:03
@acouch acouch marked this pull request as draft January 30, 2025 16:42
@@ -67,7 +67,7 @@ export default function SearchError({ error, reset }: ErrorProps) {
) {
reset();
}
}, [searchParams, reset]);
}, [searchParams, reset, previousSearchParams]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This came up from ts:check locally.

{ message: `Error logging out: ${error.message}` },
{ status: 500 },
{ message: `Error logging out: ${(cause as string) ?? message}` },
{ status },
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This passes on the status from our own errors.

"usa-alert__heading margin-bottom-0 margin-top-05 font-weight-100",
{
"margin-left-2 font-sans-xs": !error,
"margin-left-5 font-sans-sm": error,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error and success designs are different, hence the margin changes:

image
vs
image

@@ -55,11 +53,7 @@ const OpportunityIntro = ({ opportunityData }: Props) => {
};

return (
<ContentLayout
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opp title is moved to the page as part of the update

}
} catch (error) {
setSavedError(true);
console.error(error);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would want to add new relic here in the future.

});
super(serializedData);
};
super(message, { cause });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds the details to the cause property which serializes it.

@acouch acouch marked this pull request as ready for review February 6, 2025 19:48
@acouch acouch force-pushed the acouch/issue-3306-save-opps-buttons branch from ca60c29 to 840bb78 Compare February 6, 2025 20:00
@acouch acouch force-pushed the acouch/issue-3306-save-opps-buttons branch from 840bb78 to fd15fcd Compare February 6, 2025 20:04
Copy link
Collaborator

@doug-s-nava doug-s-nava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to make a follow up for e2e tests around this functionality?

one note on the error front - noticed a case where a request failed with a string message, and since parseErrorStatus is relying on the error message being a valid json string, it errors, and we end up with a 500 response. We should probably take a pass through the code to make sure we've got that right - in any case assuming that the error message will be a json string seems presumptuous.

try {
const session = await getSession();
if (!session || !session.token) {
throw new Error("No active session to get saved opportunity");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a 401?

try {
const session = await getSession();
if (!session || !session.token) {
throw new Error("No active session to save opportunity");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same note as above - should a situation with no session or token be a 401?

};

export const DELETE = async (request: Request) => {
return await handleRequest(request, "DELETE");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't need a second argument here - request.method should give you the string you need, and then we can simplify this a little.

(savedOpportunity: { opportunity_id: number }) =>
savedOpportunity.opportunity_id === opportunity_id,
);
return savedOpportunity ?? [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is expected to return an array, maybe annotate that since getSavedOpportunity suggests to me that it would return a single opportunity rather than a list

@@ -238,6 +238,35 @@ i.e.
padding: units(1) units(2);
}

.simpler-save-button {
padding: units(0.5) units(2) units(0.5) units(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this with existing classes?


describe("GET request", () => {
afterEach(() => jest.clearAllMocks());
it("gets a saved opportunity", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test for the unauthorized and no saved opps error cases?

} as unknown as NextRequest;
};

describe("POST and DELETE request", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to the other test, can you add a couple of error tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants