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

[Issue #1362] Sendy Update #2530

Merged
merged 24 commits into from
Oct 29, 2024
Merged

[Issue #1362] Sendy Update #2530

merged 24 commits into from
Oct 29, 2024

Conversation

acouch
Copy link
Collaborator

@acouch acouch commented Oct 21, 2024

Summary

Fixes #1362

Time to review: 15 mins

Changes proposed

This builds on #2428 by adding tests. See that PR for details.

@acouch acouch force-pushed the acouch/issue-1362-testing-form branch from 0cb2ba0 to ac812dc Compare October 21, 2024 15:40
@acouch acouch marked this pull request as ready for review October 25, 2024 17:49
Copy link
Contributor

@emilycnava emilycnava left a comment

Choose a reason for hiding this comment

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

Pair reviewed with Aaron, discussed changes between original draft PR and this one and it all LGTM!

@acouch acouch changed the title DRAFT [Issue #1362] Sendy Update [Issue #1362] Sendy Update Oct 25, 2024
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.

Everything that's here looks good but curious why the e2e test was deleted. Will go through some manual testing now

): Promise<sendyResponse> {
const schema = z.object({
name: z.string().min(1, {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
Copy link
Collaborator

Choose a reason for hiding this comment

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

does next-intl have any recommendations on how to pass around the t function in a typescript app? There has to be a better way, unless this typing is specifically designed to discourage passing it around. If that's the case then... really?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like it is discouraged by the maintainer but there is a better way. Let's try that.

Copy link
Collaborator

@doug-s-nava doug-s-nava Oct 28, 2024

Choose a reason for hiding this comment

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

Very weird. It seems like they're saying they discourage passing the function around because the typing is cumbersome, rather than that they specifically left the typing cumbersome in order to discourage passing the function around for some more thought out reason.

I can see not wanting to pass this function around for one particular reason: if you pass t from a server component to a client component you end up potentially closing over the entire messages object, and shipping the entire text content of your site to the client unnecessarily. I'm not exactly sure how next-intl works or if this complexity is expected as the cost of doing business but it seems potentially, and this is a very scientific word here, slops.

I think there is a lot of thinking to be done around how next-intl can / should be used on a big, complex, scalable app that has to manage a large amount of translated content.

"Sorry, an unexpected error in our system occured when trying to save your subscription. If this continues to happen, you may email <email>[email protected]</email>. Error: <sendy_error/>",
server:
"Failed to subscribe, due to a server error. Please try again later.",
already_subscribed: "This email address has already been subscribed.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] curious why this was changed - was the existing message too long / complex?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious where the impetus for changing "<email_address/> is already subscribed. If you’re not seeing our emails, check your spam folder and add [email protected] to your contacts, address book, or safe senders list. If you continue to not receive our emails, contact [email protected]." to "This email address has already been subscribed." is coming from exactly since I didn't see it in any requirements. Very possible I just missed that req somewhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I should have been more verbose. Not sure where that came from myself. @emilycnava ?

Copy link
Contributor

Choose a reason for hiding this comment

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

It wasn't a req, just a choice I made due to the positioning of the error message being different and long messages looking weird. Also the email var insertion code was broken with the old approach.

Old:
Screenshot 2024-10-28 at 3 07 53 PM

New:
Screenshot 2024-10-28 at 3 11 41 PM

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm ok with this since it's fixing a bug with the formatting, but we should probably get sign off from design / content on the final text

);
expect(testErrorAlreadySubscribed.validationErrors).toEqual({});

// Test response that indicates server error
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] might consider breaking this into 4 separate tests, so that if one use case breaks it's easier to track down

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.

  • when running an npm install on the branch I get a small diff in the package-lock removing "@types/jest": "^29.5.13",. Seems like either something we should figure out or commit

  • I get a hydration error on the subscribe page when I load it up, see screenshot. (Update: I think this was a blip, restarted my server and things seem fine)

  • I get a "failed to susbscrbe, due to a server error. Please try again later." message on the frontend when trying to subscribe. On the Next backend I see Error subscribing user: Failed to parse URL from /subscribe

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Oct 28, 2024
@acouch
Copy link
Collaborator Author

acouch commented Oct 28, 2024

@doug-s-nava

I get a "failed to susbscrbe, due to a server error. Please try again later." message on the frontend when trying to subscribe. On the Next backend I see Error subscribing user: Failed to parse URL from /subscribe

I think this might be because you don't have the sendy credentials? I updated the docs to reflect needing that: 94e62a8

Everything that's here looks good but curious why the e2e test was deleted. Will go through some manual testing now

They don't work currently with server actions. Created a ticket to fix that: #2537

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.

Local test with the correct envs checks out. Holding on approval for clarity around the "already subscribed" messaging change but the rest all LGTM

@emilycnava
Copy link
Contributor

@doug-s-nava Answered your Q r.e. already_subscribed msg above :)

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.

a few qualms but nothing to block this from going out. Really good important stuff!

✅ ✅ ✅ ✅

"Sorry, an unexpected error in our system occured when trying to save your subscription. If this continues to happen, you may email <email>[email protected]</email>. Error: <sendy_error/>",
server:
"Failed to subscribe, due to a server error. Please try again later.",
already_subscribed: "This email address has already been subscribed.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm ok with this since it's fixing a bug with the formatting, but we should probably get sign off from design / content on the final text

}

export async function subscribeEmailAction(
t: TFn,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if the real solution here is to just pass along the strings that the function needs rather than passing down the entire "t" function. That would likely mean passing a lot of strings, though, or basically partially recreating the messaging object in order to pass through just what we need. In any case I'm still worried about the entire message object getting sent down to the client, but not enough to continue blocking this PR, especially since I don't see an immediately ideal solution otherwise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was the solution I took as we moved to the app router: https://github.com/HHS/simpler-grants-gov/blob/2024.4.25-1/frontend/src/app/search/page.tsx#L51 . It is OK for small examples, but kind of got cumbersome for whole pages (can't find an example).

prevState: sendyResponse,
formData: FormData,
) {
const t = await getTranslations();
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we do

Suggested change
const t = await getTranslations();
const t = await getTranslations("Subscribe");

do we only close over that part of the messaging object? if so that could be a nice middle ground here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

await getTranslations("Subscribe"); caused a linting error.

@acouch acouch merged commit fa3aabd into main Oct 29, 2024
13 checks passed
@acouch acouch deleted the acouch/issue-1362-testing-form branch October 29, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation frontend typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E: Remove Sendy API and Update the Newsletter Form to use server actions
3 participants