Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors functions to const #70

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TeamMembers from './pages/TeamMembers/TeamMembers'

import { Routes, Route } from 'react-router-dom'

export default function App() {
const App = () => {
return (
<Routes>
{import.meta.env.NODE_ENV !== 'production' && <Route path='/login' element={<Login />} />}
Expand All @@ -26,3 +26,5 @@ export default function App() {
</Routes>
)
}

export default App
4 changes: 3 additions & 1 deletion src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom'
import { User } from '../../@types/user'
import styles from './avatar.module.scss'

export default function Avatar() {
const Avatar = () => {
const [userProfileData, setUserProfileData] = useState<User>()
const [imageSrc, setImageSrc] = useState<string>()
const [fallbackInitials, setFallbackInitials] = useState<string>('??')
Expand Down Expand Up @@ -46,3 +46,5 @@ export default function Avatar() {
</div>
)
}

export default Avatar
4 changes: 3 additions & 1 deletion src/components/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Breadcrumb as OriginalBreadcrumb } from '@statisticsnorway/ssb-componen
import { useLocation } from 'react-router-dom'
import { DaplaCtrlContext } from '../provider/DaplaCtrlProvider'

export default function Breadcrumb() {
const Breadcrumb = () => {
const location = useLocation()
const pathnames = location.pathname
.split('/')
Expand Down Expand Up @@ -34,3 +34,5 @@ export default function Breadcrumb() {

return <OriginalBreadcrumb items={items} />
}

export default Breadcrumb
4 changes: 3 additions & 1 deletion src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link } from '@statisticsnorway/ssb-component-library'
import Avatar from '../Avatar/Avatar'
import { useNavigate } from 'react-router-dom'

export default function Header() {
const Header = () => {
const navigate = useNavigate()

return (
Expand All @@ -19,3 +19,5 @@ export default function Header() {
</div>
)
}

export default Header
4 changes: 3 additions & 1 deletion src/components/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface PageLayoutProps {
content?: JSX.Element
}

export default function PageLayout({ title, button, content }: PageLayoutProps) {
const PageLayout = ({ title, button, content }: PageLayoutProps) => {
return (
<>
<Header />
Expand All @@ -25,3 +25,5 @@ export default function PageLayout({ title, button, content }: PageLayoutProps)
</>
)
}

export default PageLayout
2 changes: 1 addition & 1 deletion src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface TableData {
}[]
}

function conditionalStyling(index: number) {
const conditionalStyling = (index: number) => {
// Add conditional styling for the first element, then third etc
return (index + 1) % 2 !== 0 ? styles.greenBackground : undefined
}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { validateKeycloakToken } from '../../services/validateKeycloakToken'
import { getUserProfile, getUserProfileFallback } from '../../services/userProfile'
import { jwtRegex } from '../../utils/regex'

export default function Login() {
const Login = () => {
const [error, setError] = useState(false)
const [value, setValue] = useState('')

Expand Down Expand Up @@ -92,3 +92,5 @@ export default function Login() {
</div>
)
}

export default Login
4 changes: 3 additions & 1 deletion src/pages/NotFound/NotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import notFoundStyles from './notFound.module.scss'

import { Title } from '@statisticsnorway/ssb-component-library'

export default function NotFound() {
const NotFound = () => {
return (
<div className={notFoundStyles.centerDiv}>
<Title size={1} className={notFoundStyles.title}>
Expand All @@ -14,3 +14,5 @@ export default function NotFound() {
</div>
)
}

export default NotFound
10 changes: 6 additions & 4 deletions src/pages/TeamDetail/TeamDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Text, Link, Dialog, LeadParagraph } from '@statisticsnorway/ssb-compone
import PageSkeleton from '../../components/PageSkeleton/PageSkeleton'
import { Skeleton } from '@mui/material'

export default function TeamDetail() {
const TeamDetail = () => {
const { setBreadcrumbTeamDetailDisplayName } = useContext(DaplaCtrlContext)
const [error, setError] = useState<ErrorResponse | undefined>()
const [loadingTeamData, setLoadingTeamData] = useState<boolean>(true)
Expand Down Expand Up @@ -79,7 +79,7 @@ export default function TeamDetail() {
setBreadcrumbTeamDetailDisplayName({ displayName })
}, [teamDetailData, setBreadcrumbTeamDetailDisplayName])

function renderUsernameColumn(user: User) {
const renderUsernameColumn = (user: User) => {
return (
<>
<span>
Expand All @@ -92,15 +92,15 @@ export default function TeamDetail() {
)
}

function renderErrorAlert() {
const renderErrorAlert = () => {
return (
<Dialog type='warning' title='Could not fetch data'>
{error?.error.message}
</Dialog>
)
}

function renderContent() {
const renderContent = () => {
if (error) return renderErrorAlert()
if (loadingTeamData) return <PageSkeleton hasDescription hasTab={false} /> // TODO: Remove hasTab prop after tabs are implemented

Expand Down Expand Up @@ -153,3 +153,5 @@ export default function TeamDetail() {
/>
)
}

export default TeamDetail
10 changes: 6 additions & 4 deletions src/pages/TeamOverview/TeamOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Team } from '../../@types/team'
import { getTeamOverview, TeamOverviewData } from '../../services/teamOverview'
import { formatDisplayName } from '../../utils/utils'

export default function TeamOverview() {
const TeamOverview = () => {
const defaultActiveTab = {
title: 'Mine team',
path: 'myTeams',
Expand Down Expand Up @@ -71,7 +71,7 @@ export default function TeamOverview() {
}
}

function renderTeamNameColumn(team: Team) {
const renderTeamNameColumn = (team: Team) => {
return (
<>
<span>
Expand All @@ -84,15 +84,15 @@ export default function TeamOverview() {
)
}

function renderErrorAlert() {
const renderErrorAlert = () => {
return (
<Dialog type='warning' title='Could not fetch teams'>
{error?.error.message}
</Dialog>
)
}

function renderContent() {
const renderContent = () => {
if (error) return renderErrorAlert()
if (loading) return <PageSkeleton />

Expand Down Expand Up @@ -135,3 +135,5 @@ export default function TeamOverview() {

return <PageLayout title='Teamoversikt' content={renderContent()} />
}

export default TeamOverview
10 changes: 6 additions & 4 deletions src/pages/UserProfile/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useParams } from 'react-router-dom'
import { ErrorResponse } from '../../@types/error'
import { Skeleton } from '@mui/material'

export default function UserProfile() {
const UserProfile = () => {
const { setBreadcrumbUserProfileDisplayName } = useContext(DaplaCtrlContext)
const [error, setError] = useState<ErrorResponse | undefined>()
const [loadingTeamData, setLoadingTeamData] = useState<boolean>(true)
Expand Down Expand Up @@ -81,7 +81,7 @@ export default function UserProfile() {
}
}, [userProfileData, setBreadcrumbUserProfileDisplayName])

function renderTeamNameColumn(team: Team) {
const renderTeamNameColumn = (team: Team) => {
return (
<>
<span>
Expand All @@ -94,15 +94,15 @@ export default function UserProfile() {
)
}

function renderErrorAlert() {
const renderErrorAlert = () => {
return (
<Dialog type='warning' title='Could not fetch data'>
{error?.error.message}
</Dialog>
)
}

function renderContent() {
const renderContent = () => {
if (error) return renderErrorAlert()
if (loadingTeamData) return <PageSkeleton hasDescription hasTab={false} /> // TODO: Remove hasTab prop after tabs are implemented

Expand Down Expand Up @@ -154,3 +154,5 @@ export default function UserProfile() {
/>
)
}

export default UserProfile