Fix routes

This commit is contained in:
adam-skowronek 2022-12-16 01:43:00 +01:00
parent 25355be9ff
commit bd256e0f44
3 changed files with 29 additions and 5 deletions

View File

@ -70,8 +70,11 @@ function App() {
<Route path="supervisor" element={<Supervisor />}>
<Route index element={<Navigate to="groups" />} />
<Route path="groups" element={<Groups />} />
<Route path="groups/:id" element={<Group />} />
<Route path="groups/:id/grade-card" element={<GradeCard />} />
<Route path="schedule" element={<SupervisorSchedules />} />
<Route path="schedule/:id" element={<SupervisorSchedule />} />
<Route path="add-group" element={<AddGroup />} />
</Route>
</Routes>
</QueryClientProvider>

View File

@ -1,9 +1,10 @@
import { useQuery } from 'react-query'
import { Link, useParams } from 'react-router-dom'
import { Link, useLocation, useParams } from 'react-router-dom'
import { getGroup } from '../../api/groups'
const Group = () => {
const { id } = useParams<{ id: string }>()
const location = useLocation()
const { data: groups } = useQuery(['getGroup'], () => getGroup(Number(id)))
const { name, project_supervisor } = groups?.data || {}
@ -15,7 +16,13 @@ const Group = () => {
Opiekun: {project_supervisor?.first_name}{' '}
{project_supervisor?.last_name}
</h2>
<Link to={`/coordinator/groups/${id}/grade-card`}>
<Link
to={`/${
location.pathname.includes('coordinator')
? 'coordinator'
: 'supervisor'
}/groups/${id}/grade-card`}
>
<button className="btn btn-success mt-2">KARTA OCENY</button>
</Link>
</div>

View File

@ -1,7 +1,7 @@
import classNames from 'classnames'
import { useEffect, useState } from 'react'
import { useMutation, useQuery } from 'react-query'
import { useNavigate } from 'react-router-dom'
import { useLocation, useNavigate } from 'react-router-dom'
import useLocalStorageState from 'use-local-storage-state'
import { deleteGroup, getGroups } from '../../api/groups'
import { ReactComponent as IconRemove } from '../../assets/svg/icon-remove.svg'
@ -9,6 +9,8 @@ import { Link } from 'react-router-dom'
const Groups = () => {
let navigate = useNavigate()
const location = useLocation()
const [page, setPage] = useState(1)
const [perPage, setPerPage] = useState(10)
const [yearGroupId] = useLocalStorageState('yearGroupId')
@ -60,7 +62,15 @@ const Groups = () => {
<div className="flex items-center justify-between flex-col gap-3 md:flex-row md:gap-0">
<button
className="btn btn-success"
onClick={() => navigate('/coordinator/add-group')}
onClick={() =>
navigate(
`/${
location.pathname.includes('coordinator')
? 'coordinator'
: 'supervisor'
}/add-group`,
)
}
>
Dodaj nową grupę
</button>
@ -97,7 +107,11 @@ const Groups = () => {
<tr key={id}>
<td>
<Link
to={`/coordinator/groups/${id}`}
to={`/${
location.pathname.includes('coordinator')
? 'coordinator'
: 'supervisor'
}/groups/${id}`}
className="underline font-bold"
>
{name}