forked from polka_billy/porridger
Implemented UserPage
This commit is contained in:
45
front/src/assets/userCategories.ts
Normal file
45
front/src/assets/userCategories.ts
Normal file
@ -0,0 +1,45 @@
|
||||
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 }
|
Reference in New Issue
Block a user