Skip to content

Commit 47c5b3f

Browse files
committed
use app router
1 parent b96af31 commit 47c5b3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+423
-338
lines changed

packages/auth/src/components/Navigation.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useMemo } from 'react'
2+
import { useRouter } from 'next/navigation'
23

34
import { ActionButton } from '@keystar/ui/button'
45
import { Divider } from '@keystar/ui/layout'
@@ -15,7 +16,7 @@ import {
1516
getHrefFromList,
1617
} from '@keystone-6/core/admin-ui/components'
1718
import type { NavigationProps } from '@keystone-6/core/admin-ui/components'
18-
import { useRouter } from '@keystone-6/core/admin-ui/router'
19+
import { useKeystone } from '@keystone-6/core/admin-ui/context'
1920

2021
export default ({ labelField }: { labelField: string }) =>
2122
(props: NavigationProps) => <Navigation labelField={labelField} {...props} />
@@ -43,13 +44,15 @@ function Navigation({
4344
)
4445
)
4546

47+
const { adminPath } = useKeystone()
48+
4649
return (
4750
<NavContainer>
4851
<NavList>
4952
<NavItem href="/">Dashboard</NavItem>
5053
<Divider />
5154
{lists.map(list => (
52-
<NavItem key={list.key} href={getHrefFromList(list)}>
55+
<NavItem key={list.key} href={getHrefFromList(list, adminPath)}>
5356
{list.label}
5457
</NavItem>
5558
))}

packages/auth/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,24 @@ export function createAuth<ListTypeInfo extends BaseListTypeInfo>({
6969
: 'id')
7070

7171
const authGqlNames = getAuthGqlNames(listConfig.graphql?.singular ?? listKey)
72+
const ext = (config.ui.tsx ?? true) ? 'tsx' : 'js'
7273
const filesToWrite: AdminFileToWrite[] = [
7374
{
7475
mode: 'write',
7576
src: signinTemplate({ authGqlNames, identityField, secretField }),
76-
outputPath: 'pages/signin.js',
77+
outputPath: `signin/page.${ext}`,
7778
},
7879
{
7980
mode: 'write',
8081
src: configTemplate({ labelField }),
81-
outputPath: 'config.ts',
82+
outputPath: '.admin/config.tsx',
8283
},
8384
]
8485
if (initFirstItem) {
8586
filesToWrite.push({
8687
mode: 'write',
8788
src: initTemplate({ authGqlNames, listKey, initFirstItem }),
88-
outputPath: 'pages/init.js',
89+
outputPath: `init/page.${ext}`,
8990
})
9091
}
9192
return filesToWrite

packages/auth/src/lib/useFromRedirect.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/auth/src/pages/InitPage.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import NextHead from 'next/head'
2+
import { useRouter } from 'next/navigation'
23

34
import { gql, useMutation } from '@keystone-6/core/admin-ui/apollo'
4-
import { useList } from '@keystone-6/core/admin-ui/context'
5-
import { useRouter } from '@keystone-6/core/admin-ui/router'
5+
import { useKeystone, useList } from '@keystone-6/core/admin-ui/context'
66
import { Fields, useBuildItem } from '@keystone-6/core/admin-ui/utils'
77
import { GraphQLErrorNotice, Logo } from '@keystone-6/core/admin-ui/components'
88
import { Button } from '@keystar/ui/button'
99
import { Grid, HStack, VStack } from '@keystar/ui/layout'
1010
import { Heading } from '@keystar/ui/typography'
11-
12-
import { useRedirect } from '../lib/useFromRedirect'
13-
1411
import type { AuthGqlNames } from '../types'
1512

1613
export default (props: Parameters<typeof InitPage>[0]) => () => <InitPage {...props} />
@@ -25,7 +22,7 @@ function InitPage({
2522
fieldPaths: string[]
2623
}) {
2724
const router = useRouter()
28-
const redirect = useRedirect()
25+
const { adminPath } = useKeystone()
2926
const list = useList(listKey)
3027

3128
const builder = useBuildItem(list, fieldPaths)
@@ -62,7 +59,7 @@ function InitPage({
6259
return
6360
}
6461

65-
router.push(redirect)
62+
router.push(adminPath || '/')
6663
}
6764

6865
const pending = loading || data?.authenticate?.__typename === successTypename

packages/auth/src/pages/SigninPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import NextHead from 'next/head'
2+
import { useRouter } from 'next/navigation'
23
import { type FormEvent, useState } from 'react'
34

45
import { Button } from '@keystar/ui/button'
@@ -11,7 +12,6 @@ import { Heading, Text } from '@keystar/ui/typography'
1112

1213
import { gql, useMutation } from '@keystone-6/core/admin-ui/apollo'
1314
import { GraphQLErrorNotice, Logo } from '@keystone-6/core/admin-ui/components'
14-
import { useRouter } from '@keystone-6/core/admin-ui/router'
1515

1616
import type { AuthGqlNames } from '../types'
1717

packages/auth/src/templates/init.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export default function ({
1010
listKey: string
1111
initFirstItem: NonNullable<AuthConfig<BaseListTypeInfo>['initFirstItem']>
1212
}) {
13-
return `import makeInitPage from '@keystone-6/auth/pages/InitPage'
13+
return `'use client'
14+
import makeInitPage from '@keystone-6/auth/pages/InitPage'
1415
1516
export default makeInitPage(${JSON.stringify({
1617
listKey,

packages/auth/src/templates/signin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export default function ({
99
identityField: string
1010
secretField: string
1111
}) {
12-
return `import makeSigninPage from '@keystone-6/auth/pages/SigninPage'
12+
return `'use client'
13+
import makeSigninPage from '@keystone-6/auth/pages/SigninPage'
1314
1415
export default makeSigninPage(${JSON.stringify({
1516
authGqlNames,

packages/core/package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@
6666
"module": "./admin-ui/apollo/dist/keystone-6-core-admin-ui-apollo.esm.js",
6767
"default": "./admin-ui/apollo/dist/keystone-6-core-admin-ui-apollo.cjs.js"
6868
},
69-
"./admin-ui/router": {
70-
"types": "./admin-ui/router/dist/keystone-6-core-admin-ui-router.cjs.js",
71-
"module": "./admin-ui/router/dist/keystone-6-core-admin-ui-router.esm.js",
72-
"default": "./admin-ui/router/dist/keystone-6-core-admin-ui-router.cjs.js"
73-
},
7469
"./admin-ui/context": {
7570
"types": "./admin-ui/context/dist/keystone-6-core-admin-ui-context.cjs.js",
7671
"module": "./admin-ui/context/dist/keystone-6-core-admin-ui-context.esm.js",
@@ -316,7 +311,6 @@
316311
"admin-ui/components/index.ts",
317312
"admin-ui/apollo.tsx",
318313
"admin-ui/context.tsx",
319-
"admin-ui/router.tsx",
320314
"admin-ui/image.tsx",
321315
"admin-ui/utils/index.ts",
322316
"fields/index.ts",
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
import type { AppProps } from 'next/app'
21
import type { AdminConfig, FieldViews } from '../../../../types'
32
import { ErrorBoundary } from '../../../../admin-ui/components'
43
import { KeystoneProvider } from '../../../../admin-ui/context'
54

5+
type AdminProps = {
6+
children: React.ReactNode
7+
config: AppConfig
8+
}
9+
610
type AppConfig = {
711
adminConfig: AdminConfig
812
fieldViews: FieldViews
913
apiPath: string
14+
adminPath: string
1015
}
1116

12-
export const getApp =
13-
(props: AppConfig) =>
14-
({ Component, pageProps }: AppProps) => {
15-
return (
16-
<KeystoneProvider {...props}>
17-
<ErrorBoundary>
18-
<Component {...pageProps} />
19-
</ErrorBoundary>
20-
</KeystoneProvider>
21-
)
22-
}
17+
export function Layout({ children, config }: AdminProps) {
18+
return (
19+
<KeystoneProvider {...config}>
20+
<ErrorBoundary>{children}</ErrorBoundary>
21+
</KeystoneProvider>
22+
)
23+
}

packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { useRouter } from 'next/router'
2-
1+
'use client'
2+
import { type Usable, use } from 'react'
3+
import { useRouter } from 'next/navigation'
34
import { Button } from '@keystar/ui/button'
45
import { VStack } from '@keystar/ui/layout'
56

67
import { Fields } from '../../../../admin-ui/utils'
78
import { PageContainer } from '../../../../admin-ui/components/PageContainer'
8-
import { useList } from '../../../../admin-ui'
9+
import { useKeystone, useList } from '../../../../admin-ui'
910
import { GraphQLErrorNotice } from '../../../../admin-ui/components'
1011
import { useCreateItem } from '../../../../admin-ui/utils/useCreateItem'
1112
import { BaseToolbar, ColumnLayout, ItemPageHeader } from '../ItemPage/common'
@@ -14,10 +15,13 @@ export const getCreateItemPage = (props: Parameters<typeof CreateItemPage>[0]) =
1415
<CreateItemPage {...props} />
1516
)
1617

17-
function CreateItemPage({ listKey }: { listKey: string }) {
18-
const list = useList(listKey)
18+
export function CreateItemPage({ params }: { params: Usable<{ listKey: string }> }) {
19+
const { listsKeyByPath } = useKeystone()
20+
const _params = use<{ listKey: string }>(params)
21+
const list = useList(listsKeyByPath[_params.listKey])
1922
const createItem = useCreateItem(list)
2023
const router = useRouter()
24+
const { adminPath } = useKeystone()
2125

2226
return (
2327
<PageContainer
@@ -33,7 +37,7 @@ function CreateItemPage({ listKey }: { listKey: string }) {
3337
const item = await createItem.create()
3438
if (!item) return
3539

36-
router.push(`/${list.path}/${item.id}`)
40+
router.push(`${adminPath}/${list.path}/${item.id}`)
3741
}}
3842
style={{ display: 'contents' }}
3943
>

0 commit comments

Comments
 (0)