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