diff --git a/frontend/src/components/StatusInput.tsx b/frontend/src/components/StatusInput.tsx index 0a5d9a7f..4aa6ab8b 100644 --- a/frontend/src/components/StatusInput.tsx +++ b/frontend/src/components/StatusInput.tsx @@ -141,7 +141,7 @@ function StatusInput({ setByValue && `Satt av ${setByValue} ${dayjs(updatedDateValue) .locale('nb') - .format('d. MMM HH:mm')}` + .format('D. MMM HH:mm')}` } disabled={!allowedToChange || isLoading} placeholder='Pick one' diff --git a/frontend/src/pages/Dashboard.tsx b/frontend/src/pages/Dashboard.tsx index a8d12917..b0a396a0 100644 --- a/frontend/src/pages/Dashboard.tsx +++ b/frontend/src/pages/Dashboard.tsx @@ -1,35 +1,182 @@ -import { Box, Button, createStyles } from '@mantine/core' +import { Box, createStyles, Transition } from '@mantine/core' +import { useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' import { CalendarEvent, FileText, Users } from 'tabler-icons-react' +import { + isApplicationPeriodActive, + getAdmissionPeriod, +} from '../services/Applications' +import isOrganizer from '../utils/isOrganizer' +import { IUserProfile, getUserProfile } from '../services/User' +import dayjs from 'dayjs' +require('dayjs/locale/nb') const useStyles = createStyles((theme) => ({ dashboardWrapper: { - margin: 0, + margin: '1rem', height: '100%', display: 'flex', flexDirection: 'column', - justifyContent: 'center', alignItems: 'center', color: 'white', }, + metroBoxWrapper: { + paddingTop: '1rem', + margin: 0, + height: '100%', + display: 'flex', + flexDirection: 'row', + gap: '1.5rem', + alignItems: 'center', + color: theme.colors.ntnui_yellow[9], + '@media (max-width: 900px)': { + display: 'flex', + flexWrap: 'wrap', + justifyContent: 'center', + alignItems: 'center', + }, + }, + metroBoxes: { + border: '2px solid ' + theme.colors.ntnui_yellow[9], + width: '170px', + borderRadius: theme.radius.sm, + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + gap: '1rem', + padding: '1rem', + cursor: 'pointer', + transition: 'ease-in-out 0.1s', + '&:active': { + transform: 'scale(0.98)', + color: '#F8F082', + boxShadow: '0 0 2px #F8F082', + }, + '&:hover': { + color: '#F8F082', + boxShadow: '0 0 10px #F8F082', + }, + }, + date: { + color: theme.colors.ntnui_blue[9], + fontWeight: '600', + textAlign: 'center', + fontSize: '1.3rem', + }, + text: { + textAlign: 'center', + fontWeight: 'lighter', + '*': { + // Icon + margin: '0 0 -3px 0', + }, + }, + header: { + fontWeight: '500', + }, + subHeader: { + fontWeight: 'lighter', + }, + loader: { + margin: '0 0 -3px 0', + }, })) function Dashboard() { const { classes } = useStyles() const navigate = useNavigate() + const [periodOpen, setPeriodOpen] = useState(true) + const [startDate, setStartDate] = useState('') + const [endDate, setEndDate] = useState('') + const [isTheOrganizer, setTheOrganizer] = useState(false) + const [isLoading, setIsLoading] = useState(false) + const [userName, setUserName] = useState() + + useEffect(() => { + setIsLoading(true) + const getDashboardDataAsync = async () => { + try { + // Get user + const user = await getUserProfile() + setUserName(user) + if (await isOrganizer()) { + setTheOrganizer(true) + } + // Check if application period active + const response = await isApplicationPeriodActive() + setPeriodOpen(response) + // If active, get application period + if (response) { + const response = await getAdmissionPeriod() + const parsedStartDate = dayjs(response.admissionPeriod.start_date) + .locale('nb') + .format('D. MMMM YYYY') + const parsedEndDate = dayjs(response.admissionPeriod.end_date) + .locale('nb') + .format('D. MMMM YYYY') + setStartDate(parsedStartDate) + setEndDate(parsedEndDate) + } + setIsLoading(false) + } catch (err) { + setIsLoading(false) + } + } + getDashboardDataAsync() + }, []) return ( -

Hei, Bolle bollesen!

- - - + + {(styles) => ( + <> +

+ + Hei, + {userName?.first_name} {userName?.last_name} + +

+

+ {periodOpen ? ( + <> + Opptaksperioden er satt + fra {startDate} til{' '} + {endDate} + + ) : ( + Det er for tiden ingen satt opptaksperiode + )} +

+
+ navigate('/applications')} + > + Søknader + + navigate('/admission-status')} + > + Opptaksstatus + + {isTheOrganizer && ( + navigate('/admission-period')} + > + Opptaksperiode + + )} +
+ + )} +
) }