diff --git a/app/env.server.ts b/app/env.server.ts index e777723a..d20c370b 100644 --- a/app/env.server.ts +++ b/app/env.server.ts @@ -12,7 +12,7 @@ let env: ServerEnv * Initializes and parses given environment variables using zod * @returns Initialized env vars */ -export function initEnv() { +function initEnv() { // biome-ignore lint/nursery/noProcessEnv: This should be the only place to use process.env directly const envData = envSchema.safeParse(process.env) diff --git a/app/localization/i18n.ts b/app/localization/i18n.ts index ba43ac74..e42f3300 100644 --- a/app/localization/i18n.ts +++ b/app/localization/i18n.ts @@ -1,3 +1,4 @@ +import type { InitOptions } from "i18next" import { supportedLanguages } from "./resource" export default { @@ -8,4 +9,4 @@ export default { fallbackLng: "en", // The default namespace of i18next is "translation", but you can customize it here defaultNS: "common", -} +} satisfies Omit diff --git a/app/localization/resource.ts b/app/localization/resource.ts index 539801c7..39301aee 100644 --- a/app/localization/resource.ts +++ b/app/localization/resource.ts @@ -19,3 +19,12 @@ export const resources: Record = { common: bosnian, }, } + +declare module "i18next" { + export interface CustomTypeOptions { + defaultNS: "common" + fallbackNS: "common" + // custom resources type + resources: Resource + } +} diff --git a/app/root.tsx b/app/root.tsx index 12a011b3..0d50a40c 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -55,8 +55,24 @@ export const Layout = ({ children }: { children: React.ReactNode }) => { export const ErrorBoundary = () => { const error = useRouteError() const { t } = useTranslation() - - const errorStatusCode = isRouteErrorResponse(error) ? error.status : "500" + // Constrain the generic type so we don't provide a non-existent key + const statusCode = () => { + if (!isRouteErrorResponse(error)) { + return "500" + } + // Supported error code messages + switch (error.status) { + case 200: + return "200" + case 403: + return "403" + case 404: + return "404" + default: + return "500" + } + } + const errorStatusCode = statusCode() return (
diff --git a/app/utils/dates.test.ts b/app/utils/dates.test.ts deleted file mode 100644 index 1f0a0b49..00000000 --- a/app/utils/dates.test.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { convertDateToUserTz, convertTz } from "app/utils/dates" - -describe("convertTz Test suite", () => { - it("should convert date to user tz if there is a difference (1h)", () => { - const date = new Date() - const serverTz = "Europe/London" - const convertedServerDate = convertTz(date, serverTz) - const userTz = "Europe/Berlin" - const convertedClientDate = convertTz(date, userTz) - const differenceInMinutes = Math.round( - Math.abs(convertedClientDate.getTime() - convertedServerDate.getTime()) / 60000 - ) - expect(differenceInMinutes).toBe(60) - }) - - it("should stay the same if no difference", () => { - const date = new Date() - const serverTz = "Europe/London" - const convertedServerDate = convertTz(date, serverTz) - const userTz = "Europe/London" - const convertedClientDate = convertTz(date, userTz) - const differenceInMinutes = Math.round( - Math.abs(convertedClientDate.getTime() - convertedServerDate.getTime()) / 60000 - ) - expect(differenceInMinutes).toBe(0) - }) -}) - -describe("convertDateToUserTz Test suite", () => { - it("should convert date to user tz if there is a difference", () => { - const request = new Request("http://localhost:3000", { - headers: { - "CH-time-zone": "Europe/London", - }, - method: "GET", - }) - const date = new Date() - const serverDate = convertTz(date, "Europe/Berlin") - const clientDate = convertDateToUserTz(date, request) - const differenceInMinutes = Math.round(Math.abs(clientDate.getTime() - serverDate.getTime()) / 60000) - expect(differenceInMinutes).toBe(60) - }) - - it("should convert date to user tz if there is a difference", () => { - const request = new Request("http://localhost:3000", { - headers: { - "CH-time-zone": "Europe/London", - }, - method: "GET", - }) - const date = new Date() - const serverDate = convertTz(date, "Europe/London") - const clientDate = convertDateToUserTz(date, request) - const differenceInMinutes = Math.round(Math.abs(clientDate.getTime() - serverDate.getTime()) / 60000) - expect(differenceInMinutes).toBe(0) - }) -}) diff --git a/app/utils/dates.ts b/app/utils/dates.ts index e8905772..2a319df3 100644 --- a/app/utils/dates.ts +++ b/app/utils/dates.ts @@ -1,6 +1,6 @@ import { getTimeZone } from "../services/client-hints" -export function convertTz(date: string | Date, tzString: string) { +function convertTz(date: string | Date, tzString: string) { const dateToConvert = typeof date === "string" ? new Date(date) : date // Convert to the target timezone const convertedDate = new Date(dateToConvert.toLocaleString("en-US", { timeZone: tzString }))