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

MNTOR-3556: Front end integration #4995

Merged
merged 22 commits into from
Sep 13, 2024
Merged

MNTOR-3556: Front end integration #4995

merged 22 commits into from
Sep 13, 2024

Conversation

mansaj
Copy link
Collaborator

@mansaj mansaj commented Aug 29, 2024

An example for @codemist to help integrate

Visit localhost:6060/unsubscribe-email/monthly-report-free

@mansaj mansaj changed the base branch from main to MNTOR-1800-2 August 29, 2024 21:35
Copy link

@mansaj mansaj added the 🛑 Do Not Merge Do not merge this PR, even if approved. label Aug 29, 2024
@codemist codemist requested review from codemist and removed request for codemist August 30, 2024 12:19
@codemist codemist changed the title MNTOR-3556: MNTOR-3556: Front end integration Sep 5, 2024
@codemist codemist marked this pull request as ready for review September 5, 2024 11:56
@codemist codemist requested a review from flodolo as a code owner September 5, 2024 11:56
Base automatically changed from MNTOR-1800-2 to main September 5, 2024 16:19
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a specific reason to keep these strings isolated in a separate file?

Copy link
Collaborator

@codemist codemist Sep 10, 2024

Choose a reason for hiding this comment

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

These strings exist on a dedicated/separate page, similar to limitations-apply-premium.ftl.

@codemist codemist requested a review from Vinnl September 10, 2024 13:19
Comment on lines 33 to 72
const handleUnsubscription = async () => {
try {
const response = await fetch(`/api/unsubscribe?token=${token}`, {
method: "GET",
});

if (response.ok) {
setUnsubscribeSuccess(true);
}
} catch (e) {
console.error("Error during unsubscription:", e);
}
};

Copy link
Collaborator

@codemist codemist Sep 10, 2024

Choose a reason for hiding this comment

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

@mansaj You mentioned that we don't need a unsuccessful state if the unsubscription doesn't work, so do we still need this if (response.ok) logic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I'm understanding this correctly, this is calling the API? If so, yes, we do have to handle both success and failure. There are three possible responses: 200, 400, or 500

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fixed in 48443a6

Copy link
Collaborator

Choose a reason for hiding this comment

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

Added a react-toastify component here, which should handle the error state.

Comment on lines 33 to 72
const handleUnsubscription = async () => {
try {
const response = await fetch(`/api/unsubscribe?token=${token}`, {
method: "GET",
});

if (response.ok) {
setUnsubscribeSuccess(true);
}
} catch (e) {
console.error("Error during unsubscription:", e);
}
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I'm understanding this correctly, this is calling the API? If so, yes, we do have to handle both success and failure. There are three possible responses: 200, 400, or 500


const handleUnsubscription = async () => {
try {
const response = await fetch(`/api/unsubscribe?token=${token}`, {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this url correct? The API is at api/v1/user/unsubscribe-email?

Copy link
Collaborator

@codemist codemist Sep 10, 2024

Choose a reason for hiding this comment

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

Ah, you're right! Fixed in 05d3925

Comment on lines 40 to 44
if (session?.user?.subscriber) {
const unsubLink = await generateUnsubscribeLinkForSubscriber(
session.user.subscriber,
);
console.info({ unsubLink });
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 is only for testing right? I think we should only generate the link when the email is crafted

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should remove after testing, because everytime generateUnsubscribeLinkForSubscriber is called, it replaces the old token

Copy link
Collaborator

Choose a reason for hiding this comment

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

fixed in e7d4bd5

@codemist codemist requested a review from flozia September 11, 2024 17:37
@codemist codemist removed the 🛑 Do Not Merge Do not merge this PR, even if approved. label Sep 11, 2024
Comment on lines 25 to 30
<ToastContainer
position="top-center"
theme="colored"
autoClose={false}
toastClassName={styles.toastBody}
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

@flozia @Vinnl Added the react-toastify container here in the main shell. In future components, we should be able to just call toast("Message here").

Copy link
Collaborator

@Vinnl Vinnl left a comment

Choose a reason for hiding this comment

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

I have one blocker, unfortunately: we'll want to put the settings checkbox behind a flag (for free users), so that we can hide it until we've actually added the email.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we move this to /unsubscribe-email/monthly-report-free/page.tsx? Just to have some URL consistency with future email unsubscribes, and potentially being able to handle them all with a single route? I also imagine we'll want to allow someone to unsubscribe from all emails in one go at some point, which could then be handled by plain /unsubscribe-email/.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fixed in 84c36c4

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Vinnl For some reason this broke the override CSS styles for the toast component...

@codemist
Copy link
Collaborator

@Vinnl Good call - added a feature flag MonthlyReportFreeUser here: 344025a

mansaj and others added 6 commits September 12, 2024 10:00
* fix: gurantee boolean value

* fix: update should upsert too

* fix: delete primary_email field

* fix: remove dup primary_email from new table

* fix: generate the link for the unsub page instead

* feat: some example code for FE

* extract data from the right table

* Unsubscription from monthly report confirmation page

* pass in the right function

* fix unit tests

* fix unit tests

---------

Co-authored-by: Joey Zhou <[email protected]>
<Button
variant="link"
onPress={() => void handleUnsubscription()}
<button
Copy link
Collaborator

@codemist codemist Sep 12, 2024

Choose a reason for hiding this comment

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

I decided to resort to a default <button> element here as opposed to using the pre-made Button component + link variant because this is a unique button that's in white, which would require overriding the blue-set colour to the link <Button> variant.

@codemist codemist requested review from Vinnl and flodolo September 12, 2024 14:41
Copy link
Collaborator

@flozia flozia left a comment

Choose a reason for hiding this comment

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

This looks good to me and seems to work as intended — good job!

@codemist codemist merged commit 3e66114 into main Sep 13, 2024
15 checks passed
@codemist codemist deleted the MNTOR-3556 branch September 13, 2024 15:19
Copy link

Cleanup completed - database 'blurts-server-pr-4995' destroyed, cloud run service 'blurts-server-pr-4995' destroyed

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.

5 participants