unsubscribe page
add page in new website to be shown to the users when they follow unsubscribe link (in email footer)
This commit is contained in:
parent
a8d5b8e735
commit
b7a41c6465
|
|
@ -2,22 +2,23 @@
|
||||||
|
|
||||||
describe('Unsubscribe from email link', () => {
|
describe('Unsubscribe from email link', () => {
|
||||||
beforeEach(() =>{
|
beforeEach(() =>{
|
||||||
cy.intercept('POST', /\S+\/unsubscribe_user_match\/\S+/, { statusCode: 200, body: { ok: true } });
|
// cy.intercept('POST', /\S+\/unsubscribe_user_match\/\S+/, { statusCode: 200, body: { ok: true } });
|
||||||
|
cy.intercept('POST', /\S+\/unsubscribe\/\S+/, { statusCode: 200, body: { ok: true } });
|
||||||
})
|
})
|
||||||
|
|
||||||
it("redirect to home page if tok is not provided", () => {
|
it("redirect to home page if tok is not provided", () => {
|
||||||
cy.visit('/unsubscribe');
|
cy.visit('/public/unsubscribe');
|
||||||
cy.location('pathname').should('eq', '/');
|
cy.location('pathname').should('eq', '/errors/404');
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only("show unsubscribed message", () => {
|
it("show unsubscribed message", () => {
|
||||||
cy.visit('/unsubscribe?tok=123');
|
cy.visit('/public/unsubscribe/123');
|
||||||
cy.location('search')
|
// cy.location('search')
|
||||||
.should('equal', '?tok=123')
|
// .should('equal', '?tok=123')
|
||||||
.then((s) => new URLSearchParams(s))
|
// .then((s) => new URLSearchParams(s))
|
||||||
.invoke('get', 'tok')
|
// .invoke('get', 'tok')
|
||||||
.should('equal', '123')
|
// .should('equal', '123')
|
||||||
cy.contains("successfully unsubscribed")
|
cy.contains("Unsubscribe from JamKazam emails")
|
||||||
});
|
});
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
@ -2,12 +2,12 @@ import React, { useEffect, useState } from 'react';
|
||||||
import { Card, CardBody, CardText, CardTitle } from 'reactstrap';
|
import { Card, CardBody, CardText, CardTitle } from 'reactstrap';
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useBrowserQuery } from '../../context/BrowserQuery';
|
import { useBrowserQuery } from '../../context/BrowserQuery';
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory, useParams } from "react-router-dom";
|
||||||
|
|
||||||
|
|
||||||
const unsubscribeFromNewUsersWeeklyEmail = (token) => {
|
const unsubscribeFromNewUsersWeeklyEmail = (token) => {
|
||||||
|
|
||||||
const baseUrl = process.env.REACT_APP_LEGACY_BASE_URL
|
const baseUrl = process.env.REACT_APP_CLIENT_BASE_URL
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch(`${baseUrl}/unsubscribe_user_match/${token}`,
|
fetch(`${baseUrl}/unsubscribe_user_match/${token}`,
|
||||||
|
|
@ -22,16 +22,29 @@ 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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function JKUnsubscribe() {
|
function JKUnsubscribe() {
|
||||||
const {t} = useTranslation()
|
const {t} = useTranslation()
|
||||||
const queryObj = useBrowserQuery();
|
const queryObj = useBrowserQuery();
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
const [success, setSuccess] = useState(false)
|
const [success, setSuccess] = useState(false)
|
||||||
|
const { tok } = useParams();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const token = queryObj.get('tok')
|
if(tok){
|
||||||
if(token){
|
unsubscribe(tok)
|
||||||
unsubscribeFromNewUsersWeeklyEmail(token)
|
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
if(resp.ok){
|
if(resp.ok){
|
||||||
setSuccess(true)
|
setSuccess(true)
|
||||||
|
|
@ -46,13 +59,13 @@ function JKUnsubscribe() {
|
||||||
return (
|
return (
|
||||||
|
|
||||||
|
|
||||||
<Card color={ success ? 'success' : 'light' } style={{ width: '25rem', margin: '2rem auto' }}>
|
<Card style={{ width: '25rem', margin: '2rem auto' }}>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<CardTitle className="mb-2">Unsubscribe From Weekly Email</CardTitle>
|
<CardTitle className="mb-2">Unsubscribe from JamKazam emails</CardTitle>
|
||||||
<CardText>
|
<CardText>
|
||||||
{
|
{
|
||||||
success?
|
success?
|
||||||
'You have successfully unsubscribed from weekly emails on newly joined musicians having low internet latency to you.' :
|
'You have been unsubscribed from all JamKazam emails. You will no longer receive any emails from JamKazam.' :
|
||||||
'Unsubscribing...'
|
'Unsubscribing...'
|
||||||
}
|
}
|
||||||
</CardText>
|
</CardText>
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ const JKPublicRoutes = ({ match: { url } }) => (
|
||||||
<Route path={`${url}/knowledge-base`} component={JKKnowledgeBase} />
|
<Route path={`${url}/knowledge-base`} component={JKKnowledgeBase} />
|
||||||
<Route path={`${url}/help-desk`} component={JKHelpDesk} />
|
<Route path={`${url}/help-desk`} component={JKHelpDesk} />
|
||||||
<Route path={`${url}/forum`} component={JKForum} />
|
<Route path={`${url}/forum`} component={JKForum} />
|
||||||
<Route path={`${url}/unsubscribe`} exact component={JKUnsubscribe} />
|
<Route path={`${url}/unsubscribe/:tok`} exact component={JKUnsubscribe} />
|
||||||
<Route path={`${url}/downloads`} exact component={JKDownloads} />
|
<Route path={`${url}/downloads`} exact component={JKDownloads} />
|
||||||
<Route path={`${url}/downloads-legacy`} exact component={JKDownloadsLegacy} />
|
<Route path={`${url}/downloads-legacy`} exact component={JKDownloadsLegacy} />
|
||||||
<Route path={`${url}/obs-plugin-download`} exact component={JKObsDownloads} />
|
<Route path={`${url}/obs-plugin-download`} exact component={JKObsDownloads} />
|
||||||
|
|
|
||||||
|
|
@ -450,7 +450,11 @@ JS
|
||||||
@user.save!
|
@user.save!
|
||||||
#end
|
#end
|
||||||
|
|
||||||
render text: 'You have been unsubscribed.'
|
respond_to do |format|
|
||||||
|
format.html { render text: 'You have been unsubscribed.' }
|
||||||
|
format.json { render json: { status: 'success', message: 'You have been unsubscribed.' } }
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsubscribe_user_match
|
def unsubscribe_user_match
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,14 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do
|
||||||
methods: [:get],
|
methods: [:get],
|
||||||
credentials: true
|
credentials: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
allow do
|
||||||
|
origins Rails.configuration.spa_origin_url
|
||||||
|
|
||||||
|
resource '/unsubscribe/*',
|
||||||
|
headers: :any,
|
||||||
|
methods: [:get, :post, :put, :delete, :options],
|
||||||
|
credentials: true
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Loading…
Reference in New Issue