Skip to content
Snippets Groups Projects
Commit b7b11aa0 authored by Marte Fossum's avatar Marte Fossum
Browse files

Merge branch 'GREG-316-show-end-date-for-role' into 'master'

Show end date for role and filter on status

See merge request !373
parents 82c03b52 0035ab9b
No related branches found
No related tags found
1 merge request!373Show end date for role and filter on status
Pipeline #177993 passed
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
"firstName": "First name", "firstName": "First name",
"lastName": "Last name", "lastName": "Last name",
"dateOfBirth": "Date of birth", "dateOfBirth": "Date of birth",
"endDate": "End date",
"name": "Name", "name": "Name",
"role": "Guest role", "role": "Guest role",
"period": "Period", "period": "Period",
......
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
"firstName": "Fornavn", "firstName": "Fornavn",
"lastName": "Etternavn", "lastName": "Etternavn",
"dateOfBirth": "Fødselsdato", "dateOfBirth": "Fødselsdato",
"endDate": "Sluttdato",
"name": "Navn", "name": "Navn",
"role": "Gjesterolle", "role": "Gjesterolle",
"period": "Periode", "period": "Periode",
......
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
"firstName": "Fornamn", "firstName": "Fornamn",
"lastName": "Etternamn", "lastName": "Etternamn",
"dateOfBirth": "Fødselsdato", "dateOfBirth": "Fødselsdato",
"endDate": "Sluttdato",
"name": "Namn", "name": "Namn",
"role": "Gjesterolle", "role": "Gjesterolle",
"period": "Periode", "period": "Periode",
......
...@@ -8,6 +8,7 @@ import { appInst } from 'appConfig' ...@@ -8,6 +8,7 @@ import { appInst } from 'appConfig'
interface IPage { interface IPage {
children: React.ReactNode children: React.ReactNode
header?: string header?: string
pageWidth?: boolean
} }
let faviconPath = '' let faviconPath = ''
...@@ -30,7 +31,7 @@ switch (appInst) { ...@@ -30,7 +31,7 @@ switch (appInst) {
} }
export default function Page(props: IPage) { export default function Page(props: IPage) {
const { header, children } = props const { header, children, pageWidth } = props
const { i18n, t } = useTranslation() const { i18n, t } = useTranslation()
const appTitle = t('common:header:applicationTitle') const appTitle = t('common:header:applicationTitle')
...@@ -42,7 +43,7 @@ export default function Page(props: IPage) { ...@@ -42,7 +43,7 @@ export default function Page(props: IPage) {
<title>{header}</title> <title>{header}</title>
</Helmet> </Helmet>
<Container <Container
maxWidth="md" maxWidth={pageWidth ? 'lg' : 'md'}
sx={{ paddingBottom: '2rem', paddingTop: '2rem' }} sx={{ paddingBottom: '2rem', paddingTop: '2rem' }}
> >
{header ? <Typography variant="h1">{header}</Typography> : <></>} {header ? <Typography variant="h1">{header}</Typography> : <></>}
...@@ -54,4 +55,5 @@ export default function Page(props: IPage) { ...@@ -54,4 +55,5 @@ export default function Page(props: IPage) {
Page.defaultProps = { Page.defaultProps = {
header: null, header: null,
pageWidth: false,
} }
import React, { useState } from 'react' import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward'
import NotificationsActiveIcon from '@mui/icons-material/NotificationsActive'
import { import {
Accordion,
AccordionDetails,
AccordionSummary,
Button,
Paper,
Table, Table,
TableBody, TableBody,
TableCell, TableCell,
TableContainer, TableContainer,
TableHead, TableHead,
TableRow, TableRow,
Paper,
Accordion,
AccordionSummary,
AccordionDetails,
Button,
Typography, Typography,
} from '@mui/material' } from '@mui/material'
import NotificationsActiveIcon from '@mui/icons-material/NotificationsActive'
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward'
import { styled } from '@mui/system' import { styled } from '@mui/system'
import { useState } from 'react'
import Page from 'components/page' import Page from 'components/page'
import { useTranslation, Trans } from 'react-i18next' import { differenceInDays, format, isBefore } from 'date-fns'
import { Link } from 'react-router-dom'
import { Guest, Role } from 'interfaces' import { Guest, Role } from 'interfaces'
import { differenceInDays, isBefore } from 'date-fns' import { Trans, useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom'
import { getRoleName, getRoleOuName } from 'utils' import { getRoleName, getRoleOuName } from 'utils'
import SponsorGuestButtons from '../../components/sponsorGuestButtons' import SponsorGuestButtons from '../../components/sponsorGuestButtons'
...@@ -42,6 +42,7 @@ interface StatusProps { ...@@ -42,6 +42,7 @@ interface StatusProps {
interface GuestTableProps { interface GuestTableProps {
guests: Guest[] guests: Guest[]
emptyText: string emptyText: string
marginWidth: number
} }
interface FrontPageProps { interface FrontPageProps {
...@@ -60,6 +61,7 @@ const StyledTableRow = styled(TableRow)({ ...@@ -60,6 +61,7 @@ const StyledTableRow = styled(TableRow)({
const StyledAccordion = styled(Accordion)({ const StyledAccordion = styled(Accordion)({
borderStyle: 'none', borderStyle: 'none',
boxShadow: 'none', boxShadow: 'none',
margin: 'auto',
}) })
const StyledAccordionSummary = styled(AccordionSummary)({ const StyledAccordionSummary = styled(AccordionSummary)({
...@@ -165,6 +167,41 @@ const Status = ({ person, role }: StatusProps) => { ...@@ -165,6 +167,41 @@ const Status = ({ person, role }: StatusProps) => {
} }
} }
const sortByDate = (
guestRole: { guest: Guest; role: Role }[]
): { guest: Guest; role: Role }[] =>
guestRole.sort(
(a, b) => a.role.end_date.getTime() - b.role.end_date.getTime()
)
const sortByStatus = (guests: Guest[]): { guest: Guest; role: Role }[] => {
let activeRoleAndPerson: { guest: Guest; role: Role }[] = []
let expiringRoleAndPerson: { guest: Guest; role: Role }[] = []
let expiredRoleAndPerson: { guest: Guest; role: Role }[] = []
let status
guests.forEach((guest) =>
guest.roles.forEach((role) => {
;[status] = calculateStatus(guest, role)
if (status === 'active') {
activeRoleAndPerson.push({ guest, role })
} else if (status === 'expiring') {
expiringRoleAndPerson.push({ guest, role })
} else {
expiredRoleAndPerson.push({ guest, role })
}
})
)
activeRoleAndPerson = sortByDate(activeRoleAndPerson)
expiringRoleAndPerson = sortByDate(expiringRoleAndPerson)
expiredRoleAndPerson = sortByDate(expiredRoleAndPerson)
return expiringRoleAndPerson
.concat(activeRoleAndPerson)
.concat(expiredRoleAndPerson)
}
const PersonLine = ({ person, role }: PersonLineProps) => { const PersonLine = ({ person, role }: PersonLineProps) => {
const [t] = useTranslation(['common']) const [t] = useTranslation(['common'])
...@@ -175,6 +212,7 @@ const PersonLine = ({ person, role }: PersonLineProps) => { ...@@ -175,6 +212,7 @@ const PersonLine = ({ person, role }: PersonLineProps) => {
</TableCell> </TableCell>
<TableCell align="left">{getRoleName(role)}</TableCell> <TableCell align="left">{getRoleName(role)}</TableCell>
<Status person={person} role={role} /> <Status person={person} role={role} />
<TableCell align="left"> {format(role.end_date, 'yyyy-MM-dd')}</TableCell>
<TableCell align="left">{getRoleOuName(role)}</TableCell> <TableCell align="left">{getRoleOuName(role)}</TableCell>
<TableCell align="left"> <TableCell align="left">
<Button <Button
...@@ -190,35 +228,38 @@ const PersonLine = ({ person, role }: PersonLineProps) => { ...@@ -190,35 +228,38 @@ const PersonLine = ({ person, role }: PersonLineProps) => {
) )
} }
const GuestTable = ({ guests, emptyText }: GuestTableProps) => { const GuestTable = ({ guests, emptyText, marginWidth }: GuestTableProps) => {
const { t } = useTranslation('common') const { t } = useTranslation('common')
return ( return (
<TableContainer <TableContainer
component={Paper} component={Paper}
sx={{ boxShadow: 'none', borderRadius: '0rem' }} sx={{
boxShadow: 'none',
borderRadius: '0rem',
minWidth: marginWidth,
}}
> >
<Table sx={{ minWidth: 650 }} aria-label="simple table"> <Table sx={{ minWidth: marginWidth }} aria-label="simple table">
<StyledTableHead> <StyledTableHead>
<TableRow> <TableRow>
<StyledTableHeadCell>{t('common:name')}</StyledTableHeadCell> <StyledTableHeadCell>{t('common:name')}</StyledTableHeadCell>
<StyledTableHeadCell>{t('common:role')}</StyledTableHeadCell> <StyledTableHeadCell>{t('common:role')}</StyledTableHeadCell>
<StyledTableHeadCell>{t('common:status')}</StyledTableHeadCell> <StyledTableHeadCell>{t('common:status')}</StyledTableHeadCell>
<StyledTableHeadCell>{t('common:endDate')}</StyledTableHeadCell>
<StyledTableHeadCell>{t('common:department')}</StyledTableHeadCell> <StyledTableHeadCell>{t('common:department')}</StyledTableHeadCell>
<StyledTableHeadCell /> <StyledTableHeadCell />
</TableRow> </TableRow>
</StyledTableHead> </StyledTableHead>
<TableBody> <TableBody>
{guests.length > 0 ? ( {guests.length > 0 ? (
guests.map((person) => sortByStatus(guests).map((personRole) => (
person.roles.map((role) => ( <PersonLine
<PersonLine key={`${personRole.guest.first} ${personRole.guest.last} ${personRole.role.id}`}
key={`${person.first} ${person.last} ${role.id}`} role={personRole.role}
role={role} person={personRole.guest}
person={person} />
/> ))
))
)
) : ( ) : (
<StyledTableRow> <StyledTableRow>
<TableCell> {emptyText}</TableCell> <TableCell> {emptyText}</TableCell>
...@@ -261,7 +302,11 @@ const InvitedGuests = ({ persons }: GuestProps) => { ...@@ -261,7 +302,11 @@ const InvitedGuests = ({ persons }: GuestProps) => {
> >
{t('common:sentInvitationsDescription')} {t('common:sentInvitationsDescription')}
</Typography> </Typography>
<GuestTable guests={guests} emptyText={t('common:noInvitations')} /> <GuestTable
guests={guests}
emptyText={t('common:noInvitations')}
marginWidth={650}
/>
</AccordionDetails> </AccordionDetails>
</StyledAccordion> </StyledAccordion>
) )
...@@ -297,7 +342,11 @@ const ActiveGuests = ({ persons }: GuestProps) => { ...@@ -297,7 +342,11 @@ const ActiveGuests = ({ persons }: GuestProps) => {
> >
{t('common:activeGuestsDescription')} {t('common:activeGuestsDescription')}
</Typography> </Typography>
<GuestTable guests={guests} emptyText={t('common:noActiveGuests')} /> <GuestTable
guests={guests}
emptyText={t('common:noActiveGuests')}
marginWidth={1000}
/>
</AccordionDetails> </AccordionDetails>
</StyledAccordion> </StyledAccordion>
) )
...@@ -342,7 +391,11 @@ const WaitingGuests = ({ persons }: GuestProps) => { ...@@ -342,7 +391,11 @@ const WaitingGuests = ({ persons }: GuestProps) => {
Gjester som har FEIDE-bruker trenger ikke godkjenning. Gjester som har FEIDE-bruker trenger ikke godkjenning.
</Trans> </Trans>
</Typography> </Typography>
<GuestTable guests={guests} emptyText={t('common:noWaitingGuests')} /> <GuestTable
guests={guests}
emptyText={t('common:noWaitingGuests')}
marginWidth={650}
/>
</AccordionDetails> </AccordionDetails>
</StyledAccordion> </StyledAccordion>
) )
...@@ -350,7 +403,7 @@ const WaitingGuests = ({ persons }: GuestProps) => { ...@@ -350,7 +403,7 @@ const WaitingGuests = ({ persons }: GuestProps) => {
function FrontPage({ guests }: FrontPageProps) { function FrontPage({ guests }: FrontPageProps) {
return ( return (
<Page> <Page pageWidth>
<SponsorGuestButtons yourGuestsActive /> <SponsorGuestButtons yourGuestsActive />
<InvitedGuests persons={guests} /> <InvitedGuests persons={guests} />
<br /> <br />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment