Fix types
This commit is contained in:
parent
a27a029452
commit
623ec69e1f
5 changed files with 10 additions and 8 deletions
|
@ -6,7 +6,7 @@ export interface FormProps<T> {
|
||||||
confirmLeave?: boolean;
|
confirmLeave?: boolean;
|
||||||
initial?: T;
|
initial?: T;
|
||||||
resetOnSubmit?: boolean;
|
resetOnSubmit?: boolean;
|
||||||
onSubmit?: (data: T) => void;
|
onSubmit?: (data: T) => Promise<any[]> | void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Form<T>(props: FormProps<T>) {
|
function Form<T>(props: FormProps<T>) {
|
||||||
|
|
|
@ -76,7 +76,7 @@ const CustomerCreatePage: React.FC<CustomerCreatePageProps> = ({
|
||||||
const {
|
const {
|
||||||
errors: validationErrors,
|
errors: validationErrors,
|
||||||
submit: handleSubmitWithAddress
|
submit: handleSubmitWithAddress
|
||||||
} = useAddressValidation<CustomerCreatePageFormData>(formData =>
|
} = useAddressValidation<CustomerCreatePageFormData, void>(formData =>
|
||||||
onSubmit({
|
onSubmit({
|
||||||
address: {
|
address: {
|
||||||
city: formData.city,
|
city: formData.city,
|
||||||
|
|
|
@ -45,7 +45,7 @@ export interface PageDetailsPageProps {
|
||||||
saveButtonBarState: ConfirmButtonTransitionState;
|
saveButtonBarState: ConfirmButtonTransitionState;
|
||||||
onBack: () => void;
|
onBack: () => void;
|
||||||
onRemove: () => void;
|
onRemove: () => void;
|
||||||
onSubmit: (data: PageDetailsPageFormData) => void;
|
onSubmit: (data: PageDetailsPageFormData) => Promise<any[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
||||||
|
@ -84,13 +84,13 @@ const PageDetailsPage: React.FC<PageDetailsPageProps> = ({
|
||||||
title: page?.title || ""
|
title: page?.title || ""
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = (data: FormData) => {
|
const handleSubmit = (data: PageDetailsPageFormData) => {
|
||||||
const metadata = isMetadataModified ? data.metadata : undefined;
|
const metadata = isMetadataModified ? data.metadata : undefined;
|
||||||
const privateMetadata = isPrivateMetadataModified
|
const privateMetadata = isPrivateMetadataModified
|
||||||
? data.privateMetadata
|
? data.privateMetadata
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
onSubmit({
|
return onSubmit({
|
||||||
...data,
|
...data,
|
||||||
isPublished: data.isPublished || !!data.publicationDate,
|
isPublished: data.isPublished || !!data.publicationDate,
|
||||||
metadata,
|
metadata,
|
||||||
|
|
|
@ -9,7 +9,9 @@ import {
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import PageDetailsPage, { FormData } from "../components/PageDetailsPage";
|
import PageDetailsPage, {
|
||||||
|
PageDetailsPageFormData
|
||||||
|
} from "../components/PageDetailsPage";
|
||||||
import { TypedPageCreate } from "../mutations";
|
import { TypedPageCreate } from "../mutations";
|
||||||
import { PageCreate as PageCreateData } from "../types/PageCreate";
|
import { PageCreate as PageCreateData } from "../types/PageCreate";
|
||||||
import { pageListUrl, pageUrl } from "../urls";
|
import { pageListUrl, pageUrl } from "../urls";
|
||||||
|
@ -40,7 +42,7 @@ export const PageCreate: React.FC<PageCreateProps> = () => {
|
||||||
return (
|
return (
|
||||||
<TypedPageCreate onCompleted={handlePageCreate}>
|
<TypedPageCreate onCompleted={handlePageCreate}>
|
||||||
{(pageCreate, pageCreateOpts) => {
|
{(pageCreate, pageCreateOpts) => {
|
||||||
const handleCreate = async (formData: FormData) => {
|
const handleCreate = async (formData: PageDetailsPageFormData) => {
|
||||||
const result = await pageCreate({
|
const result = await pageCreate({
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
|
|
|
@ -58,7 +58,7 @@ const WarehouseCreatePage: React.FC<WarehouseCreatePageProps> = ({
|
||||||
const {
|
const {
|
||||||
errors: validationErrors,
|
errors: validationErrors,
|
||||||
submit: handleSubmit
|
submit: handleSubmit
|
||||||
} = useAddressValidation<WarehouseCreatePageFormData>(onSubmit);
|
} = useAddressValidation(onSubmit);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form initial={initialForm} onSubmit={handleSubmit}>
|
<Form initial={initialForm} onSubmit={handleSubmit}>
|
||||||
|
|
Loading…
Reference in a new issue