Skip to content

Commit 92f458d

Browse files
authored
feat(next,ui): improves loading states (#6434)
1 parent 043a91d commit 92f458d

File tree

94 files changed

+983
-881
lines changed

Some content is hidden

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

94 files changed

+983
-881
lines changed

next.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default withBundleAnalyzer(
1717
ignoreBuildErrors: true,
1818
},
1919
experimental: {
20-
reactCompiler: false
20+
reactCompiler: false,
2121
},
2222
async redirects() {
2323
return [

packages/next/src/layouts/Root/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ export const RootLayout = async ({
5757
})
5858

5959
const payload = await getPayloadHMR({ config })
60+
6061
const i18n: I18nClient = await initI18n({
6162
config: config.i18n,
6263
context: 'client',
6364
language: languageCode,
6465
})
66+
6567
const clientConfig = await createClientConfig({ config, t: i18n.t })
6668

6769
const dir = (rtlLanguages as unknown as AcceptedLanguages[]).includes(languageCode)

packages/next/src/utilities/initPage/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ export const initPage = async ({
4747
language,
4848
})
4949

50+
const languageOptions = Object.entries(payload.config.i18n.supportedLanguages || {}).reduce(
51+
(acc, [language, languageConfig]) => {
52+
if (Object.keys(payload.config.i18n.supportedLanguages).includes(language)) {
53+
acc.push({
54+
label: languageConfig.translations.general.thisLanguage,
55+
value: language,
56+
})
57+
}
58+
59+
return acc
60+
},
61+
[],
62+
)
63+
5064
const req = await createLocalReq(
5165
{
5266
fallbackLocale: null,
@@ -98,6 +112,7 @@ export const initPage = async ({
98112
cookies,
99113
docID,
100114
globalConfig,
115+
languageOptions,
101116
locale,
102117
permissions,
103118
req,

packages/next/src/utilities/initPage/shared.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { SanitizedConfig } from 'payload/types'
22

33
const authRouteKeys: (keyof SanitizedConfig['admin']['routes'])[] = [
4-
'account',
54
'createFirstUser',
65
'forgot',
76
'login',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Select } from '@payloadcms/ui/fields/Select'
2+
import { useTranslation } from '@payloadcms/ui/providers/Translation'
3+
import React from 'react'
4+
5+
export const LocaleSelector: React.FC<{
6+
localeOptions: {
7+
label: Record<string, string> | string
8+
value: string
9+
}[]
10+
onChange: (value: string) => void
11+
}> = ({ localeOptions, onChange }) => {
12+
const { t } = useTranslation()
13+
14+
return (
15+
<Select
16+
label={t('general:locale')}
17+
name="locale"
18+
onChange={(value) => onChange(value)}
19+
options={localeOptions}
20+
path="locale"
21+
/>
22+
)
23+
}

packages/next/src/views/API/index.client.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { CopyToClipboard } from '@payloadcms/ui/elements/CopyToClipboard'
44
import { Gutter } from '@payloadcms/ui/elements/Gutter'
55
import { Checkbox } from '@payloadcms/ui/fields/Checkbox'
66
import { NumberField as NumberInput } from '@payloadcms/ui/fields/Number'
7-
import { Select } from '@payloadcms/ui/fields/Select'
87
import { Form } from '@payloadcms/ui/forms/Form'
98
import { MinimizeMaximize } from '@payloadcms/ui/icons/MinimizeMaximize'
109
import { SetViewActions } from '@payloadcms/ui/providers/Actions'
@@ -19,6 +18,7 @@ import * as React from 'react'
1918
import { toast } from 'react-toastify'
2019

2120
import { SetDocumentStepNav } from '../Edit/Default/SetDocumentStepNav/index.js'
21+
import { LocaleSelector } from './LocaleSelector/index.js'
2222
import { RenderJSON } from './RenderJSON/index.js'
2323
import './index.scss'
2424

@@ -173,15 +173,7 @@ export const APIViewClient: React.FC = () => {
173173
path="authenticated"
174174
/>
175175
</div>
176-
{localeOptions && (
177-
<Select
178-
label={t('general:locale')}
179-
name="locale"
180-
onChange={(value) => setLocale(value)}
181-
options={localeOptions}
182-
path="locale"
183-
/>
184-
)}
176+
{localeOptions && <LocaleSelector localeOptions={localeOptions} onChange={setLocale} />}
185177
<NumberInput
186178
label={t('general:depth')}
187179
max={10}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use client'
2+
import type { LanguageOptions } from 'payload/types'
3+
4+
import { ReactSelect } from '@payloadcms/ui/elements/ReactSelect'
5+
import { useTranslation } from '@payloadcms/ui/providers/Translation'
6+
import React from 'react'
7+
8+
export const LanguageSelector: React.FC<{
9+
languageOptions: LanguageOptions
10+
}> = (props) => {
11+
const { languageOptions } = props
12+
13+
const { i18n, switchLanguage } = useTranslation()
14+
15+
return (
16+
<ReactSelect
17+
inputId="language-select"
18+
onChange={async ({ value }) => {
19+
await switchLanguage(value)
20+
}}
21+
options={languageOptions}
22+
value={languageOptions.find((language) => language.value === i18n.language)}
23+
/>
24+
)
25+
}

packages/next/src/views/Account/Settings/index.tsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
'use client'
2-
import { ReactSelect } from '@payloadcms/ui/elements/ReactSelect'
1+
import type { I18n } from '@payloadcms/translations'
2+
import type { LanguageOptions } from 'payload/types'
3+
34
import { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'
4-
import { useTranslation } from '@payloadcms/ui/providers/Translation'
55
import React from 'react'
66

77
import { ToggleTheme } from '../ToggleTheme/index.js'
8+
import { LanguageSelector } from './LanguageSelector.js'
89
import './index.scss'
910

1011
const baseClass = 'payload-settings'
1112

1213
export const Settings: React.FC<{
1314
className?: string
15+
i18n: I18n
16+
languageOptions: LanguageOptions
1417
}> = (props) => {
15-
const { className } = props
16-
17-
const { i18n, languageOptions, switchLanguage, t } = useTranslation()
18+
const { className, i18n, languageOptions } = props
1819

1920
return (
2021
<div className={[baseClass, className].filter(Boolean).join(' ')}>
21-
<h3>{t('general:payloadSettings')}</h3>
22+
<h3>{i18n.t('general:payloadSettings')}</h3>
2223
<div className={`${baseClass}__language`}>
23-
<FieldLabel htmlFor="language-select" label={t('general:language')} />
24-
<ReactSelect
25-
inputId="language-select"
26-
onChange={async ({ value }) => {
27-
await switchLanguage(value)
28-
}}
29-
options={languageOptions}
30-
value={languageOptions.find((language) => language.value === i18n.language)}
31-
/>
24+
<FieldLabel htmlFor="language-select" label={i18n.t('general:language')} />
25+
<LanguageSelector languageOptions={languageOptions} />
3226
</div>
3327
<ToggleTheme />
3428
</div>

packages/next/src/views/Account/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { FormQueryParamsProvider } from '@payloadcms/ui/providers/FormQueryParam
99
import { notFound } from 'next/navigation.js'
1010
import React from 'react'
1111

12+
import { getDocumentData } from '../Document/getDocumentData.js'
1213
import { getDocumentPermissions } from '../Document/getDocumentPermissions.js'
1314
import { EditView } from '../Edit/index.js'
1415
import { Settings } from './Settings/index.js'
@@ -21,6 +22,7 @@ export const Account: React.FC<AdminViewProps> = async ({
2122
searchParams,
2223
}) => {
2324
const {
25+
languageOptions,
2426
locale,
2527
permissions,
2628
req,
@@ -49,6 +51,13 @@ export const Account: React.FC<AdminViewProps> = async ({
4951
req,
5052
})
5153

54+
const { data, formState } = await getDocumentData({
55+
id: user.id,
56+
collectionConfig,
57+
locale,
58+
req,
59+
})
60+
5261
const viewComponentProps: ServerSideEditViewProps = {
5362
initPageResult,
5463
params,
@@ -58,14 +67,16 @@ export const Account: React.FC<AdminViewProps> = async ({
5867

5968
return (
6069
<DocumentInfoProvider
61-
AfterFields={<Settings />}
70+
AfterFields={<Settings i18n={i18n} languageOptions={languageOptions} />}
6271
action={`${serverURL}${api}/${userSlug}${user?.id ? `/${user.id}` : ''}`}
6372
apiURL={`${serverURL}${api}/${userSlug}${user?.id ? `/${user.id}` : ''}`}
6473
collectionSlug={userSlug}
6574
docPermissions={docPermissions}
6675
hasPublishPermission={hasPublishPermission}
6776
hasSavePermission={hasSavePermission}
6877
id={user?.id.toString()}
78+
initialData={data}
79+
initialState={formState}
6980
isEditing
7081
>
7182
<DocumentHeader

packages/next/src/views/Dashboard/Default/index.client.tsx

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

0 commit comments

Comments
 (0)