-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Askem feedback buttons (HL-922)
- Loading branch information
Showing
11 changed files
with
186 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { ASKEM_SCRIPT_URL } from '../constants'; | ||
import { canShowAskem } from '../utils/cookie'; | ||
|
||
export const useAskem = ( | ||
lang: string | undefined, | ||
isSubmittedApplication: boolean, | ||
isLoading: boolean | ||
): boolean => { | ||
const showAskem = canShowAskem(lang); | ||
useEffect(() => { | ||
if (!canShowAskem || isLoading) { | ||
return () => {}; | ||
} | ||
|
||
const script = document.createElement('script'); | ||
// eslint-disable-next-line scanjs-rules/assign_to_src | ||
script.src = ASKEM_SCRIPT_URL; | ||
script.type = 'text/javascript'; | ||
|
||
window.rnsData = { | ||
apiKey: process.env.NEXT_PUBLIC_ASKEM_API_KEY, | ||
title: 'Helsinki-lisä', | ||
canonicalUrl: window.location.href, | ||
}; | ||
|
||
document.body.append(script); | ||
return () => { | ||
script.remove(); | ||
}; | ||
}, [lang, isSubmittedApplication, isLoading, showAskem]); | ||
return showAskem; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getLastCookieValue } from 'shared/cookies/get-last-cookie-value'; | ||
|
||
import type { ConsentsCookie } from '../types/common'; | ||
|
||
const parseConsentsCookie = (): ConsentsCookie | undefined => { | ||
const consentsCookieEncoded = getLastCookieValue( | ||
'city-of-helsinki-cookie-consents' | ||
); | ||
if (!consentsCookieEncoded) { | ||
return undefined; | ||
} | ||
const consentsCookieString = decodeURIComponent(consentsCookieEncoded); | ||
return JSON.parse(consentsCookieString) as ConsentsCookie; | ||
}; | ||
|
||
export const canShowAskem = (lang: string): boolean => { | ||
const consentsCookie = parseConsentsCookie(); | ||
return consentsCookie && consentsCookie.rns && lang === 'fi'; | ||
}; |