feat: Add TRPC procedure for hotel API, schemas, and use in hotel content page

This commit is contained in:
Chuma McPhoy
2024-07-02 15:27:07 +02:00
parent 965e093100
commit 0d5b775c24
6 changed files with 11510 additions and 36 deletions

View File

@@ -7,7 +7,7 @@ export enum Lang {
de = "de",
}
export const languages = {
export const languages: Record<Lang, string> = {
[Lang.da]: "Dansk",
[Lang.de]: "Deutsch",
[Lang.en]: "English",
@@ -16,7 +16,7 @@ export const languages = {
[Lang.sv]: "Svenska",
}
export const localeToLang = {
export const localeToLang: Record<string, Lang> = {
en: Lang.en,
"en-US": Lang.en,
"en-GB": Lang.en,
@@ -56,12 +56,6 @@ export const localeToLang = {
"se-NO": Lang.no,
} as const
export function findLang(pathname: string) {
return Object.values(Lang).find(
(l) => pathname.startsWith(`/${l}/`) || pathname === `/${l}`
)
}
export const languageSelect = [
{ label: "Danish", value: "Da" },
{ label: "German", value: "De" },
@@ -70,3 +64,38 @@ export const languageSelect = [
{ label: "Norwegian", value: "No" },
{ label: "Swedish", value: "Sv" },
]
// -- Lang util functions --
export function findLang(pathname: string) {
return Object.values(Lang).find(
(l) => pathname.startsWith(`/${l}/`) || pathname === `/${l}`
)
}
// Helper function to convert API's (e.g. the Hotel endpoint) capitalized values to Lang enum.
export function fromUppercaseToLangEnum(lang: string): Lang | undefined {
const lowerCaseLang = lang.charAt(0).toLowerCase() + lang.slice(1)
return Object.values(Lang).find((l) => l === lowerCaseLang)
}
// Helper function to convert Lang enum to uppercase
// Needed for certtain API (e.g. the Hotel endpoint).
export const toUppercaseLang = (lang: Lang): string => {
switch (lang) {
case Lang.en:
return "En"
case Lang.sv:
return "Sv"
case Lang.no:
return "No"
case Lang.fi:
return "Fi"
case Lang.da:
return "Da"
case Lang.de:
return "De"
default:
throw new Error("Invalid language")
}
}