Feat/lokalise rebuild * chore(lokalise): update translation ids * chore(lokalise): easier to switch between projects * chore(lokalise): update translation ids * . * . * . * . * . * . * chore(lokalise): update translation ids * chore(lokalise): update translation ids * . * . * . * chore(lokalise): update translation ids * chore(lokalise): update translation ids * . * . * chore(lokalise): update translation ids * chore(lokalise): update translation ids * chore(lokalise): new translations * merge * switch to errors for missing id's * merge * sync translations Approved-by: Linus Flood
102 lines
2.4 KiB
TypeScript
102 lines
2.4 KiB
TypeScript
import type { User } from "@scandic-hotels/trpc/types/user"
|
|
import type { IntlShape } from "react-intl"
|
|
|
|
import type {
|
|
Ancillaries,
|
|
Ancillary,
|
|
SelectedAncillary,
|
|
} from "@/types/components/myPages/myStay/ancillaries"
|
|
|
|
function filterPoints(ancillaries: Ancillaries, user: User | null) {
|
|
return ancillaries.map((ancillary) => {
|
|
return {
|
|
...ancillary,
|
|
ancillaryContent: ancillary.ancillaryContent.map(
|
|
({ points, ...ancillary }) => ({
|
|
...ancillary,
|
|
points: user ? points : undefined,
|
|
})
|
|
),
|
|
}
|
|
})
|
|
}
|
|
|
|
export function generateUniqueAncillaries(
|
|
ancillaries: Ancillaries
|
|
): Ancillary["ancillaryContent"] {
|
|
const uniqueAncillaries = new Map(
|
|
ancillaries.flatMap((a) => {
|
|
return a.ancillaryContent.map((ancillary) => [ancillary.id, ancillary])
|
|
})
|
|
)
|
|
return [...uniqueAncillaries.values()]
|
|
}
|
|
|
|
/**
|
|
* Adds the breakfast package to the ancillaries
|
|
*
|
|
* Returns the ancillaries array with the breakfast package added to the
|
|
* specified category. If the category doesn't exist it's created.
|
|
*/
|
|
function addBreakfastPackage(
|
|
ancillaries: Ancillaries,
|
|
breakfast: SelectedAncillary | undefined,
|
|
internalCategoryName: string,
|
|
translatedCategoryName: string
|
|
): Ancillaries {
|
|
if (!breakfast) return ancillaries
|
|
|
|
const category = ancillaries.find(
|
|
(a) => a.internalCategoryName === internalCategoryName
|
|
)
|
|
if (category) {
|
|
const newCategory = {
|
|
...category,
|
|
ancillaryContent: [breakfast, ...category.ancillaryContent],
|
|
}
|
|
|
|
return ancillaries.map((ancillary) =>
|
|
ancillary.internalCategoryName === internalCategoryName
|
|
? newCategory
|
|
: ancillary
|
|
)
|
|
}
|
|
|
|
return [
|
|
{
|
|
internalCategoryName,
|
|
translatedCategoryName,
|
|
ancillaryContent: [breakfast],
|
|
},
|
|
...ancillaries,
|
|
]
|
|
}
|
|
|
|
export function mapAncillaries(
|
|
intl: IntlShape,
|
|
ancillaries: Ancillaries | null,
|
|
breakfastAncillary: SelectedAncillary | undefined,
|
|
user: User | null
|
|
) {
|
|
const withBreakfastPopular = addBreakfastPackage(
|
|
ancillaries ?? [],
|
|
breakfastAncillary,
|
|
"Popular",
|
|
intl.formatMessage({
|
|
defaultMessage: "Popular",
|
|
id: "myStay.ancillaries.popularCategory",
|
|
})
|
|
)
|
|
const withBreakfastFood = addBreakfastPackage(
|
|
withBreakfastPopular,
|
|
breakfastAncillary,
|
|
"Food",
|
|
intl.formatMessage({
|
|
id: "common.food",
|
|
defaultMessage: "Food",
|
|
})
|
|
)
|
|
|
|
return filterPoints(withBreakfastFood, user)
|
|
}
|