mirror of
https://github.com/quepasaevents/qpa-client.git
synced 2023-12-14 05:33:02 +01:00
Super user has edit link for all events
This commit is contained in:
parent
f86a0c73b4
commit
ccd2470212
1 changed files with 38 additions and 34 deletions
|
@ -1,9 +1,8 @@
|
|||
import styled from "@emotion/styled"
|
||||
import * as React from "react"
|
||||
import {hot} from "react-hot-loader"
|
||||
import {
|
||||
useAppContext} from "../../App/Context/AppContext"
|
||||
import {OccurrenceData} from "../../Event/useOccurrencesQuery"
|
||||
import { hot } from "react-hot-loader"
|
||||
import { useAppContext } from "../../App/Context/AppContext"
|
||||
import { OccurrenceData } from "../../Event/useOccurrencesQuery"
|
||||
import ListItem from "./ListItem"
|
||||
|
||||
interface Props {
|
||||
|
@ -25,7 +24,7 @@ const List = (props: Props) => {
|
|||
return 0
|
||||
})
|
||||
const days: { [day: string]: OccurrenceData[] } = {}
|
||||
sorted.forEach((occ) => {
|
||||
sorted.forEach(occ => {
|
||||
const day = occ.start.substring(0, 10)
|
||||
if (!days[day]) {
|
||||
days[day] = []
|
||||
|
@ -33,45 +32,50 @@ const List = (props: Props) => {
|
|||
days[day].push(occ)
|
||||
})
|
||||
const dayNames = Object.keys(days)
|
||||
const {me} = useAppContext()
|
||||
|
||||
const { me } = useAppContext()
|
||||
const isSuperUser = !!me.roles.find(role =>
|
||||
["admin", "embassador"].includes(role.type)
|
||||
)
|
||||
return (
|
||||
<ListRoot className={props.className}>
|
||||
{
|
||||
dayNames.map((dayName) => {
|
||||
const [year, month, day] = dayName.split("-")
|
||||
const dayDate = new Date(dayName)
|
||||
const dayNumber = dayDate.getDay()
|
||||
return (
|
||||
<DayItems key={dayName}>
|
||||
<DayName>
|
||||
<div css={{gridArea: "1/1/3/2", fontSize: 32}}>{DAY_NAMES[dayNumber]}</div>
|
||||
<div css={{gridArea: "1/2/2/3"}}>{day}-{month}</div>
|
||||
<div css={{gridArea: "2/2/3/3", letterSpacing: 2}}>{year}</div>
|
||||
</DayName>
|
||||
<Items>
|
||||
{days[dayName].map((occ) => (
|
||||
<ListItem canEdit={me && !!me.events.find((myEvent) => myEvent.id === occ.event.id)} key={occ.id}
|
||||
occurrence={occ}/>
|
||||
))}
|
||||
</Items>
|
||||
</DayItems>
|
||||
)
|
||||
})
|
||||
}
|
||||
{dayNames.map(dayName => {
|
||||
const [year, month, day] = dayName.split("-")
|
||||
const dayDate = new Date(dayName)
|
||||
const dayNumber = dayDate.getDay()
|
||||
return (
|
||||
<DayItems key={dayName}>
|
||||
<DayName>
|
||||
<div css={{ gridArea: "1/1/3/2", fontSize: 32 }}>
|
||||
{DAY_NAMES[dayNumber]}
|
||||
</div>
|
||||
<div css={{ gridArea: "1/2/2/3" }}>
|
||||
{day}-{month}
|
||||
</div>
|
||||
<div css={{ gridArea: "2/2/3/3", letterSpacing: 2 }}>{year}</div>
|
||||
</DayName>
|
||||
<Items>
|
||||
{days[dayName].map(occ => {
|
||||
const isOwner =
|
||||
me && !!me.events.find(myEvent => myEvent.id === occ.event.id)
|
||||
return (
|
||||
<ListItem canEdit={isOwner || isSuperUser} key={occ.id} occurrence={occ} />
|
||||
)
|
||||
})}
|
||||
</Items>
|
||||
</DayItems>
|
||||
)
|
||||
})}
|
||||
</ListRoot>
|
||||
)
|
||||
}
|
||||
|
||||
const ListRoot = styled.div`
|
||||
`
|
||||
const ListRoot = styled.div``
|
||||
|
||||
const Items = styled.div`
|
||||
`
|
||||
const Items = styled.div``
|
||||
|
||||
const DayName = styled.div`
|
||||
font-weight: 600;
|
||||
color: rgba(0,0,0,.6);
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
font-size: 14px;
|
||||
width: auto;
|
||||
|
||||
|
|
Loading…
Reference in a new issue