Merge branch 'alpha' into feat/config-i18n

This commit is contained in:
James Mikrut
2024-04-08 16:26:38 -04:00
committed by GitHub
33 changed files with 111 additions and 70 deletions

View File

@@ -10,3 +10,5 @@
**/temp **/temp
**/docs/** **/docs/**
tsconfig.json tsconfig.json
packages/payload/*.js
packages/payload/*.d.ts

View File

@@ -1,6 +1,6 @@
{ {
"name": "payload-monorepo", "name": "payload-monorepo",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"private": true, "private": true,
"type": "module", "type": "module",
"workspaces:": [ "workspaces:": [

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/db-mongodb", "name": "@payloadcms/db-mongodb",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"description": "The officially supported MongoDB database adapter for Payload", "description": "The officially supported MongoDB database adapter for Payload",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/db-postgres", "name": "@payloadcms/db-postgres",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"description": "The officially supported Postgres database adapter for Payload", "description": "The officially supported Postgres database adapter for Payload",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/graphql", "name": "@payloadcms/graphql",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"main": "./src/index.ts", "main": "./src/index.ts",
"types": "./src/index.d.ts", "types": "./src/index.d.ts",
"type": "module", "type": "module",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/next", "name": "@payloadcms/next",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"main": "./src/index.js", "main": "./src/index.js",
"types": "./src/index.js", "types": "./src/index.js",
"type": "module", "type": "module",

View File

@@ -56,7 +56,7 @@ export const RootLayout = async ({
async function switchLanguageServerAction(lang: string): Promise<void> { async function switchLanguageServerAction(lang: string): Promise<void> {
'use server' 'use server'
nextCookies().set({ nextCookies().set({
name: `${config.cookiePrefix || 'payload'}-lng'`, name: `${config.cookiePrefix || 'payload'}-lng`,
path: '/', path: '/',
value: lang, value: lang,
}) })

View File

@@ -17,7 +17,7 @@ export const getRequestLanguage = ({
headers, headers,
}: GetRequestLanguageArgs): string => { }: GetRequestLanguageArgs): string => {
const acceptLanguage = headers.get('Accept-Language') const acceptLanguage = headers.get('Accept-Language')
const cookieLanguage = cookies.get(`${config.cookiePrefix || 'payload'}-lng'`) const cookieLanguage = cookies.get(`${config.cookiePrefix || 'payload'}-lng`)
const reqLanguage = const reqLanguage =
(typeof cookieLanguage === 'string' ? cookieLanguage : cookieLanguage?.value) || (typeof cookieLanguage === 'string' ? cookieLanguage : cookieLanguage?.value) ||

View File

@@ -12,7 +12,7 @@ import './index.scss'
export { generateCreateFirstUserMetadata } from './meta.js' export { generateCreateFirstUserMetadata } from './meta.js'
export const CreateFirstUser: React.FC<AdminViewProps> = async ({ initPageResult }) => { export const CreateFirstUserView: React.FC<AdminViewProps> = async ({ initPageResult }) => {
const { const {
req, req,
req: { req: {

View File

@@ -10,7 +10,7 @@ import type {
import { APIView as DefaultAPIView } from '../API/index.js' import { APIView as DefaultAPIView } from '../API/index.js'
import { EditView as DefaultEditView } from '../Edit/index.js' import { EditView as DefaultEditView } from '../Edit/index.js'
import { LivePreviewView as DefaultLivePreviewView } from '../LivePreview/index.js' import { LivePreviewView as DefaultLivePreviewView } from '../LivePreview/index.js'
import { Unauthorized } from '../Unauthorized/index.js' import { UnauthorizedView } from '../Unauthorized/index.js'
import { VersionView as DefaultVersionView } from '../Version/index.js' import { VersionView as DefaultVersionView } from '../Version/index.js'
import { VersionsView as DefaultVersionsView } from '../Versions/index.js' import { VersionsView as DefaultVersionsView } from '../Versions/index.js'
import { getCustomViewByKey } from './getCustomViewByKey.js' import { getCustomViewByKey } from './getCustomViewByKey.js'
@@ -77,7 +77,7 @@ export const getViewsFromConfig = ({
CustomView = getCustomViewByKey(views, 'Default') CustomView = getCustomViewByKey(views, 'Default')
DefaultView = DefaultEditView DefaultView = DefaultEditView
} else { } else {
ErrorView = Unauthorized ErrorView = UnauthorizedView
} }
break break
} }
@@ -87,7 +87,7 @@ export const getViewsFromConfig = ({
CustomView = getCustomViewByKey(views, 'Default') CustomView = getCustomViewByKey(views, 'Default')
DefaultView = DefaultEditView DefaultView = DefaultEditView
} else { } else {
ErrorView = Unauthorized ErrorView = UnauthorizedView
} }
break break
} }
@@ -118,7 +118,7 @@ export const getViewsFromConfig = ({
CustomView = getCustomViewByKey(views, 'Versions') CustomView = getCustomViewByKey(views, 'Versions')
DefaultView = DefaultVersionsView DefaultView = DefaultVersionsView
} else { } else {
ErrorView = Unauthorized ErrorView = UnauthorizedView
} }
break break
} }
@@ -150,7 +150,7 @@ export const getViewsFromConfig = ({
CustomView = getCustomViewByKey(views, 'Version') CustomView = getCustomViewByKey(views, 'Version')
DefaultView = DefaultVersionView DefaultView = DefaultVersionView
} else { } else {
ErrorView = Unauthorized ErrorView = UnauthorizedView
} }
} else { } else {
const baseRoute = [adminRoute, collectionEntity, collectionSlug, segment3] const baseRoute = [adminRoute, collectionEntity, collectionSlug, segment3]
@@ -191,7 +191,7 @@ export const getViewsFromConfig = ({
CustomView = getCustomViewByKey(views, 'Default') CustomView = getCustomViewByKey(views, 'Default')
DefaultView = DefaultEditView DefaultView = DefaultEditView
} else { } else {
ErrorView = Unauthorized ErrorView = UnauthorizedView
} }
break break
} }
@@ -219,7 +219,7 @@ export const getViewsFromConfig = ({
CustomView = getCustomViewByKey(views, 'Versions') CustomView = getCustomViewByKey(views, 'Versions')
DefaultView = DefaultVersionsView DefaultView = DefaultVersionsView
} else { } else {
ErrorView = Unauthorized ErrorView = UnauthorizedView
} }
break break
} }
@@ -229,7 +229,7 @@ export const getViewsFromConfig = ({
CustomView = getCustomViewByKey(views, 'Default') CustomView = getCustomViewByKey(views, 'Default')
DefaultView = DefaultEditView DefaultView = DefaultEditView
} else { } else {
ErrorView = Unauthorized ErrorView = UnauthorizedView
} }
break break
} }
@@ -244,7 +244,7 @@ export const getViewsFromConfig = ({
CustomView = getCustomViewByKey(views, 'Version') CustomView = getCustomViewByKey(views, 'Version')
DefaultView = DefaultVersionView DefaultView = DefaultVersionView
} else { } else {
ErrorView = Unauthorized ErrorView = UnauthorizedView
} }
} else { } else {
const baseRoute = [adminRoute, 'globals', globalSlug].filter(Boolean).join('/') const baseRoute = [adminRoute, 'globals', globalSlug].filter(Boolean).join('/')

View File

@@ -15,6 +15,7 @@ import React from 'react'
import type { GenerateEditViewMetadata } from './getMetaBySegment.js' import type { GenerateEditViewMetadata } from './getMetaBySegment.js'
import { NotFoundView } from '../NotFound/index.js'
import { getMetaBySegment } from './getMetaBySegment.js' import { getMetaBySegment } from './getMetaBySegment.js'
import { getViewsFromConfig } from './getViewsFromConfig.js' import { getViewsFromConfig } from './getViewsFromConfig.js'
@@ -106,12 +107,8 @@ export const Document: React.FC<AdminViewProps> = async ({
ErrorView = collectionViews?.ErrorView ErrorView = collectionViews?.ErrorView
} }
if (!CustomView && !DefaultView && !ViewOverride) { if (!CustomView && !DefaultView && !ViewOverride && !ErrorView) {
if (ErrorView) { ErrorView = NotFoundView
return <ErrorView initPageResult={initPageResult} searchParams={searchParams} />
}
notFound()
} }
} }
@@ -143,12 +140,8 @@ export const Document: React.FC<AdminViewProps> = async ({
DefaultView = globalViews?.DefaultView DefaultView = globalViews?.DefaultView
ErrorView = globalViews?.ErrorView ErrorView = globalViews?.ErrorView
if (!CustomView && !DefaultView && !ViewOverride) { if (!CustomView && !DefaultView && !ViewOverride && !ErrorView) {
if (ErrorView) { ErrorView = NotFoundView
return <ErrorView initPageResult={initPageResult} searchParams={searchParams} />
}
notFound()
} }
} }
} }
@@ -219,11 +212,15 @@ export const Document: React.FC<AdminViewProps> = async ({
uploadEdits: undefined, uploadEdits: undefined,
}} }}
> >
<RenderCustomComponent {ErrorView ? (
CustomComponent={ViewOverride || CustomView} <ErrorView initPageResult={initPageResult} searchParams={searchParams} />
DefaultComponent={DefaultView} ) : (
componentProps={viewComponentProps} <RenderCustomComponent
/> CustomComponent={ViewOverride || CustomView}
DefaultComponent={DefaultView}
componentProps={viewComponentProps}
/>
)}
</FormQueryParamsProvider> </FormQueryParamsProvider>
</EditDepthProvider> </EditDepthProvider>
</DocumentInfoProvider> </DocumentInfoProvider>

View File

@@ -13,7 +13,7 @@ export { generateForgotPasswordMetadata } from './meta.js'
const Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default const Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default
export const forgotPasswordBaseClass = 'forgot-password' export const forgotPasswordBaseClass = 'forgot-password'
export const ForgotPassword: React.FC<AdminViewProps> = ({ initPageResult }) => { export const ForgotPasswordView: React.FC<AdminViewProps> = ({ initPageResult }) => {
const { const {
req: { req: {
i18n, i18n,

View File

@@ -13,7 +13,7 @@ import React, { Fragment } from 'react'
import type { DefaultListViewProps, ListPreferences } from './Default/types.js' import type { DefaultListViewProps, ListPreferences } from './Default/types.js'
import { Unauthorized } from '../Unauthorized/index.js' import { UnauthorizedView } from '../Unauthorized/index.js'
import { DefaultListView } from './Default/index.js' import { DefaultListView } from './Default/index.js'
export { generateListMetadata } from './meta.js' export { generateListMetadata } from './meta.js'
@@ -35,7 +35,7 @@ export const ListView: React.FC<AdminViewProps> = async ({ initPageResult, searc
const collectionSlug = collectionConfig?.slug const collectionSlug = collectionConfig?.slug
if (!permissions?.collections?.[collectionSlug]?.read?.permission) { if (!permissions?.collections?.[collectionSlug]?.read?.permission) {
return <Unauthorized initPageResult={initPageResult} searchParams={searchParams} /> return <UnauthorizedView initPageResult={initPageResult} searchParams={searchParams} />
} }
let listPreferences: ListPreferences let listPreferences: ListPreferences

View File

@@ -11,7 +11,7 @@ export { generateLoginMetadata } from './meta.js'
export const loginBaseClass = 'login' export const loginBaseClass = 'login'
export const Login: React.FC<AdminViewProps> = ({ initPageResult, searchParams }) => { export const LoginView: React.FC<AdminViewProps> = ({ initPageResult, searchParams }) => {
const { req } = initPageResult const { req } = initPageResult
const { const {

View File

@@ -10,7 +10,7 @@ const baseClass = 'logout'
export { generateLogoutMetadata } from './meta.js' export { generateLogoutMetadata } from './meta.js'
export const Logout: React.FC< export const LogoutView: React.FC<
AdminViewProps & { AdminViewProps & {
inactivity?: boolean inactivity?: boolean
} }
@@ -39,5 +39,5 @@ export const Logout: React.FC<
} }
export const LogoutInactivity: React.FC<AdminViewProps> = (props) => { export const LogoutInactivity: React.FC<AdminViewProps> = (props) => {
return <Logout inactivity {...props} /> return <LogoutView inactivity {...props} />
} }

View File

@@ -1,6 +1,6 @@
import type { I18n } from '@payloadcms/translations' import type { I18n } from '@payloadcms/translations'
import type { Metadata } from 'next' import type { Metadata } from 'next'
import type { SanitizedConfig } from 'payload/types' import type { AdminViewComponent, SanitizedConfig } from 'payload/types'
import { getNextI18n } from '@payloadcms/next/utilities' import { getNextI18n } from '@payloadcms/next/utilities'
import { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser' import { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser'
@@ -65,3 +65,7 @@ export const NotFoundPage = async ({
</Fragment> </Fragment>
) )
} }
export const NotFoundView: AdminViewComponent = () => {
return <NotFoundClient marginTop="large" />
}

View File

@@ -4,15 +4,15 @@ import type { AdminViewComponent } from 'payload/types'
import type { initPage } from '../../utilities/initPage.js' import type { initPage } from '../../utilities/initPage.js'
import { Account } from '../Account/index.js' import { Account } from '../Account/index.js'
import { CreateFirstUser } from '../CreateFirstUser/index.js' import { CreateFirstUserView } from '../CreateFirstUser/index.js'
import { Dashboard } from '../Dashboard/index.js' import { Dashboard } from '../Dashboard/index.js'
import { Document as DocumentView } from '../Document/index.js' import { Document as DocumentView } from '../Document/index.js'
import { ForgotPassword, forgotPasswordBaseClass } from '../ForgotPassword/index.js' import { ForgotPasswordView, forgotPasswordBaseClass } from '../ForgotPassword/index.js'
import { ListView } from '../List/index.js' import { ListView } from '../List/index.js'
import { Login, loginBaseClass } from '../Login/index.js' import { LoginView, loginBaseClass } from '../Login/index.js'
import { Logout, LogoutInactivity } from '../Logout/index.js' import { LogoutInactivity, LogoutView } from '../Logout/index.js'
import { ResetPassword, resetPasswordBaseClass } from '../ResetPassword/index.js' import { ResetPassword, resetPasswordBaseClass } from '../ResetPassword/index.js'
import { Unauthorized } from '../Unauthorized/index.js' import { UnauthorizedView } from '../Unauthorized/index.js'
import { Verify, verifyBaseClass } from '../Verify/index.js' import { Verify, verifyBaseClass } from '../Verify/index.js'
import { getCustomViewByRoute } from './getCustomViewByRoute.js' import { getCustomViewByRoute } from './getCustomViewByRoute.js'
@@ -24,12 +24,12 @@ const baseClasses = {
} }
const oneSegmentViews = { const oneSegmentViews = {
'create-first-user': CreateFirstUser, 'create-first-user': CreateFirstUserView,
forgot: ForgotPassword, forgot: ForgotPasswordView,
login: Login, login: LoginView,
logout: Logout, logout: LogoutView,
'logout-inactivity': LogoutInactivity, 'logout-inactivity': LogoutInactivity,
unauthorized: Unauthorized, unauthorized: UnauthorizedView,
} }
export const getViewFromConfig = ({ export const getViewFromConfig = ({

View File

@@ -0,0 +1,36 @@
@import '../../scss/styles.scss';
.unauthorized {
margin-top: var(--base);
& > * {
&:first-child {
margin-top: 0;
}
&:last-child {
margin-bottom: 0;
}
}
&__button {
margin: 0;
}
&--margin-top-large {
margin-top: calc(var(--base) * 2);
}
@include large-break {
&--margin-top-large {
margin-top: var(--base);
}
}
@include small-break {
margin-top: calc(var(--base) / 2);
&--margin-top-large {
margin-top: calc(var(--base) / 2);
}
}
}

View File

@@ -5,11 +5,15 @@ import { Gutter } from '@payloadcms/ui/elements/Gutter'
import LinkImport from 'next/link.js' import LinkImport from 'next/link.js'
import React from 'react' import React from 'react'
import './index.scss'
const Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default const Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default
export { generateUnauthorizedMetadata } from './meta.js' export { generateUnauthorizedMetadata } from './meta.js'
export const Unauthorized: AdminViewComponent = ({ initPageResult }) => { const baseClass = 'unauthorized'
export const UnauthorizedView: AdminViewComponent = ({ initPageResult }) => {
const { const {
req: { req: {
i18n, i18n,
@@ -22,11 +26,10 @@ export const Unauthorized: AdminViewComponent = ({ initPageResult }) => {
} = initPageResult } = initPageResult
return ( return (
<Gutter className="unauthorized"> <Gutter className={baseClass}>
<h2>{i18n.t('error:unauthorized')}</h2> <h2>{i18n.t('error:unauthorized')}</h2>
<p>{i18n.t('error:notAllowedToAccessPage')}</p> <p>{i18n.t('error:notAllowedToAccessPage')}</p>
<br /> <Button Link={Link} className={`${baseClass}__button`} el="link" to={logoutRoute}>
<Button Link={Link} el="link" to={logoutRoute}>
{i18n.t('authentication:logOut')} {i18n.t('authentication:logOut')}
</Button> </Button>
</Gutter> </Gutter>

View File

@@ -1,4 +1,4 @@
export { RootLayout } from './layouts/Root/index.js' export { RootLayout } from './layouts/Root/index.js'
export { Dashboard as DashboardPage } from './views/Dashboard/index.js' export { Dashboard as DashboardPage } from './views/Dashboard/index.js'
export { Login } from './views/Login/index.js' export { LoginView } from './views/Login/index.js'
export { RootPage } from './views/Root/index.js' export { RootPage } from './views/Root/index.js'

View File

@@ -1,6 +1,6 @@
{ {
"name": "payload", "name": "payload",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"description": "Node, React and MongoDB Headless CMS and Application Framework", "description": "Node, React and MongoDB Headless CMS and Application Framework",
"license": "MIT", "license": "MIT",
"main": "./src/index.ts", "main": "./src/index.ts",

View File

@@ -1,7 +1,7 @@
{ {
"name": "@payloadcms/plugin-cloud-storage", "name": "@payloadcms/plugin-cloud-storage",
"description": "The official cloud storage plugin for Payload CMS", "description": "The official cloud storage plugin for Payload CMS",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"main": "./src/index.ts", "main": "./src/index.ts",
"types": "./src/index.ts", "types": "./src/index.ts",
"type": "module", "type": "module",

View File

@@ -1,7 +1,7 @@
{ {
"name": "@payloadcms/plugin-cloud", "name": "@payloadcms/plugin-cloud",
"description": "The official Payload Cloud plugin", "description": "The official Payload Cloud plugin",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"main": "./src/index.ts", "main": "./src/index.ts",
"types": "./src/index.ts", "types": "./src/index.ts",
"license": "MIT", "license": "MIT",

View File

@@ -1,7 +1,7 @@
{ {
"name": "@payloadcms/plugin-form-builder", "name": "@payloadcms/plugin-form-builder",
"description": "Form builder plugin for Payload CMS", "description": "Form builder plugin for Payload CMS",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"homepage:": "https://payloadcms.com", "homepage:": "https://payloadcms.com",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/plugin-nested-docs", "name": "@payloadcms/plugin-nested-docs",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"description": "The official Nested Docs plugin for Payload", "description": "The official Nested Docs plugin for Payload",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/plugin-redirects", "name": "@payloadcms/plugin-redirects",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"homepage:": "https://payloadcms.com", "homepage:": "https://payloadcms.com",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/plugin-search", "name": "@payloadcms/plugin-search",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"homepage:": "https://payloadcms.com", "homepage:": "https://payloadcms.com",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/plugin-seo", "name": "@payloadcms/plugin-seo",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"homepage:": "https://payloadcms.com", "homepage:": "https://payloadcms.com",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/richtext-lexical", "name": "@payloadcms/richtext-lexical",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"description": "The officially supported Lexical richtext adapter for Payload", "description": "The officially supported Lexical richtext adapter for Payload",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/richtext-slate", "name": "@payloadcms/richtext-slate",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"description": "The officially supported Slate richtext adapter for Payload", "description": "The officially supported Slate richtext adapter for Payload",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/translations", "name": "@payloadcms/translations",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"main": "./src/exports/index.ts", "main": "./src/exports/index.ts",
"types": "./src/types.ts", "types": "./src/types.ts",
"type": "module", "type": "module",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@payloadcms/ui", "name": "@payloadcms/ui",
"version": "3.0.0-alpha.58", "version": "3.0.0-alpha.59",
"type": "module", "type": "module",
"homepage": "https://payloadcms.com", "homepage": "https://payloadcms.com",
"repository": { "repository": {

View File

@@ -25,7 +25,6 @@ const DefaultSaveDraftButton: React.FC = () => {
const editDepth = useEditDepth() const editDepth = useEditDepth()
const { t } = useTranslation() const { t } = useTranslation()
const { submit } = useForm() const { submit } = useForm()
const label = t('general:save')
const saveDraft = useCallback(async () => { const saveDraft = useCallback(async () => {
const search = `?locale=${locale}&depth=0&fallback-locale=null&draft=true` const search = `?locale=${locale}&depth=0&fallback-locale=null&draft=true`
@@ -74,7 +73,7 @@ const DefaultSaveDraftButton: React.FC = () => {
size="small" size="small"
type="button" type="button"
> >
{label} {t('version:saveDraft')}
</FormSubmit> </FormSubmit>
) )
} }