Files
web/apps/scandic-web/components/Current/LangPopup/index.tsx
Anton Gunnarsson cbf9e7b7c2 Merged in chore/next15 (pull request #1999)
chore (SW-834): Upgrade to Next 15

* wip: apply codemod and upgrade swc plugin

* wip: design-system to react 19, fix issues from async (search)params

* wip: fix remaining issues from codemod

serverClient is now async because context use headers()
getLang is now async because it uses headers()

* Minor cleanup

* Inline react-material-symbols package

Package is seemingly not maintained any more and doesn't support
React 19. This copies the package source into `design-system`,
makes the necessary changes for 19 and export it for others to use.

* Fix missing awaits

* Disable modal exit animations

Enabling modal exit animations via isExiting prop is causing
modals to be rendered in "hidden" state and never unmount.
Seems to be an issue with react-aria-components,
see https://github.com/adobe/react-spectrum/issues/7563.
Can probably be fixed by rewriting to a solution similar to
https://react-spectrum.adobe.com/react-aria/examples/framer-modal-sheet.html

* Remove unstable cache implementation and use in memory cache locally

* Fix ref type in SelectFilter

* Use cloneElement to add key prop to element


Approved-by: Linus Flood
2025-06-02 11:11:50 +00:00

98 lines
2.3 KiB
TypeScript

/* eslint-disable formatjs/no-literal-string-in-jsx */
import { headers } from "next/headers"
import { Lang, localeToLang } from "@/constants/languages"
import { getLang } from "@/i18n/serverContext"
export default async function LangPopup() {
const headersList = await headers()
const preferedLang = headersList.get("Accept-Language") ?? ""
const possibleLangs = Object.keys(localeToLang)
if (!possibleLangs.includes(preferedLang)) {
return null
}
const langOfChoice: Lang = localeToLang[preferedLang as Lang]
const lang = await getLang()
if (langOfChoice === lang) {
return null
}
let language = ""
let viewIn = ""
switch (langOfChoice) {
case Lang.de:
language = "Deutsch"
viewIn = "Ansicht in"
break
case Lang.da:
language = "Dansk"
viewIn = "Se in"
break
case Lang.fi:
language = "Suomi"
viewIn = "Katso in"
break
case Lang.no:
language = "Norsk"
viewIn = "Se in"
break
case Lang.sv:
language = "Svenska"
viewIn = "Visa in"
break
}
return (
<div className="lang-popup hidden" id="lang-popup">
<a
href="#"
className="lang-popup__close"
title="Close language change popup"
>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
width="16px"
height="16px"
viewBox="0 0 16 16"
version="1.1"
style={{
stroke: "#757575",
width: "14px",
height: "14px",
display: "block",
strokeWidth: "2px",
}}
>
<title>Close</title>
<g id="web-close" fillRule="evenodd">
<line x1="0" y1="0" x2="100%" y2="100%" />
<line x1="0" y1="100%" x2="100%" y2="0" />
</g>
</svg>
</a>
<div className="lang-popup__body">
<p className="lang-popup__msg">
You are viewing our website in English, would you like to change to{" "}
{language}?
</p>
</div>
<div className="lang-popup__footer">
<a href="" className="lang-popup__cta btn btn--primary">
{viewIn} {language}
</a>
<a href="#" className="lang-popup__cancel btn btn--link">
No thanks
</a>
</div>
</div>
)
}