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

Fix sonarcloud problems #902

Merged
merged 2 commits into from
May 1, 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
24 changes: 15 additions & 9 deletions apps/dashboard/src/app/(dashboard)/article/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
"use client"

import { Loader } from "@mantine/core"
import type { PropsWithChildren } from "react"
import { type PropsWithChildren, useMemo } from "react"
import { trpc } from "../../../../utils/trpc"
import { ArticleDetailsContext } from "./provider"

export default function ArticleDetailsLayout({ children, params }: PropsWithChildren<{ params: { id: string } }>) {
const { data, isLoading } = trpc.article.get.useQuery(params.id)
return (
<>
{isLoading || !data ? (
<Loader />
) : (
<ArticleDetailsContext.Provider value={{ article: data }}>{children}</ArticleDetailsContext.Provider>
)}
</>
const value = useMemo(
() =>
data === undefined || isLoading
? null
: {
article: data,
},
[data, isLoading]
)

if (value === null) {
return <Loader />
}

return <ArticleDetailsContext.Provider value={value}>{children}</ArticleDetailsContext.Provider>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Attendance } from "@dotkomonline/types"
import { Divider } from "@mantine/core"
import { Box, Title } from "@mantine/core"
import { Box, Divider, Title } from "@mantine/core"
import type { FC } from "react"
import { useAttendanceForm } from "../../../../modules/attendance/components/attendance-page/AttendanceForm"
import { InfoBox } from "../../../../modules/attendance/components/attendance-page/InfoBox"
Expand All @@ -21,7 +20,7 @@ export const AttendancePage: FC = () => {
return <NoAttendanceFallback eventId={event.id} />
}

return <_AttendancePage attendance={attendance} />
return <AttendancePageDetail attendance={attendance} />
}

const NoAttendanceFallback: FC<{ eventId: string }> = ({ eventId }) => {
Expand Down Expand Up @@ -50,7 +49,7 @@ const NoAttendanceFallback: FC<{ eventId: string }> = ({ eventId }) => {
interface EventAttendanceProps {
attendance: Attendance
}
const _AttendancePage: FC<EventAttendanceProps> = ({ attendance }) => {
const AttendancePageDetail: FC<EventAttendanceProps> = ({ attendance }) => {
const { pools } = usePoolsGetQuery(attendance.id)

const updateAttendanceMut = useUpdateAttendanceMutation()
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/app/(dashboard)/event/[id]/extras-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const ExtrasPage: FC = () => {
return <NoAttendanceFallback eventId={event.id} />
}

return <_ExtrasPage attendance={attendance} />
return <ExtrasPageDetail attendance={attendance} />
}

const NoAttendanceFallback: FC<{ eventId: string }> = ({ eventId }) => {
Expand Down Expand Up @@ -47,7 +47,7 @@ const NoAttendanceFallback: FC<{ eventId: string }> = ({ eventId }) => {
interface Props {
attendance: Attendance
}
export const _ExtrasPage: FC<Props> = ({ attendance }) => {
export const ExtrasPageDetail: FC<Props> = ({ attendance }) => {
const openCreate = useCreateAttendanceExtrasModal({
attendance,
})
Expand Down
33 changes: 15 additions & 18 deletions apps/dashboard/src/app/(dashboard)/event/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
"use client"

import { Loader } from "@mantine/core"
import type { PropsWithChildren } from "react"
import { type PropsWithChildren, useMemo } from "react"
import { useEventDetailsGetQuery } from "../../../../modules/event/queries/use-event-get-query"
import { EventDetailsContext } from "./provider"

export default function EventDetailsLayout({ children, params }: PropsWithChildren<{ params: { id: string } }>) {
const { data, isLoading: eventLoading } = useEventDetailsGetQuery(params.id)

console.log(eventLoading, data)

return (
<>
{eventLoading || data === undefined ? (
<Loader />
) : (
<EventDetailsContext.Provider
value={{
const { data, isLoading } = useEventDetailsGetQuery(params.id)
const value = useMemo(
() =>
data === undefined || isLoading
? null
: {
event: data.event,
eventCommittees: data.eventCommittees,
attendance: data.attendance,
}}
>
{children}
</EventDetailsContext.Provider>
)}
</>
},
[data, isLoading]
)

if (value === null) {
return <Loader />
}

return <EventDetailsContext.Provider value={value}>{children}</EventDetailsContext.Provider>
}
3 changes: 1 addition & 2 deletions apps/dashboard/src/app/(dashboard)/event/[id]/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client"

import type { Attendance, Committee } from "@dotkomonline/types"
import type { Event } from "@dotkomonline/types"
import type { Attendance, Committee, Event } from "@dotkomonline/types"
import { createContext, useContext } from "react"

/** Context consisting of everything required to use and render the form */
Expand Down
31 changes: 19 additions & 12 deletions apps/dashboard/src/app/(dashboard)/interest-group/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
"use client"

import { Loader } from "@mantine/core"
import type { PropsWithChildren } from "react"
import { type PropsWithChildren, useMemo } from "react"
import { trpc } from "../../../../utils/trpc"
import { InterestGroupDetailsContext } from "./provider"

export default function OfflineDetailsLayout({ children, params }: PropsWithChildren<{ params: { id: string } }>) {
export default function InterestGroupDetailsLayout({
children,
params,
}: PropsWithChildren<{ params: { id: string } }>) {
const { data, isLoading } = trpc.interestGroup.get.useQuery(params.id)
return (
<>
{isLoading || !data ? (
<Loader />
) : (
<InterestGroupDetailsContext.Provider value={{ interestGroup: data }}>
{children}
</InterestGroupDetailsContext.Provider>
)}
</>
const value = useMemo(
() =>
data === undefined || isLoading
? null
: {
interestGroup: data,
},
[data, isLoading]
)

if (value === null) {
return <Loader />
}

return <InterestGroupDetailsContext.Provider value={value}>{children}</InterestGroupDetailsContext.Provider>
}
24 changes: 15 additions & 9 deletions apps/dashboard/src/app/(dashboard)/job-listing/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
"use client"

import { Loader } from "@mantine/core"
import type { PropsWithChildren } from "react"
import { type PropsWithChildren, useMemo } from "react"
import { trpc } from "../../../../utils/trpc"
import { JobListingDetailsContext } from "./provider"

export default function JobListingDetailsLayout({ children, params }: PropsWithChildren<{ params: { id: string } }>) {
const { data, isLoading } = trpc.jobListing.get.useQuery(params.id)
return (
<>
{isLoading || !data ? (
<Loader />
) : (
<JobListingDetailsContext.Provider value={{ jobListing: data }}>{children}</JobListingDetailsContext.Provider>
)}
</>
const value = useMemo(
() =>
data === undefined || isLoading
? null
: {
jobListing: data,
},
[data, isLoading]
)

if (value === null) {
return <Loader />
}

return <JobListingDetailsContext.Provider value={value}>{children}</JobListingDetailsContext.Provider>
}
24 changes: 15 additions & 9 deletions apps/dashboard/src/app/(dashboard)/offline/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
"use client"

import { Loader } from "@mantine/core"
import type { PropsWithChildren } from "react"
import { type PropsWithChildren, useMemo } from "react"
import { trpc } from "../../../../utils/trpc"
import { OfflineDetailsContext } from "./provider"

export default function OfflineDetailsLayout({ children, params }: PropsWithChildren<{ params: { id: string } }>) {
const { data, isLoading } = trpc.offline.get.useQuery(params.id)
return (
<>
{isLoading || !data ? (
<Loader />
) : (
<OfflineDetailsContext.Provider value={{ offline: data }}>{children}</OfflineDetailsContext.Provider>
)}
</>
const value = useMemo(
() =>
data === undefined || isLoading
? null
: {
offline: data,
},
[data, isLoading]
)

if (value === null) {
return <Loader />
}

return <OfflineDetailsContext.Provider value={value}>{children}</OfflineDetailsContext.Provider>
}
2 changes: 1 addition & 1 deletion apps/dashboard/src/app/(dashboard)/punishment/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useMarkCountUsersQuery } from "../../../modules/punishment/queries/use-
import { usePunishmentAllQuery } from "../../../modules/punishment/queries/use-punishment-all-query"
import { formatDate } from "../../../utils/format"

function MarkUserCount({ markId }: { markId: MarkId }) {
function MarkUserCount({ markId }: Readonly<{ markId: MarkId }>) {
const { data } = useMarkCountUsersQuery(markId)
return <>{data ?? 0}</>
}
Expand Down
33 changes: 19 additions & 14 deletions apps/dashboard/src/app/(dashboard)/user/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
"use client"

import { Loader } from "@mantine/core"
import type { PropsWithChildren } from "react"
import { type PropsWithChildren, useMemo } from "react"
import { trpc } from "../../../../utils/trpc"
import { UserDetailsContext } from "./provider"

export default function UserDetailsLayout({ children, params }: PropsWithChildren<{ params: { id: string } }>) {
const id = decodeURIComponent(params.id)
const { data, isLoading, error } = trpc.user.get.useQuery(id)
const { data, isLoading } = trpc.user.get.useQuery(id)
const value = useMemo(
() =>
data === undefined || isLoading
? null
: {
user: data,
},
[data, isLoading]
)

if (error) {
console.log(error)
return <div>{error.message}</div>
if (value === null) {
return <Loader />
}

return (
<>
{isLoading || !data ? (
<Loader />
) : (
<UserDetailsContext.Provider value={{ user: data }}>{children}</UserDetailsContext.Provider>
)}
</>
)
const u = value.user
if (u === null) {
return <div>User {id} not found</div>
}

return <UserDetailsContext.Provider value={{ user: u }}>{children}</UserDetailsContext.Provider>
}
2 changes: 0 additions & 2 deletions apps/dashboard/src/app/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,6 @@ export function useFormBuilder<T extends z.ZodRawShape>({
)
})

console.log(form.formState.errors)

return function Form() {
return (
<form
Expand Down
8 changes: 4 additions & 4 deletions apps/dashboard/src/app/notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface NotificationConfig {
const createNotificationMethod =
(config: NotificationConfig) =>
({ title, message, id, method: _method, autoClose }: NotificationProps) => {
const method = _method || "show"
const method = _method ?? "show"

return notifications[method]({
...config,
Expand Down Expand Up @@ -132,19 +132,19 @@ export const useQueryGenericMutationNotification = ({ method }: Props) => {
}

export const notifyLoading = (props: NotificationProps) =>
notifications[props.method || "show"]({
notifications[props.method ?? "show"]({
...props,
...notificationConfigs.loading,
})

export const notifyComplete = (props: NotificationProps) =>
notifications[props.method || "show"]({
notifications[props.method ?? "show"]({
...props,
...notificationConfigs.complete,
})

export const notifyFail = (props: NotificationProps) =>
notifications[props.method || "show"]({
notifications[props.method ?? "show"]({
...props,
...notificationConfigs.fail,
})
6 changes: 3 additions & 3 deletions apps/dashboard/src/components/GenericSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface GenericSearchProps<T> {
onSubmit(item: T): void
items: T[]
dataMapper(item: T): string
placeholder?: string | null | undefined
placeholder?: string | null
resetOnClick?: boolean
}

Expand All @@ -33,7 +33,7 @@ const GenericSearch = <T,>({
}
}

const placeholderText = placeholder !== null ? placeholder || "Search..." : undefined
const placeholderText = placeholder !== null ? placeholder ?? "Search..." : undefined

const data = items.map(dataMapper)

Expand All @@ -42,7 +42,7 @@ const GenericSearch = <T,>({
const duplicateMap = new Map<string, number>()

const dataWithDuplicates = data.map((item) => {
const count = duplicateMap.get(item) || 0
const count = duplicateMap.get(item) ?? 0
duplicateMap.set(item, count + 1)

if (count === 0) {
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/components/GenericTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Card, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text }
import { type Table as ReactTable, flexRender } from "@tanstack/react-table"

export interface GenericTableProps<T> {
table: ReactTable<T>
readonly table: ReactTable<T>
}

export function GenericTable<T>({ table }: GenericTableProps<T>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ const AttendancePoolCard: FC<NormalPoolBoxProps> = ({ pool, attendanceId, delete

export const PoolBox: FC<PoolsBoxProps> = ({ pools, attendanceId }) => {
const deleteGroupMut = useDeletePoolMutation()

const Pool: FC<{ pool: AttendancePool }> = ({ pool }) => {
return <AttendancePoolCard key={pool.id} pool={pool} deleteGroup={deleteGroup} attendanceId={attendanceId} />
}

const deleteGroup = (id: string, numAttendees: number) => {
if (numAttendees > 0) {
notifyFail({
Expand All @@ -76,7 +71,7 @@ export const PoolBox: FC<PoolsBoxProps> = ({ pools, attendanceId }) => {
return (
<Box>
{pools?.map((pool) => (
<Pool key={pool.id} pool={pool} />
<AttendancePoolCard key={pool.id} pool={pool} deleteGroup={deleteGroup} attendanceId={attendanceId} />
))}
{pools?.length === 0 && <Text fs="italic">Ingen påmeldingsgrupper</Text>}
</Box>
Expand Down
Loading
Loading