diff --git a/jam-ui/cypress/e2e/account/change-email-confirm-page.cy.js b/jam-ui/cypress/e2e/account/change-email-confirm-page.cy.js index 9cdb5448f..829a45c74 100644 --- a/jam-ui/cypress/e2e/account/change-email-confirm-page.cy.js +++ b/jam-ui/cypress/e2e/account/change-email-confirm-page.cy.js @@ -8,6 +8,7 @@ describe('Change Email Confirm Page', () => { email: 'sam@example.com' }); cy.stubAuthenticate({ ...currentUser }); + cy.intercept('POST', /\S+\/update_email/, { statusCode: 200, body: { ok: true } }); }); it('should display the confirm page when visiting the confirm URL', () => { @@ -15,7 +16,7 @@ describe('Change Email Confirm Page', () => { const token = 'dummy-confirm-token'; // Visit the confirm URL - cy.visit(`/public/confirm-email-change?token=${token}`); + cy.visit(`/confirm-email-change?token=${token}`); // Assert that the JKChangeEmailConfirm page is rendered // Adjust selectors/texts as per your actual component diff --git a/jam-ui/cypress/e2e/home/unsubscribe.cy.js b/jam-ui/cypress/e2e/home/unsubscribe.cy.js index d018ba172..1f85a6c40 100644 --- a/jam-ui/cypress/e2e/home/unsubscribe.cy.js +++ b/jam-ui/cypress/e2e/home/unsubscribe.cy.js @@ -1,24 +1,31 @@ /// +import makeFakeUser from '../../factories/user'; + describe('Unsubscribe from email link', () => { - beforeEach(() =>{ + beforeEach(() => { // cy.intercept('POST', /\S+\/unsubscribe_user_match\/\S+/, { statusCode: 200, body: { ok: true } }); + const currentUser = makeFakeUser({ + email: 'sam@example.com' + }); + cy.stubAuthenticate({ ...currentUser }); cy.intercept('POST', /\S+\/unsubscribe\/\S+/, { statusCode: 200, body: { ok: true } }); }) it("redirect to home page if tok is not provided", () => { - cy.visit('/public/unsubscribe'); + cy.visit('/unsubscribe'); cy.location('pathname').should('eq', '/errors/404'); }); it("show unsubscribed message", () => { - cy.visit('/public/unsubscribe/123'); + cy.visit('/unsubscribe/123'); // cy.location('search') // .should('equal', '?tok=123') // .then((s) => new URLSearchParams(s)) // .invoke('get', 'tok') // .should('equal', '123') - cy.contains("Unsubscribe from JamKazam emails") + cy.contains("You have successfully unsubscribed from JamKazam emails.").should('be.visible'); + cy.contains("Loading...").should('not.exist'); }); }) \ No newline at end of file diff --git a/jam-ui/src/components/dashboard/JKDashboardMain.js b/jam-ui/src/components/dashboard/JKDashboardMain.js index c5cb2255c..356825a0b 100644 --- a/jam-ui/src/components/dashboard/JKDashboardMain.js +++ b/jam-ui/src/components/dashboard/JKDashboardMain.js @@ -55,6 +55,9 @@ import JKMyJamTracks from '../jamtracks/JKMyJamTracks'; import JKJamTrackShow from '../jamtracks/JKJamTrackShow'; import JKPayPalConfirmation from '../shopping-cart/JKPayPalConfirmation'; +import JKUnsubscribe from '../public/JKUnsubscribe'; +import JKConfirmEmailChange from '../public/JKConfirmEmailChange'; + //import loadable from '@loadable/component'; //const DashboardRoutes = loadable(() => import('../../layouts/JKDashboardRoutes')); @@ -319,6 +322,8 @@ function JKDashboardMain() { + + {/*Redirect*/} diff --git a/jam-ui/src/components/public/JKConfirmEmailChange.js b/jam-ui/src/components/public/JKConfirmEmailChange.js index 1029eff38..2d0c33ff7 100644 --- a/jam-ui/src/components/public/JKConfirmEmailChange.js +++ b/jam-ui/src/components/public/JKConfirmEmailChange.js @@ -3,13 +3,17 @@ import { useLocation } from "react-router-dom"; import { Card, CardBody, CardText, CardTitle } from 'reactstrap'; import { useState, useEffect } from 'react'; import { updateEmail } from '../../helpers/rest'; +import { useTranslation } from 'react-i18next'; const JKConfirmEmailChange = () => { + const { t } = useTranslation("account"); const location = useLocation(); const params = new URLSearchParams(location.search); const token = params.get('token'); const [success, setSuccess] = useState(false); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); useEffect(() => { if (token) { @@ -23,6 +27,9 @@ const JKConfirmEmailChange = () => { }) .catch(() => { setSuccess(false); + setError(t('identity.changed_email_confirmation.error')); + }).finally(() => { + setLoading(false); }); } }, [token]); @@ -31,15 +38,13 @@ const JKConfirmEmailChange = () => { - Change Email Confirmation + {t('identity.changed_email_confirmation.title')} - - { - success? - 'Your email has been successfully updated.' : - 'Loading...' - } - + <> + {loading &&
{t('identity.changed_email_confirmation.loading')}
} + {success &&
{t('identity.changed_email_confirmation.success')}
} + {error &&
{error}
} +
) diff --git a/jam-ui/src/components/public/JKUnsubscribe.js b/jam-ui/src/components/public/JKUnsubscribe.js index 54704abe2..b26def779 100644 --- a/jam-ui/src/components/public/JKUnsubscribe.js +++ b/jam-ui/src/components/public/JKUnsubscribe.js @@ -1,16 +1,18 @@ import React, { useEffect, useState } from 'react'; -import { Card, CardBody, CardText, CardTitle } from 'reactstrap'; -import { useTranslation } from "react-i18next"; +import { Card, CardBody, CardText, CardTitle } from 'reactstrap'; +import { useTranslation } from 'react-i18next'; import { useBrowserQuery } from '../../context/BrowserQuery'; import { useHistory, useParams } from "react-router-dom"; const unsubscribeFromNewUsersWeeklyEmail = (token) => { - + + + const baseUrl = process.env.REACT_APP_CLIENT_BASE_URL return new Promise((resolve, reject) => { - fetch(`${baseUrl}/unsubscribe_user_match/${token}`, + fetch(`${baseUrl}/unsubscribe_user_match/${token}`, { method: 'POST' } ).then(response => { if (response.ok) { @@ -25,53 +27,61 @@ const unsubscribeFromNewUsersWeeklyEmail = (token) => { const unsubscribe = (token) => { const baseUrl = process.env.REACT_APP_CLIENT_BASE_URL return new Promise((resolve, reject) => { - fetch(`${baseUrl}/unsubscribe/${token}`, { method: 'POST' }) - .then(response => { - if(response.ok){ - resolve(response) - } else { - reject(response) - } - }) + fetch(`${baseUrl}/unsubscribe/${token}`, { method: 'POST', headers: { 'Content-Type': 'application/json', accept: 'application/json' } }) + .then(response => { + if (response.ok) { + resolve(response) + } else { + reject(response) + } + }).catch(error => { + reject(error); + }); }) } function JKUnsubscribe() { - const {t} = useTranslation() - const queryObj = useBrowserQuery(); + const { t } = useTranslation("unsubscribe"); const history = useHistory() + const [loading, setLoading] = useState(true) const [success, setSuccess] = useState(false) + const [error, setError] = useState(null) const { tok } = useParams(); + useEffect(() => { - if(tok){ + if (tok) { unsubscribe(tok) - .then((resp) => { - if(resp.ok){ - setSuccess(true) - } - }) - .catch(error => console.error(error)) - }else{ + .then((resp) => { + if (resp.ok) { + setSuccess(true) + } else { + setSuccess(false) + } + }) + .catch(error => { + setError(error) + }).finally(() => { + setLoading(false) + }); + } else { history.push('/') } }, []) - + return ( - - + - Unsubscribe from JamKazam emails - - { - success? - 'You have been unsubscribed from all JamKazam emails. You will no longer receive any emails from JamKazam.' : - 'Unsubscribing...' - } - + {t('page_title')} + <> + {loading &&
{t('loading')}
} + {success &&
{t('success')}
} + {error &&
{t('error')}
} + +
- + ) } diff --git a/jam-ui/src/i18n/locales/en/account.json b/jam-ui/src/i18n/locales/en/account.json index 5e80c50e6..e0d30b5be 100644 --- a/jam-ui/src/i18n/locales/en/account.json +++ b/jam-ui/src/i18n/locales/en/account.json @@ -26,6 +26,12 @@ "confirmation_email_sent": "A confirmation email has been sent to your email address. Please click the link in the email to confirm your email address." } }, + "changed_email_confirmation": { + "title": "Change Email Confirmation", + "loadding": "Loading...", + "success": "Your email has been successfully changed.", + "error": "An error occurred while confirming your email change. Please try again later." + }, "password_form": { "title": "Password", "help_text": "To update the password associated with your account, enter your current password (for security reasons) and the new password, and click the \"Save Password\" button.", diff --git a/jam-ui/src/i18n/locales/en/unsubscribe.json b/jam-ui/src/i18n/locales/en/unsubscribe.json index 23293c247..3e552d7cb 100644 --- a/jam-ui/src/i18n/locales/en/unsubscribe.json +++ b/jam-ui/src/i18n/locales/en/unsubscribe.json @@ -1,3 +1,6 @@ { - "page_title": "Unsubscribe" + "page_title": "Unsubscribe from JamKazam emails", + "success": "You have successfully unsubscribed from JamKazam emails.", + "error": "An error occurred while unsubscribing. Please try again later.", + "loading": "Loading..." } \ No newline at end of file diff --git a/jam-ui/src/layouts/JKPublicRoutes.js b/jam-ui/src/layouts/JKPublicRoutes.js index f4330eb0c..dd1df5eca 100644 --- a/jam-ui/src/layouts/JKPublicRoutes.js +++ b/jam-ui/src/layouts/JKPublicRoutes.js @@ -23,8 +23,8 @@ const JKPublicRoutes = ({ match: { url } }) => ( - - + {/* + */} diff --git a/ruby/lib/jam_ruby/app/views/layouts/user_mailer_beta.html.erb b/ruby/lib/jam_ruby/app/views/layouts/user_mailer_beta.html.erb index 703b915c4..ca95ba2be 100644 --- a/ruby/lib/jam_ruby/app/views/layouts/user_mailer_beta.html.erb +++ b/ruby/lib/jam_ruby/app/views/layouts/user_mailer_beta.html.erb @@ -30,7 +30,7 @@

<%= I18n.t "mailer_layout.footer.paragraph1" -%> JamKazam.
<%= I18n.t "mailer_layout.footer.you_can" -%>