Merged in feat/LOY-424-Sidepeek-Past-Stays (pull request #3270)

feat(LOY-424): Load More Past Stays via Sidepeek

* feat(LOY-424): Load More Past Stays via Sidepeek

* chore(LOY-424): use new section header

* fix(LOY-424): remove uneeded nextCursor check


Approved-by: Emma Zettervall
This commit is contained in:
Chuma Mcphoy (We Ahead)
2025-12-03 15:19:25 +00:00
parent c6fff09c73
commit 30b9d14fb0
8 changed files with 229 additions and 46 deletions

View File

@@ -0,0 +1,29 @@
import { dt } from "@scandic-hotels/common/dt"
import type { Stay } from "@scandic-hotels/trpc/routers/user/output"
export interface StaysByYear {
year: number
stays: Stay[]
}
/**
* Groups stays by year based on checkinDate.
* @returns an array sorted by year in descending order (most recent first).
*/
export function groupStaysByYear(stays: Stay[]): StaysByYear[] {
const groupedMap = new Map<number, Stay[]>()
for (const stay of stays) {
const year = dt(stay.attributes.checkinDate).year()
if (!groupedMap.has(year)) {
groupedMap.set(year, [])
}
groupedMap.get(year)!.push(stay)
}
return Array.from(groupedMap.entries())
.sort(([yearA], [yearB]) => yearB - yearA)
.map(([year, stays]) => ({ year, stays }))
}