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

feat: RV Eventing on Payment Page #19

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: Remove uniqueness from events in AlertMessage
julianajlk committed Nov 1, 2024
commit d63254d9d8cfd1e5046850cc8a823723a66cb48d
31 changes: 11 additions & 20 deletions src/feedback/AlertMessage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {
useCallback, useEffect, useRef, useState,
useCallback, useEffect, useRef,
} from 'react';
import { useDispatch } from 'react-redux';
import PropTypes from 'prop-types';
@@ -24,30 +24,21 @@ const AlertMessage = (props) => {

const alertRef = useRef(null);
const dispatch = useDispatch();
const [hasBeenShown, setHasBeenShown] = useState({});

// RV promo banner tracking for successful coupon application
useEffect(() => {
const observerCallback = (entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && messageType === 'success' && userMessage.includes('added to basket')) {
// Single call behavior
const elementId = entry.target?.id;
if (!hasBeenShown[elementId]) {
const tagularElement = {
title: PaymentTitle,
url: entry.target?.baseURI,
pageType: 'checkout',
elementType: ElementType.Button,
name: 'promotional-code',
text: 'Apply',
};
dispatch(trackElementIntersection(tagularElement));
setHasBeenShown(prevState => ({
...prevState,
[elementId]: true,
}));
}
const tagularElement = {
title: PaymentTitle,
url: entry.target?.baseURI,
pageType: 'checkout',
elementType: ElementType.Button,
name: 'promotional-code',
text: 'Apply',
};
dispatch(trackElementIntersection(tagularElement));
}
});
};
@@ -68,7 +59,7 @@ const AlertMessage = (props) => {
}
observer.disconnect();
};
}, [messageType, userMessage, hasBeenShown, dispatch]);
}, [messageType, userMessage, dispatch]);

const statusAlertProps = {
variant: ALERT_TYPES.WARNING,