Merged in fix/intl-global-error (pull request #1510)

Fix: Error message when copy fail. Null check on localstorage. Removed Intl from global-error.tsx

* Error message if failed to copy

* Use try/catch instead


Approved-by: Joakim Jäderberg
This commit is contained in:
Linus Flood
2025-03-11 10:49:56 +00:00
parent 2ef2b2e28d
commit 7563db9dbc
11 changed files with 26 additions and 11 deletions

View File

@@ -2,7 +2,6 @@
import * as Sentry from "@sentry/nextjs"
import { useEffect } from "react"
import { useIntl } from "react-intl"
import styles from "./global-error.module.css"
@@ -13,8 +12,6 @@ export default function GlobalError({
}) {
console.log({ global_error: error })
const intl = useIntl()
useEffect(() => {
Sentry.captureException(error)
}, [error])
@@ -23,7 +20,7 @@ export default function GlobalError({
<html>
<body>
<div className={styles.layout}>
<h1>{intl.formatMessage({ id: "Something went really wrong!" })}</h1>
<h1>Something went really wrong!</h1>
</div>
</body>
</html>

View File

@@ -14,10 +14,14 @@ export default function CopyButton({ membershipNumber }: CopyButtonProps) {
const intl = useIntl()
function handleCopy() {
navigator.clipboard.writeText(membershipNumber)
toast.success(
intl.formatMessage({ id: "Membership ID copied to clipboard" })
)
try {
navigator.clipboard.writeText(membershipNumber)
toast.success(
intl.formatMessage({ id: "Membership ID copied to clipboard" })
)
} catch {
toast.error(intl.formatMessage({ id: "Failed to copy" }))
}
}
return (

View File

@@ -42,8 +42,12 @@ export default function Campaign() {
<footer className={styles.modalFooter}>
<Button
onClick={() => {
navigator.clipboard.writeText(reward.operaRewardId)
toast.success(intl.formatMessage({ id: "Copied to clipboard" }))
try {
navigator.clipboard.writeText(reward.operaRewardId)
toast.success(intl.formatMessage({ id: "Copied to clipboard" }))
} catch {
toast.error(intl.formatMessage({ id: "Failed to copy" }))
}
}}
type="button"
variant="icon"

View File

@@ -167,7 +167,9 @@ export default function BookingWidgetClient({
}, [methods, selectedLocation])
useEffect(() => {
if (typeof window !== "undefined" && !selectedBookingCode) {
if (!window?.sessionStorage || !window?.localStorage) return
if (!selectedBookingCode) {
const storedBookingCode = localStorage.getItem("bookingCode")
const initialBookingCode: BookingCodeSchema | undefined =
storedBookingCode && isValidJson(storedBookingCode)

View File

@@ -131,6 +131,8 @@ export default function Search({ locations, handlePressEnter }: SearchProps) {
}
useEffect(() => {
if (!window?.sessionStorage || !window?.localStorage) return
const searchData = sessionStorage.getItem(sessionStorageKey)
const searchHistory = localStorage.getItem(localStorageKey)
const payload: SetStorageData["payload"] = {}

View File

@@ -236,6 +236,7 @@
"Extras to your booking": "Tillæg til din booking",
"FAQ": "Ofte stillede spørgsmål",
"Failed to add to calendar": "Fejl ved tilføjelse til kalender",
"Failed to copy": "Kunne ikke kopiere",
"Failed to delete credit card, please try again later.": "Kunne ikke slette kreditkort. Prøv venligst igen senere.",
"Failed to submit form, please try again later.": "Failed to submit form, please try again later.",
"Failed to unlink account": "Failed to unlink account",

View File

@@ -237,6 +237,7 @@
"Extras to your booking": "Extras zu Ihrer Buchung",
"FAQ": "Häufig gestellte Fragen",
"Failed to add to calendar": "Fehler beim Hinzufügen zum Kalender",
"Failed to copy": "Kopieren fehlgeschlagen",
"Failed to delete credit card, please try again later.": "Kreditkarte konnte nicht gelöscht werden. Bitte versuchen Sie es später noch einmal.",
"Failed to submit form, please try again later.": "Failed to submit form, please try again later.",
"Failed to unlink account": "Failed to unlink account",

View File

@@ -241,6 +241,7 @@
"Extras to your booking": "Extras to your booking",
"FAQ": "FAQ",
"Failed to add to calendar": "Failed to add to calendar",
"Failed to copy": "Failed to copy",
"Failed to delete credit card, please try again later.": "Failed to delete credit card, please try again later.",
"Failed to submit form, please try again later.": "Failed to submit form, please try again later.",
"Failed to unlink account": "Failed to unlink account",

View File

@@ -236,6 +236,7 @@
"Extras to your booking": "Varauksessa lisäpalveluita",
"FAQ": "Usein kysytyt kysymykset",
"Failed to add to calendar": "Virhe kalenteriin lisäämisessä",
"Failed to copy": "Kopiointi epäonnistui",
"Failed to delete credit card, please try again later.": "Luottokortin poistaminen epäonnistui, yritä myöhemmin uudelleen.",
"Failed to submit form, please try again later.": "Failed to submit form, please try again later.",
"Failed to unlink account": "Failed to unlink account",

View File

@@ -235,6 +235,7 @@
"Extras to your booking": "Tilvalg til bestillingen din",
"FAQ": "Ofte stilte spørsmål",
"Failed to add to calendar": "Feil ved tilføyelse til kalender",
"Failed to copy": "Kunne ikke kopiere",
"Failed to delete credit card, please try again later.": "Kunne ikke slette kredittkortet, prøv igjen senere.",
"Failed to submit form, please try again later.": "Failed to submit form, please try again later.",
"Failed to unlink account": "Failed to unlink account",

View File

@@ -235,6 +235,7 @@
"Extras to your booking": "Extra tillval till din bokning",
"FAQ": "FAQ",
"Failed to add to calendar": "Misslyckades att lägga till i kalender",
"Failed to copy": "Kunde inte kopiera",
"Failed to delete credit card, please try again later.": "Det gick inte att ta bort kreditkortet, försök igen senare.",
"Failed to submit form, please try again later.": "Failed to submit form, please try again later.",
"Failed to unlink account": "Failed to unlink account",