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