forked from polka_billy/porridger
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { Announcement } from '../api/announcement/types'
|
|
import { FiltersType } from '../utils/filters'
|
|
|
|
const userCategories = ['givingOut', 'booked', 'history'] as const
|
|
|
|
type UserCategory = typeof userCategories[number]
|
|
|
|
const UserCategoriesNames: Record<UserCategory, string> = {
|
|
givingOut: 'Раздача',
|
|
booked: 'Бронь',
|
|
history: 'История',
|
|
}
|
|
|
|
const userCategoriesInfos: Record<UserCategory, (ann: Announcement) => string> = {
|
|
givingOut: (ann: Announcement) => (
|
|
`Годен до ${new Date(ann.bestBy).toLocaleDateString('ru')}`
|
|
),
|
|
booked: (ann: Announcement) => (
|
|
`Бронь ещё ${(ann as Announcement & { bookedBy: number[] }).bookedBy.length} чел.`
|
|
),
|
|
history: (ann: Announcement) => (
|
|
`Забрал ${new Date((ann as Announcement & { taken: number }).taken).toLocaleDateString('ru')}`
|
|
),
|
|
}
|
|
|
|
const composeUserCategoriesFilters: Record<UserCategory, () => FiltersType> = {
|
|
givingOut: () => {
|
|
const userId = -1
|
|
|
|
return ({ userId })
|
|
},
|
|
booked: () => {
|
|
const userId = -1
|
|
|
|
return ({ bookedBy: userId })
|
|
},
|
|
history: () => {
|
|
const userId = -1
|
|
|
|
return ({ userId, status: 'taken' })
|
|
}
|
|
}
|
|
|
|
export type { UserCategory }
|
|
export { userCategories, UserCategoriesNames, userCategoriesInfos, composeUserCategoriesFilters }
|