Skip to content

Commit

Permalink
Refactor frontend imports and improve type definitions
Browse files Browse the repository at this point in the history
- Updated import paths to use absolute imports with @/ prefix
- Simplified and improved type definitions in Layout and inertiaConfig
- Adjusted component props and type annotations for better type safety
- Cleaned up import statements across multiple frontend components
  • Loading branch information
mpressen committed Feb 4, 2025
1 parent 65be67f commit 4aa7738
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 31 deletions.
6 changes: 3 additions & 3 deletions app/frontend/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { SidebarProvider, SidebarTrigger } from '@/components/ui/sidebar'
const flashTypes = ['message', 'success', 'info', 'warning', 'error'] as const

interface LayoutProps {
children: ReactElement
showSidebar?: boolean
flash: { [key in typeof flashTypes[number]]?: string }
showSidebar: boolean
flash: any
children?: ReactElement
}

export default function Layout ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactElement } from 'react'
import useFormHandler from '@/hooks/useFormHandler'
import { z } from 'zod'
import MyInput from '../../../shared/MyInput'
import MyInput from '@/components/shared/MyInput'
import { Button } from '@/components/ui/button'
import { StepForward } from 'lucide-react'

Expand Down
4 changes: 2 additions & 2 deletions app/frontend/components/pages/auth/signUp/SignUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useRef, ReactElement, FormEvent } from 'react'
import { Link } from '@inertiajs/react'
import useFormHandler from '@/hooks/useFormHandler'
import { KeysWithStringValues } from '@/types/utilityTypes'
import MyInput from '../shared/MyInput'
import MyCheckbox from '../shared/MyCheckbox'
import MyInput from '@/components/shared/MyInput'
import MyCheckbox from '@/components/shared/MyCheckbox'
import ReCAPTCHA from 'react-google-recaptcha'
import { Button } from '@/components/ui/button'
import { StepForward } from 'lucide-react'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
SelectValue
} from '@/components/ui/select'
import { usePage } from '@inertiajs/react'
import KeywordAsyncCreatableSelect from './OsblDatasheet/KeywordAsyncCreatableSelect'
import KeywordAsyncCreatableSelect from '@/components/pages/contribution/new/OsblDatasheet/KeywordAsyncCreatableSelect'
import HelpTooltip from '@/components/shared/HelpTooltip'
import InterventionAreaAsyncCreatableSelect from './OsblDatasheet/InterventionAreaAsyncCreatableSelect'
import InterventionAreaAsyncCreatableSelect from '@/components/pages/contribution/new/OsblDatasheet/InterventionAreaAsyncCreatableSelect'
import MyNumberInput from '@/components/shared/MyNumberInput'
import MyCheckbox from '@/components/shared/MyCheckbox'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Sheet,
SheetTrigger
} from '@/components/ui/sheet'
import OsblDocumentSheet from './OsblDocuments/OsblDocumentSheet'
import OsblDocumentSheet from '@/components/pages/contribution/new/OsblDocuments/OsblDocumentSheet'

export default function OsblDocuments ({ data, setData, errors, clearErrors, setError }: FormProps): ReactElement {
const documents = data.document_attachments_attributes ?? []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Sheet,
SheetTrigger
} from '@/components/ui/sheet'
import OsblFinanceSheet from './OsblFinances/OsblFinanceSheet'
import OsblFinanceSheet from '@/components/pages/contribution/new/OsblFinances/OsblFinanceSheet'

export default function OsblFinances ({ data, setData, errors, clearErrors, setError }: FormProps): ReactElement {
const [sortAscending, setSortAscending] = useState(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Sheet,
SheetTrigger
} from '@/components/ui/sheet'
import OsblLocationSheet from './OsblLocations/OsblLocationSheet'
import OsblLocationSheet from '@/components/pages/contribution/new/OsblLocations/OsblLocationSheet'

export default function OsblLocations ({ data, setData }: Pick<FormProps, 'data' | 'setData'>): ReactElement {
const locations = data.locations_attributes ?? []
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/components/shared/MyFileInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactElement, useRef, useState } from 'react'
import MyInput from './MyInput'
import MyInput from '@/components/shared/MyInput'

interface MyFileInputProps {
id: string
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/components/shared/MyInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface WithLabel extends BaseMyInputProps {
}

interface WithoutLabel extends BaseMyInputProps {
labelText: never
labelText?: never
placeholder: string
}

Expand Down
36 changes: 19 additions & 17 deletions app/frontend/lib/inertiaConfig.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import { createElement } from 'react'
import type { ResolvedComponent } from '@inertiajs/react'
import { createElement, ReactElement } from 'react'
import type { PageResolver } from '@inertiajs/core'
import Layout from '@/Layout'

interface ResolvedComponent {
default: {
layout: (pageContent: ReactElement & { props: { flash?: any } }) => ReactElement
}
}

export const getTitle = (title: string | null): string =>
title ? `${title} | Benefactorum` : 'Benefactorum'
title !== null ? `${title} | Benefactorum` : 'Benefactorum'

export const resolvePage = (name: string): ResolvedComponent => {
export const resolvePage: PageResolver = (name) => {
const pages = import.meta.glob<ResolvedComponent>(
'../pages/**/!(*.test).tsx',
{ eager: true }
)
const page = pages[`../pages/${name}.tsx`] as {
default: { layout?: (page: JSX.Element) => JSX.Element }
}
if (!page) {
const page = pages[`../pages/${name}.tsx`]

if (page === undefined) {
console.error(`Missing Inertia page component: '${name}.tsx'`)
}
page.default.layout = (page) =>
createElement(
Layout,
{
showSidebar: name.startsWith('Contribution/'),
flash: page.props.flash
},
page
)

page.default.layout = (pageContent) =>
createElement(Layout, {
showSidebar: name.startsWith('Contribution/'),
flash: pageContent.props?.flash
}, pageContent)
return page
}
2 changes: 1 addition & 1 deletion app/frontend/pages/Contribution/New.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import OsblFinance from '@/components/pages/contribution/new/OsblFinances'
import OsblDocuments from '@/components/pages/contribution/new/OsblDocuments'
import OsblLocations from '@/components/pages/contribution/new/OsblLocations'
import { CurrentUserType } from '@/types/types'
import { FormData } from './types'
import { FormData } from '@/pages/Contribution/types'
import z from 'zod'
import deepCleanData from '@/lib/deepCleanData'
import { toast } from 'sonner'
Expand Down

0 comments on commit 4aa7738

Please sign in to comment.