Skip to content

Commit

Permalink
Website: Survey page (fixing bugs) (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhn authored Dec 10, 2024
1 parent c68376d commit ee9617c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#react-survey {
--primary: #fbc700;
--background: #ffffff;
--background-dim: #f3f3f3;
--background-dim: transparent;
--background-dim-light: #f9f9f9;
--primary-foreground: #ffffff;
--foreground: #161616;
Expand Down
4 changes: 3 additions & 1 deletion website/src/components/i18n-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { useI18n } from '@/components/providers/context-providers';
import { useIsPage } from '@/hooks/useIsPage';
import { WebsiteCurrency, WebsiteLanguage, WebsiteRegion } from '@/i18n';
import { CurrencyDollarIcon } from '@heroicons/react/24/outline';
import { GlobeEuropeAfricaIcon, LanguageIcon } from '@heroicons/react/24/solid';
Expand Down Expand Up @@ -48,6 +49,7 @@ export function I18nDialog({
translations,
children,
}: PropsWithChildren<I18nDialogProps>) {
const isSurveyPage = useIsPage('survey');
const [open, setOpen] = useState(false);
const { language, setLanguage, region, setRegion, currency, setCurrency } = useI18n();

Expand All @@ -74,7 +76,7 @@ export function I18nDialog({
</Select>
)}

{!_.isEmpty(regions) && (
{!_.isEmpty(regions) && !isSurveyPage && (
<Select value={region} onValueChange={(c: WebsiteRegion) => setRegion(c)}>
<SelectTrigger className="space-x-2">
<GlobeEuropeAfricaIcon className="h-4 w-4" />
Expand Down
6 changes: 4 additions & 2 deletions website/src/components/tracking/cookie-consent-banner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { useIsPage } from '@/hooks/useIsPage';
import { Button, Card, CardContent, Typography } from '@socialincome/ui';
import { ConsentStatusString } from 'firebase/analytics';
import { useEffect, useState } from 'react';
Expand All @@ -13,12 +14,13 @@ type CookieConsentBannerClientProps = {
};

export function CookieConsentBanner({ translations }: CookieConsentBannerClientProps) {
const isSurveyPage = useIsPage('survey');
const [hideBanner, setHideBanner] = useState(true);

useEffect(() => {
const cookieConsent = localStorage.getItem('cookie_consent');
setHideBanner(Boolean(cookieConsent));
}, [setHideBanner]);
setHideBanner(Boolean(cookieConsent) || isSurveyPage);
}, [isSurveyPage, setHideBanner]);

const setCookieConsent = (mode: ConsentStatusString) => {
localStorage.setItem('cookie_consent', mode);
Expand Down
12 changes: 12 additions & 0 deletions website/src/hooks/useIsPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { usePathname } from 'next/navigation';

export function useIsPage(page: string) {
const pathname = usePathname();
// URL structure: /[lang]/[region]/[page]
const segments = pathname.split('/');

// If `page` is blank and `segments` length is less than 4, it’s the home page
if (!page) return segments.length < 4;

return segments.length >= 4 ? segments[3] === page : false;
}

0 comments on commit ee9617c

Please sign in to comment.