Skip to content

Commit

Permalink
Dedupe + rename FormPage
Browse files Browse the repository at this point in the history
  • Loading branch information
apedroferreira committed Feb 17, 2025
1 parent a416385 commit 243b8c6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/toolpad-core/src/Crud/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import invariant from 'invariant';
import { FormPage } from './FormPage';
import { CrudForm } from './CrudForm';
import { DataModel, DataSource, OmitId } from './shared';
import { CrudContext } from '../shared/context';

Expand Down Expand Up @@ -56,7 +56,7 @@ function Create<D extends DataModel>(props: CreateProps<D>) {
);

return (
<FormPage
<CrudForm
dataSource={dataSource}
initialValues={initialValues}
onSubmit={handleCreate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ import dayjs, { Dayjs } from 'dayjs';
import { useNotifications } from '../useNotifications';
import { DataField, DataModel, DataSource, OmitId } from './shared';

interface FormPageLocaleText {
interface CrudFormLocaleText {
submitButtonLabel: string;
submitSuccessMessage: string;
submitErrorMessage: string;
}

export interface FormPageProps<D extends DataModel> {
export interface CrudFormProps<D extends DataModel> {
dataSource:
| (DataSource<D> & Required<Pick<DataSource<D>, 'createOne'>>)
| (DataSource<D> & Required<Pick<DataSource<D>, 'updateOne'>>);
initialValues?: Partial<OmitId<D>>;
onSubmit: (formValues: Partial<OmitId<D>>) => void | Promise<void>;
onSubmitSuccess?: () => void;
resetOnSubmit?: boolean;
localeText: FormPageLocaleText;
localeText: CrudFormLocaleText;
}

/**
* @ignore - internal component.
*/
function FormPage<D extends DataModel>(props: FormPageProps<D>) {
function CrudForm<D extends DataModel>(props: CrudFormProps<D>) {
const {
dataSource,
initialValues = {} as Partial<OmitId<D>>,
Expand Down Expand Up @@ -362,7 +362,7 @@ function FormPage<D extends DataModel>(props: FormPageProps<D>) {
);
}

FormPage.propTypes /* remove-proptypes */ = {
CrudForm.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
Expand All @@ -373,4 +373,4 @@ FormPage.propTypes /* remove-proptypes */ = {
dataSource: PropTypes.object.isRequired,
} as any;

export { FormPage };
export { CrudForm };
4 changes: 2 additions & 2 deletions packages/toolpad-core/src/Crud/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Alert from '@mui/material/Alert';
import Box from '@mui/material/Box';
import CircularProgress from '@mui/material/CircularProgress';
import invariant from 'invariant';
import { FormPage } from './FormPage';
import { CrudForm } from './CrudForm';
import { DataModel, DataModelId, DataSource, OmitId } from './shared';
import { CrudContext } from '../shared/context';

Expand Down Expand Up @@ -102,7 +102,7 @@ function Edit<D extends DataModel>(props: EditProps<D>) {
}

return data ? (
<FormPage
<CrudForm
dataSource={dataSource}
initialValues={data}
onSubmit={handleEdit}
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 243b8c6

Please sign in to comment.