From 35e62588b198bdfbf975be08ab1dd885dc538731 Mon Sep 17 00:00:00 2001 From: Robin Monnier Date: Thu, 3 Oct 2024 17:40:45 +0200 Subject: [PATCH] fix: use referrer from client --- components-ui/button-pro-connect/index.tsx | 22 +++++----- middleware.ts | 26 ++--------- pages/connexion/agent-public.tsx | 50 ---------------------- 3 files changed, 15 insertions(+), 83 deletions(-) delete mode 100644 pages/connexion/agent-public.tsx diff --git a/components-ui/button-pro-connect/index.tsx b/components-ui/button-pro-connect/index.tsx index 55d0778ca..cf3e180a9 100644 --- a/components-ui/button-pro-connect/index.tsx +++ b/components-ui/button-pro-connect/index.tsx @@ -1,27 +1,29 @@ 'use client'; import { logConversionEvent } from '#utils/matomo'; +import { usePathname } from 'next/navigation'; import React from 'react'; type IProps = { + shouldRedirectToReferer: boolean; event: string; - pathForRedirection?: string; }; const ButtonProConnect: React.FC = ({ + shouldRedirectToReferer = false, event = 'BTN_DEFAULT', - pathForRedirection, }) => { + const currentPath = usePathname(); + const referrer = document?.referrer; + const isFromSite = referrer.indexOf('https://annuaire-entreprises') === 0; + + const pathFrom = + shouldRedirectToReferer && isFromSite ? referrer : currentPath; + return (
- {pathForRedirection && ( - + {pathFrom && ( + )}