further types
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
import React, {
|
||||
useState, createContext, useContext,
|
||||
} from 'react';
|
||||
|
||||
import PropTypes from 'prop-types';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Chevron from '../../icons/Chevron';
|
||||
import { Context } from './types';
|
||||
|
||||
import './index.scss';
|
||||
|
||||
const Context = createContext({});
|
||||
const Context = createContext({} as Context);
|
||||
|
||||
const StepNavProvider = ({ children }) => {
|
||||
const StepNavProvider: React.FC = ({ children }) => {
|
||||
const [stepNav, setStepNav] = useState([]);
|
||||
|
||||
return (
|
||||
@@ -24,16 +23,9 @@ const StepNavProvider = ({ children }) => {
|
||||
);
|
||||
};
|
||||
|
||||
StepNavProvider.propTypes = {
|
||||
children: PropTypes.oneOfType([
|
||||
PropTypes.arrayOf(PropTypes.node),
|
||||
PropTypes.node,
|
||||
]).isRequired,
|
||||
};
|
||||
const useStepNav = (): Context => useContext(Context);
|
||||
|
||||
const useStepNav = () => useContext(Context);
|
||||
|
||||
const StepNav = () => {
|
||||
const StepNav: React.FC = () => {
|
||||
const dashboardLabel = <span>Dashboard</span>;
|
||||
const { stepNav } = useStepNav();
|
||||
|
||||
@@ -46,8 +38,7 @@ const StepNav = () => {
|
||||
<Chevron />
|
||||
</Link>
|
||||
)
|
||||
: dashboardLabel
|
||||
}
|
||||
: dashboardLabel}
|
||||
{stepNav.map((item, i) => {
|
||||
const StepLabel = <span key={i}>{item.label}</span>;
|
||||
|
||||
|
||||
9
src/admin/components/elements/StepNav/types.ts
Normal file
9
src/admin/components/elements/StepNav/types.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export type StepNavItem = {
|
||||
label: string
|
||||
url?: string
|
||||
}
|
||||
|
||||
export type Context = {
|
||||
stepNav: StepNavItem[]
|
||||
setStepNav: (items: StepNavItem[]) => void
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
date picker
|
||||
handle remove
|
||||
file details
|
||||
paginator
|
||||
pill
|
||||
react select
|
||||
search filter
|
||||
sort complex
|
||||
table
|
||||
thumbnail
|
||||
upload gallery
|
||||
whereBuilder
|
||||
@@ -14,13 +14,13 @@ export type Fields = {
|
||||
}
|
||||
|
||||
export type Data = {
|
||||
[key: string]: unknown
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export type Props = {
|
||||
disabled?: boolean
|
||||
onSubmit?: (fields: Fields, data: Data) => void
|
||||
method?: 'GET' | 'PUT' | 'DELETE' | 'POST'
|
||||
method?: 'get' | 'put' | 'delete' | 'post'
|
||||
action?: string
|
||||
handleResponse?: (res: Response) => void
|
||||
onSuccess?: (json: unknown) => void
|
||||
|
||||
@@ -69,11 +69,7 @@ const RenderFields: React.FC<Props> = (props) => {
|
||||
if ((filter && typeof filter === 'function' && filter(field)) || !filter) {
|
||||
const FieldComponent = field?.admin?.hidden ? fieldTypes.hidden : fieldTypes[field.type];
|
||||
|
||||
let fieldPermissions = permissions?.[field.name];
|
||||
|
||||
if (!field.name) {
|
||||
fieldPermissions = permissions;
|
||||
}
|
||||
const fieldPermissions = field?.name ? permissions?.[field.name] : permissions;
|
||||
|
||||
let { admin: { readOnly } = {} } = field;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { CollectionPermission, GlobalPermission } from '../../../../auth/types';
|
||||
import { Field } from '../../../../fields/config/types';
|
||||
import { CollectionFieldPermissions, GlobalFieldPermissions } from '../../../../auth/types';
|
||||
import { FieldWithPath } from '../../../../fields/config/types';
|
||||
import { FieldTypes } from '../field-types';
|
||||
|
||||
export type Operation = 'create' | 'update'
|
||||
|
||||
@@ -11,7 +12,8 @@ export type Props = {
|
||||
className?: string
|
||||
operation: Operation
|
||||
readOnly: boolean
|
||||
permissions: CollectionPermission | GlobalPermission
|
||||
permissions: CollectionFieldPermissions | GlobalFieldPermissions
|
||||
filter: (field: Field) => boolean
|
||||
fieldSchema: Field[]
|
||||
fieldSchema: FieldWithPath[]
|
||||
fieldTypes: FieldTypes
|
||||
}
|
||||
|
||||
@@ -19,7 +19,28 @@ import array from './Array';
|
||||
import row from './Row';
|
||||
import upload from './Upload';
|
||||
|
||||
export default {
|
||||
export type FieldTypes = {
|
||||
code: React.ComponentType
|
||||
email: React.ComponentType
|
||||
hidden: React.ComponentType
|
||||
text: React.ComponentType
|
||||
date: React.ComponentType
|
||||
password: React.ComponentType
|
||||
relationship: React.ComponentType
|
||||
textarea: React.ComponentType
|
||||
select: React.ComponentType
|
||||
number: React.ComponentType
|
||||
checkbox: React.ComponentType
|
||||
richText: React.ComponentType
|
||||
radio: React.ComponentType
|
||||
blocks: React.ComponentType
|
||||
group: React.ComponentType
|
||||
array: React.ComponentType
|
||||
row: React.ComponentType
|
||||
upload: React.ComponentType
|
||||
}
|
||||
|
||||
const fieldTypes: FieldTypes = {
|
||||
code,
|
||||
email,
|
||||
hidden,
|
||||
@@ -39,3 +60,5 @@ export default {
|
||||
row,
|
||||
upload,
|
||||
};
|
||||
|
||||
export default fieldTypes;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Link } from 'react-router-dom';
|
||||
import format from 'date-fns/format';
|
||||
import { useConfig } from '@payloadcms/config-provider';
|
||||
@@ -15,12 +14,13 @@ import LeaveWithoutSaving from '../../modals/LeaveWithoutSaving';
|
||||
import Meta from '../../utilities/Meta';
|
||||
import Auth from '../collections/Edit/Auth';
|
||||
import Loading from '../../elements/Loading';
|
||||
import { Props } from './types';
|
||||
|
||||
import './index.scss';
|
||||
|
||||
const baseClass = 'account';
|
||||
|
||||
const DefaultAccount = (props) => {
|
||||
const DefaultAccount: React.FC<Props> = (props) => {
|
||||
const {
|
||||
collection,
|
||||
data,
|
||||
@@ -86,7 +86,7 @@ const DefaultAccount = (props) => {
|
||||
operation="update"
|
||||
permissions={permissions.fields}
|
||||
readOnly={!hasSavePermission}
|
||||
filter={(field) => (!field.position || field?.admin?.position !== 'sidebar')}
|
||||
filter={(field) => field?.admin?.position !== 'sidebar'}
|
||||
fieldTypes={fieldTypes}
|
||||
fieldSchema={fields}
|
||||
/>
|
||||
@@ -128,7 +128,6 @@ const DefaultAccount = (props) => {
|
||||
permissions={permissions.fields}
|
||||
readOnly={!hasSavePermission}
|
||||
filter={(field) => field?.admin?.position === 'sidebar'}
|
||||
position="sidebar"
|
||||
fieldTypes={fieldTypes}
|
||||
fieldSchema={fields}
|
||||
/>
|
||||
@@ -162,54 +161,4 @@ const DefaultAccount = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
DefaultAccount.defaultProps = {
|
||||
isEditing: false,
|
||||
data: undefined,
|
||||
onSave: null,
|
||||
};
|
||||
|
||||
DefaultAccount.propTypes = {
|
||||
hasSavePermission: PropTypes.bool.isRequired,
|
||||
apiURL: PropTypes.string.isRequired,
|
||||
action: PropTypes.string.isRequired,
|
||||
collection: PropTypes.shape({
|
||||
labels: PropTypes.shape({
|
||||
plural: PropTypes.string,
|
||||
singular: PropTypes.string,
|
||||
}),
|
||||
slug: PropTypes.string,
|
||||
admin: PropTypes.shape({
|
||||
useAsTitle: PropTypes.string,
|
||||
}),
|
||||
fields: PropTypes.arrayOf(PropTypes.shape({})),
|
||||
preview: PropTypes.func,
|
||||
timestamps: PropTypes.bool,
|
||||
auth: PropTypes.shape({
|
||||
useAPIKey: PropTypes.bool,
|
||||
}),
|
||||
}).isRequired,
|
||||
isEditing: PropTypes.bool,
|
||||
data: PropTypes.shape({
|
||||
updatedAt: PropTypes.string,
|
||||
createdAt: PropTypes.string,
|
||||
id: PropTypes.string,
|
||||
email: PropTypes.string,
|
||||
}),
|
||||
permissions: PropTypes.shape({
|
||||
create: PropTypes.shape({
|
||||
permission: PropTypes.bool,
|
||||
}),
|
||||
update: PropTypes.shape({
|
||||
permission: PropTypes.bool,
|
||||
}),
|
||||
delete: PropTypes.shape({
|
||||
permission: PropTypes.bool,
|
||||
}),
|
||||
fields: PropTypes.shape({}),
|
||||
}).isRequired,
|
||||
onSave: PropTypes.func,
|
||||
initialState: PropTypes.shape({}).isRequired,
|
||||
isLoading: PropTypes.bool.isRequired,
|
||||
};
|
||||
|
||||
export default DefaultAccount;
|
||||
|
||||
14
src/admin/components/views/Account/types.ts
Normal file
14
src/admin/components/views/Account/types.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { CollectionConfig } from '../../../../collections/config/types';
|
||||
import { Fields, Data } from '../../forms/Form/types';
|
||||
import { CollectionPermission } from '../../../../auth/types';
|
||||
|
||||
export type Props = {
|
||||
hasSavePermission: boolean
|
||||
apiURL: string
|
||||
collection: CollectionConfig
|
||||
data: Data
|
||||
permissions: CollectionPermission
|
||||
initialState: Fields
|
||||
isLoading: boolean
|
||||
action: string
|
||||
}
|
||||
Reference in New Issue
Block a user