Skip to content

Commit

Permalink
Fix error with tabs in the admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
erikao1998 committed Jun 27, 2024
1 parent ac3077b commit 2ce719d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/client/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const router = createBrowserRouter(
errorElement: <RootBoundary />,
children: [
{
index: true,
path: 'summary',
element: <Summary />,
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/client/components/Admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Admin = () => {

const pathParts = location.pathname.split('/').filter(Boolean)

const tab = pathParts.length === 1 ? 'summary' : pathParts[1]
const tab = pathParts[1] === 'entry' ? 'summary' : pathParts[1]

return (
<Box
Expand All @@ -35,7 +35,7 @@ const Admin = () => {
>
<Tab
component={Link}
to="."
to="./summary"
label={t('admin:summaryTab')}
value="summary"
/>
Expand Down
3 changes: 2 additions & 1 deletion src/client/components/Admin/Summary/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Table = ({ tableValues }: { tableValues: TableValues[] }) => {
})}
>
{columnId === 'projectName' ? (
<Link to={`./entry/${row.getValue('id')}`}>
<Link to={`/admin/entry/${row.getValue('id')}`}>
{cell.getValue<string>()}
</Link>
) : (
Expand All @@ -77,6 +77,7 @@ const Table = ({ tableValues }: { tableValues: TableValues[] }) => {
)

const handleDeleteRiskAssessment = (row: MRT_Row<TableValues>) => {
// eslint-disable-next-line no-alert
if (!window.confirm('Haluatko poistaa valitun riskiarvion?')) return

try {
Expand Down
7 changes: 2 additions & 5 deletions src/client/components/UserPage/UserEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useState } from 'react'
import { Box, Button, Tab, Tabs } from '@mui/material'
import ArrowBackIcon from '@mui/icons-material/ArrowBack'

import { Link, useLocation, useParams } from 'react-router-dom'
import { Link, useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import RenderAnswers from '../ResultPage/RenderAnswers'
import RiskTable from '../ResultPage/RiskTable'
Expand Down Expand Up @@ -51,16 +51,13 @@ const UserEntry = () => {
const { entryId } = useParams()
const { survey } = useSurvey()
const { entry } = useEntry(entryId)
const location = useLocation()
const [tabValue, setTabValue] = useState(0)
const { t } = useTranslation()

const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setTabValue(newValue)
}

const parentRoute = location.pathname.split('/')[1]

if (!entry || !survey) return null

const { answers, country, updatedData } = entry.data
Expand All @@ -69,7 +66,7 @@ const UserEntry = () => {
<Box sx={{ m: 3 }}>
<Box sx={{ width: '100%', my: 2 }}>
<Link
to={`/${parentRoute}`}
to="/admin/summary"
style={{ textDecoration: 'none', color: 'inherit' }}
>
<Button variant="outlined">
Expand Down

0 comments on commit 2ce719d

Please sign in to comment.