Skip to content

Commit

Permalink
Merge branch 'main' into update-address-forms-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-alexsaiannyi committed Jul 15, 2024
2 parents 4fe2829 + e648a62 commit af76b31
Show file tree
Hide file tree
Showing 26 changed files with 251 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-poets-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Add store selector page.
24 changes: 24 additions & 0 deletions core/app/[locale]/store-selector/_components/locale-link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Link } from '~/components/link';
import { localeLanguageRegionMap, LocaleType } from '~/i18n';
import { cn } from '~/lib/utils';

export const LocaleLink = ({ locale, selected }: { locale: LocaleType; selected: boolean }) => {
return (
<Link
className={cn(
'border border-gray-200 px-3 py-2 text-xs hover:bg-gray-100 hover:text-black',
selected && 'border-black',
)}
href="/"
locale={locale}
>
<div className="flex h-full items-center gap-2">
<div className="text-2xl">{localeLanguageRegionMap[locale].flag}</div>
<div className="flex flex-col gap-1">
<span className="font-bold">{localeLanguageRegionMap[locale].language}</span>
<span>{localeLanguageRegionMap[locale].region}</span>
</div>
</div>
</Link>
);
};
76 changes: 76 additions & 0 deletions core/app/[locale]/store-selector/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';

import { client } from '~/client';
import { graphql } from '~/client/graphql';
import { Link } from '~/components/link';
import { StoreLogo, StoreLogoFragment } from '~/components/store-logo';
import { NavigationMenu, NavigationMenuLink } from '~/components/ui/navigation-menu';
import { locales, LocaleType } from '~/i18n';

import { LocaleLink } from './_components/locale-link';

export const metadata = {
title: 'Location selector',
};

const StoreSelectorPageQuery = graphql(
`
query LocationSelectorPageQuery {
site {
settings {
...StoreLogoFragment
}
}
}
`,
[StoreLogoFragment],
);

export default async function StoreSelector({
params: { locale: selectedLocale },
}: {
params: { locale: LocaleType };
}) {
unstable_setRequestLocale(selectedLocale);

const t = await getTranslations('StoreSelector');

const { data } = await client.fetch({
document: StoreSelectorPageQuery,
});

const storeSettings = data.site.settings;

return (
<>
<header>
<NavigationMenu>
<NavigationMenuLink asChild>
{storeSettings && (
<Link className="p-0" href="/">
<StoreLogo data={storeSettings} />
</Link>
)}
</NavigationMenuLink>
</NavigationMenu>
</header>

<div className="flex flex-col gap-2 px-4 lg:container sm:px-10 lg:mx-auto lg:max-w-[1000px] lg:px-12">
<h1 className="text-3xl font-black lg:text-4xl">{t('heading')}</h1>

<div className="grid grid-cols-1 gap-6 py-6 md:grid-cols-3 md:gap-11 lg:grid-cols-4 lg:gap-8">
{locales.map((locale) => (
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
<LocaleLink key={locale} locale={locale} selected={selectedLocale === locale} />
))}
</div>
</div>
</>
);
}

export function generateStaticParams() {
return locales.map((locale) => ({ locale }));
}

export const dynamic = 'force-static';
16 changes: 14 additions & 2 deletions core/components/footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CategoryFooterMenuFragment,
} from './footer-menus';
import { WebPageFooterMenu, WebPageFooterMenuFragment } from './footer-menus/web-page-footer-menu';
import { Locale } from './locale';
import { PaymentMethods } from './payment-methods';
import { SocialIcons, SocialIconsFragment } from './social-icons';

Expand Down Expand Up @@ -69,10 +70,21 @@ export const Footer = ({ data }: Props) => {
</div>
</FooterSection>

<FooterSection className="flex flex-col justify-between gap-10 sm:flex-row sm:gap-8 sm:py-6">
<PaymentMethods />
<FooterSection className="flex flex-col gap-10 sm:gap-8 sm:py-6 lg:hidden">
<Locale />

<div className="flex w-full flex-col justify-between gap-10 sm:flex-row sm:gap-8">
<PaymentMethods />
{data.settings && <Copyright data={data.settings} />}
</div>
</FooterSection>

<FooterSection className="hidden justify-between gap-8 py-6 lg:flex">
{data.settings && <Copyright data={data.settings} />}
<div className="flex gap-8">
<Locale />
<PaymentMethods />
</div>
</FooterSection>
</ComponentsFooter>
);
Expand Down
20 changes: 20 additions & 0 deletions core/components/footer/locale.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getLocale } from 'next-intl/server';

import { localeLanguageRegionMap, locales, LocaleType } from '~/i18n';

import { Link } from '../link';

export const Locale = async () => {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const locale = (await getLocale()) as LocaleType;

return (
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
locales.length > 1 && (
<Link className="flex gap-2" href="/store-selector">
<span>{localeLanguageRegionMap[locale].flag}</span>
<span>{localeLanguageRegionMap[locale].region}</span>
</Link>
)
);
};
71 changes: 52 additions & 19 deletions core/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,62 @@ enum LocalePrefixes {
ASNEEDED = 'as-needed', // removes prefix on default locale
}

// Enable locales by including them here
// List includes locales with existing messages support
const locales = [
'da',
'en',
'es-419',
'es-AR',
'es-CL',
'es-CO',
'es-LA',
'es-MX',
'es-PE',
'es',
'it',
'nl',
'pl',
'pt',
'de',
'fr',
'ja',
'no',
'pt-BR',
'sv',
// 'da',
// 'es-419',
// 'es-AR',
// 'es-CL',
// 'es-CO',
// 'es-LA',
// 'es-MX',
// 'es-PE',
// 'es',
// 'it',
// 'nl',
// 'pl',
// 'pt',
// 'de',
// 'fr',
// 'ja',
// 'no',
// 'pt-BR',
// 'sv',
] as const;

type LocaleLanguageRegionMap = {
[key in LocaleType]: { language: string; region: string; flag: string };
};

/**
* Custom map of locale to language and region
* Temporary solution until we have a better way to include regions for all locales
*/
export const localeLanguageRegionMap: LocaleLanguageRegionMap = {
en: { language: 'English', region: 'United States', flag: '🇺🇸' },
// da: { language: 'Dansk', region: 'Danmark', flag: '🇩🇰' }
// 'es-419': { language: 'Español', region: 'America Latina', flag: '' },
// 'es-AR': { language: 'Español', region: 'Argentina', flag: '🇦🇷' },
// 'es-CL': { language: 'Español', region: 'Chile', flag: '🇨🇱' },
// 'es-CO': { language: 'Español', region: 'Colombia', flag: '🇨🇴' },
// 'es-LA': { language: 'Español', region: 'America Latina', flag: '' },
// 'es-MX': { language: 'Español', region: 'México', flag: '🇲🇽' },
// 'es-PE': { language: 'Español', region: 'Perú', flag: '🇵🇪' },
// es: { language: 'Español', region: 'España', flag: '🇪🇸' },
// it: { language: 'Italiano', region: 'Italia', flag: '🇮🇹' },
// nl: { language: 'Nederlands', region: 'Nederland', flag: '🇳🇱' },
// pl: { language: 'Polski', region: 'Polska', flag: '🇵🇱' },
// pt: { language: 'Português', region: 'Portugal', flag: '🇵🇹' },
// de: { language: 'Deutsch', region: 'Deutschland', flag: '🇩🇪' },
// fr: { language: 'Français', region: 'France', flag: '🇫🇷' },
// ja: { language: '日本語', region: '日本', flag: '🇯🇵' },
// no: { language: 'Norsk', region: 'Norge', flag: '🇳🇴' },
// 'pt-BR': { language: 'Português', region: 'Brasil', flag: '🇧🇷' },
// sv: { language: 'Svenska', region: 'Sverige', flag: '🇸🇪' },
};

type LocalePrefixesType = `${LocalePrefixes}`;

// Temporary we use NEVER prefix to prioritize accept-language header
Expand Down
3 changes: 3 additions & 0 deletions core/messages/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Behandler...",
"addedProductQuantity": "<cartLink>{CartItems, plural, =1 {1 varer} other {# varer}} tilføjet til din indkøbskurv</cartLink>",
"errorAddingProductToCart": "Fejl ved tilføjelse af produkt til indkøbskurv. Prøv igen."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Verarbeitung ...",
"addedProductQuantity": "{cartItems, plural, =1 {1 Item} other {# Items}} wurde zu<cartLink> Ihrem Warenkorb</cartLink> hinzugefügt",
"errorAddingProductToCart": "Fehler beim Hinzufügen des Produkts zum Warenkorb. Bitte versuchen Sie es erneut."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Processing...",
"addedProductQuantity": "{cartItems, plural, =1 {1 Item} other {# Items}} added to <cartLink> your cart</cartLink>",
"errorAddingProductToCart": "Error adding product to cart. Please try again."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/es-419.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Procesando…",
"addedProductQuantity": "{cartItems, plural, =1 {1 artículo} other {# artículos}} agregado(s) a <cartLink>tu carrito</cartLink>",
"errorAddingProductToCart": "Error al agregar un producto al carrito. Vuelve a intentarlo."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/es-AR.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Procesando…",
"addedProductQuantity": "{cartItems, plural, =1 {1 artículo} other {# artículos}} agregado(s) a <cartLink>tu carrito</cartLink>",
"errorAddingProductToCart": "Error al agregar un producto al carrito. Vuelve a intentarlo."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/es-CL.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Procesando…",
"addedProductQuantity": "{cartItems, plural, =1 {1 artículo} other {# artículos}} agregado(s) a <cartLink>tu carrito</cartLink>",
"errorAddingProductToCart": "Error al agregar un producto al carrito. Vuelve a intentarlo."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/es-CO.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Procesando…",
"addedProductQuantity": "{cartItems, plural, =1 {1 artículo} other {# artículos}} agregado(s) a <cartLink>tu carrito</cartLink>",
"errorAddingProductToCart": "Error al agregar un producto al carrito. Vuelve a intentarlo."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/es-LA.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Procesando…",
"addedProductQuantity": "{cartItems, plural, =1 {1 artículo} other {# artículos}} agregado(s) a <cartLink>tu carrito</cartLink>",
"errorAddingProductToCart": "Error al agregar un producto al carrito. Vuelve a intentarlo."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/es-MX.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Procesando…",
"addedProductQuantity": "{cartItems, plural, =1 {1 artículo} other {# artículos}} agregado(s) a <cartLink>tu carrito</cartLink>",
"errorAddingProductToCart": "Error al agregar un producto al carrito. Vuelve a intentarlo."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/es-PE.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Procesando…",
"addedProductQuantity": "{cartItems, plural, =1 {1 artículo} other {# artículos}} agregado(s) a <cartLink>tu carrito</cartLink>",
"errorAddingProductToCart": "Error al agregar un producto al carrito. Vuelve a intentarlo."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Procesando...",
"addedProductQuantity": "{cartItems, plural, =1 {1 Item} other {# Items}} añadidos <cartLink> al carrito</cartLink>",
"errorAddingProductToCart": "Error al añadir el producto al carrito. Inténtalo de nuevo."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Traitement en cours…",
"addedProductQuantity": "<cartLink>{CartItems, plural, =1 {1 article} other {# articles}} ajouté(s) à votre panier</cartLink>",
"errorAddingProductToCart": "Erreur lors de l'ajout d'un produit au panier. Veuillez réessayer."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Elaborazione in corso...",
"addedProductQuantity": "{cartItems, plural, =1 {1 articolo} other {# articoli}} aggiunto/i al <cartLink> carrello</cartLink>",
"errorAddingProductToCart": "Errore durante l'aggiunta del prodotto al carrello. Riprova."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "処理中...",
"addedProductQuantity": "{cartItems, plural, =1 {1 Item} other {# Items}} added to <cartLink> your cart</cartLink>",
"errorAddingProductToCart": "Error adding product to cart. Please try again."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Verwerken...",
"addedProductQuantity": "{cartItems, plural, =1 {1 item} other {# items}} toegevoegd aan <cartLink> je winkelwagen</cartLink>",
"errorAddingProductToCart": "Fout opgetreden bij het toevoegen van product aan winkelwagen. Probeer het opnieuw."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Behandler …",
"addedProductQuantity": "{cartItems, plural, =1 {1 vare} other {# varer}} lagt til i <cartLink>handlekurven din</cartLink>",
"errorAddingProductToCart": "Feil da produktet skulle legges til i handlekurven. Prøv igjen."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
3 changes: 3 additions & 0 deletions core/messages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,8 @@
"processing": "Przetwarzanie...",
"addedProductQuantity": "Dodano {cartItems, plural, =1 {1 produkt} other {# produkty(-ów)}} <cartLink>do koszyka</cartLink>",
"errorAddingProductToCart": "Błąd podczas dodawania produktu do koszyka. Spróbuj ponownie."
},
"StoreSelector": {
"heading": "Select a language and region"
}
}
Loading

0 comments on commit af76b31

Please sign in to comment.