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

Website: Survey page (fixing bugs) #971

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook seems to have a quite specific use-case. It only checks for the third item in the path segments. Maybe a hook usePathnameContains(page: string) would be more re-usable?

You then still do

const isSurveyPage = usePathnameContains('/[lang]/[region]/survey');

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s a good idea, I’ll update it.

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;
}
Loading