From 08be7866a5b736dc0b9a822b262bfb357fbc9c26 Mon Sep 17 00:00:00 2001 From: james-a-morris Date: Wed, 11 Jun 2025 16:45:46 -0400 Subject: [PATCH 1/2] feat(newsletter): handle already subscribed users gracefully - Add detection for already subscribed users in response - Set custom message for already subscribed state - Treat already subscribed as successful subscription Signed-off-by: james-a-morris --- src/app/_components/subscribe-section.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app/_components/subscribe-section.tsx b/src/app/_components/subscribe-section.tsx index 6e82f78..d79f99c 100644 --- a/src/app/_components/subscribe-section.tsx +++ b/src/app/_components/subscribe-section.tsx @@ -34,9 +34,16 @@ export function SubscribeSection(props: { variant: "aqua" | "teal" | "purple" }) "Content-Type": "application/json", }, }); - setResponseMsg(await response.text()); + const responseMsg = await response.text(); + const userAlreadySubscribed = responseMsg.toLowerCase().includes("already a list member"); - if (response.ok) { + if (userAlreadySubscribed) { + setResponseMsg("Already subscribed"); + } else { + setResponseMsg(responseMsg); + } + + if (response.ok || userAlreadySubscribed) { setStatus("success"); } else { setStatus("error"); From b9097f9cb0a5b9969abc606866606ec8b0c5c86a Mon Sep 17 00:00:00 2001 From: james-a-morris Date: Wed, 11 Jun 2025 16:47:38 -0400 Subject: [PATCH 2/2] chore: lint Signed-off-by: james-a-morris --- src/app/_components/subscribe-section.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/_components/subscribe-section.tsx b/src/app/_components/subscribe-section.tsx index d79f99c..e851779 100644 --- a/src/app/_components/subscribe-section.tsx +++ b/src/app/_components/subscribe-section.tsx @@ -35,7 +35,9 @@ export function SubscribeSection(props: { variant: "aqua" | "teal" | "purple" }) }, }); const responseMsg = await response.text(); - const userAlreadySubscribed = responseMsg.toLowerCase().includes("already a list member"); + const userAlreadySubscribed = responseMsg + .toLowerCase() + .includes("already a list member"); if (userAlreadySubscribed) { setResponseMsg("Already subscribed");