Improve typing
This commit is contained in:
parent
a34d22de8f
commit
63f042a91b
3 changed files with 28 additions and 26 deletions
|
@ -56,10 +56,7 @@ export interface ProductCreateData extends ProductCreateFormData {
|
||||||
stocks: ProductStockInput[];
|
stocks: ProductStockInput[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UseProductCreateFormResult {
|
type ProductCreateHandlers = Record<
|
||||||
change: FormChange;
|
|
||||||
data: ProductCreateData;
|
|
||||||
handlers: Record<
|
|
||||||
| "changeMetadata"
|
| "changeMetadata"
|
||||||
| "selectCategory"
|
| "selectCategory"
|
||||||
| "selectCollection"
|
| "selectCollection"
|
||||||
|
@ -69,9 +66,13 @@ export interface UseProductCreateFormResult {
|
||||||
> &
|
> &
|
||||||
Record<
|
Record<
|
||||||
"changeStock" | "selectAttribute" | "selectAttributeMultiple",
|
"changeStock" | "selectAttribute" | "selectAttributeMultiple",
|
||||||
FormsetChange
|
FormsetChange<string>
|
||||||
> &
|
> &
|
||||||
Record<"addStock" | "deleteStock", (id: string) => void>;
|
Record<"addStock" | "deleteStock", (id: string) => void>;
|
||||||
|
export interface UseProductCreateFormResult {
|
||||||
|
change: FormChange;
|
||||||
|
data: ProductCreateData;
|
||||||
|
handlers: ProductCreateHandlers;
|
||||||
hasChanged: boolean;
|
hasChanged: boolean;
|
||||||
submit: () => Promise<boolean>;
|
submit: () => Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +187,7 @@ function useProductCreateForm(
|
||||||
opts.productTypes,
|
opts.productTypes,
|
||||||
triggerChange
|
triggerChange
|
||||||
);
|
);
|
||||||
const handleStockChange: FormsetChange = (id, value) => {
|
const handleStockChange: FormsetChange<string> = (id, value) => {
|
||||||
triggerChange();
|
triggerChange();
|
||||||
stocks.change(id, value);
|
stocks.change(id, value);
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,18 +62,19 @@ export interface ProductUpdateSubmitData extends ProductUpdateFormData {
|
||||||
removeStocks: string[];
|
removeStocks: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UseProductUpdateFormResult {
|
type ProductUpdateHandlers = Record<
|
||||||
change: FormChange;
|
|
||||||
data: ProductUpdateData;
|
|
||||||
handlers: Record<
|
|
||||||
"changeMetadata" | "selectCategory" | "selectCollection" | "selectTaxRate",
|
"changeMetadata" | "selectCategory" | "selectCollection" | "selectTaxRate",
|
||||||
FormChange
|
FormChange
|
||||||
> &
|
> &
|
||||||
Record<
|
Record<
|
||||||
"changeStock" | "selectAttribute" | "selectAttributeMultiple",
|
"changeStock" | "selectAttribute" | "selectAttributeMultiple",
|
||||||
FormsetChange
|
FormsetChange<string>
|
||||||
> &
|
> &
|
||||||
Record<"addStock" | "deleteStock", (id: string) => void>;
|
Record<"addStock" | "deleteStock", (id: string) => void>;
|
||||||
|
export interface UseProductUpdateFormResult {
|
||||||
|
change: FormChange;
|
||||||
|
data: ProductUpdateData;
|
||||||
|
handlers: ProductUpdateHandlers;
|
||||||
hasChanged: boolean;
|
hasChanged: boolean;
|
||||||
submit: () => Promise<boolean>;
|
submit: () => Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
@ -185,7 +186,7 @@ function useProductUpdateForm(
|
||||||
attributes.data,
|
attributes.data,
|
||||||
triggerChange
|
triggerChange
|
||||||
);
|
);
|
||||||
const handleStockChange: FormsetChange = (id, value) => {
|
const handleStockChange: FormsetChange<string> = (id, value) => {
|
||||||
triggerChange();
|
triggerChange();
|
||||||
stocks.change(id, value);
|
stocks.change(id, value);
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { getAttributeInputFromProductType, ProductType } from "./data";
|
||||||
export function createAttributeChangeHandler(
|
export function createAttributeChangeHandler(
|
||||||
changeAttributeData: FormsetChange<string[]>,
|
changeAttributeData: FormsetChange<string[]>,
|
||||||
triggerChange: () => void
|
triggerChange: () => void
|
||||||
): FormsetChange {
|
): FormsetChange<string> {
|
||||||
return (attributeId: string, value: string) => {
|
return (attributeId: string, value: string) => {
|
||||||
triggerChange();
|
triggerChange();
|
||||||
changeAttributeData(attributeId, value === "" ? [] : [value]);
|
changeAttributeData(attributeId, value === "" ? [] : [value]);
|
||||||
|
@ -19,7 +19,7 @@ export function createAttributeMultiChangeHandler(
|
||||||
changeAttributeData: FormsetChange<string[]>,
|
changeAttributeData: FormsetChange<string[]>,
|
||||||
attributes: FormsetData<ProductAttributeInputData, string[]>,
|
attributes: FormsetData<ProductAttributeInputData, string[]>,
|
||||||
triggerChange: () => void
|
triggerChange: () => void
|
||||||
): FormsetChange {
|
): FormsetChange<string> {
|
||||||
return (attributeId: string, value: string) => {
|
return (attributeId: string, value: string) => {
|
||||||
const attribute = attributes.find(
|
const attribute = attributes.find(
|
||||||
attribute => attribute.id === attributeId
|
attribute => attribute.id === attributeId
|
||||||
|
|
Loading…
Reference in a new issue