wip
This commit is contained in:
parent
785c34375e
commit
5262e97b20
1 changed files with 68 additions and 31 deletions
|
@ -12,9 +12,7 @@ import { ProductVariantCreateFormData } from "./form";
|
||||||
|
|
||||||
export enum ProductVariantCreateReducerActionType {
|
export enum ProductVariantCreateReducerActionType {
|
||||||
applyPriceToAll,
|
applyPriceToAll,
|
||||||
applyPriceToAttribute,
|
|
||||||
applyStockToAll,
|
applyStockToAll,
|
||||||
applyStockToAttribute,
|
|
||||||
changeApplyPriceToAllValue,
|
changeApplyPriceToAllValue,
|
||||||
changeApplyPriceToAttributeId,
|
changeApplyPriceToAttributeId,
|
||||||
changeApplyStockToAllValue,
|
changeApplyStockToAllValue,
|
||||||
|
@ -29,17 +27,39 @@ export enum ProductVariantCreateReducerActionType {
|
||||||
}
|
}
|
||||||
export type VariantField = "price" | "sku";
|
export type VariantField = "price" | "sku";
|
||||||
export interface ProductVariantCreateReducerAction {
|
export interface ProductVariantCreateReducerAction {
|
||||||
all?: boolean;
|
applyPriceOrStockToAll?: {
|
||||||
attributeId?: string;
|
all: boolean;
|
||||||
data?: ProductVariantCreateFormData;
|
};
|
||||||
field?: VariantField;
|
changeApplyPriceToAllValue?: {
|
||||||
quantity?: number;
|
value: string;
|
||||||
stock?: StockInput;
|
};
|
||||||
|
changeApplyPriceOrStockToAttributeId?: {
|
||||||
|
attributeId: string;
|
||||||
|
};
|
||||||
|
changeApplyStockToAllValue?: Record<"quantity" | "warehouseIndex", number>;
|
||||||
|
changeAttributeValuePrice?: Record<"valueId" | "price", string>;
|
||||||
|
changeAttributeValueStock?: {
|
||||||
|
valueId: string;
|
||||||
|
quantity: number;
|
||||||
|
warehouseIndex: number;
|
||||||
|
};
|
||||||
|
changeVariantData?: {
|
||||||
|
field: VariantField;
|
||||||
|
value: string;
|
||||||
|
variantIndex: number;
|
||||||
|
};
|
||||||
|
changeVariantStockData?: {
|
||||||
|
stock: StockInput;
|
||||||
|
variantIndex: number;
|
||||||
|
};
|
||||||
|
deleteVariant?: {
|
||||||
|
variantIndex: number;
|
||||||
|
};
|
||||||
|
reload?: {
|
||||||
|
data?: ProductVariantCreateFormData;
|
||||||
|
};
|
||||||
|
selectValue?: Record<"attributeId" | "valueId", string>;
|
||||||
type: ProductVariantCreateReducerActionType;
|
type: ProductVariantCreateReducerActionType;
|
||||||
value?: string;
|
|
||||||
valueId?: string;
|
|
||||||
variantIndex?: number;
|
|
||||||
warehouseIndex?: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectValue(
|
function selectValue(
|
||||||
|
@ -319,49 +339,66 @@ function reduceProductVariantCreateFormData(
|
||||||
) {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ProductVariantCreateReducerActionType.selectValue:
|
case ProductVariantCreateReducerActionType.selectValue:
|
||||||
return selectValue(prevState, action.attributeId, action.valueId);
|
return selectValue(
|
||||||
|
prevState,
|
||||||
|
action.selectValue.attributeId,
|
||||||
|
action.selectValue.attributeId
|
||||||
|
);
|
||||||
case ProductVariantCreateReducerActionType.applyPriceToAll:
|
case ProductVariantCreateReducerActionType.applyPriceToAll:
|
||||||
return applyPriceToAll(prevState, action.all);
|
return applyPriceToAll(prevState, action.applyPriceOrStockToAll.all);
|
||||||
case ProductVariantCreateReducerActionType.applyStockToAll:
|
case ProductVariantCreateReducerActionType.applyStockToAll:
|
||||||
return applyStockToAll(prevState, action.all);
|
return applyStockToAll(prevState, action.applyPriceOrStockToAll.all);
|
||||||
case ProductVariantCreateReducerActionType.changeAttributeValuePrice:
|
case ProductVariantCreateReducerActionType.changeAttributeValuePrice:
|
||||||
return changeAttributeValuePrice(prevState, action.valueId, action.value);
|
return changeAttributeValuePrice(
|
||||||
|
prevState,
|
||||||
|
action.changeAttributeValuePrice.valueId,
|
||||||
|
action.changeAttributeValuePrice.price
|
||||||
|
);
|
||||||
case ProductVariantCreateReducerActionType.changeAttributeValueStock:
|
case ProductVariantCreateReducerActionType.changeAttributeValueStock:
|
||||||
return changeAttributeValueStock(
|
return changeAttributeValueStock(
|
||||||
prevState,
|
prevState,
|
||||||
action.valueId,
|
action.changeAttributeValueStock.valueId,
|
||||||
action.quantity,
|
action.changeAttributeValueStock.warehouseIndex,
|
||||||
action.warehouseIndex
|
action.changeAttributeValueStock.quantity
|
||||||
);
|
);
|
||||||
case ProductVariantCreateReducerActionType.changeApplyPriceToAttributeId:
|
case ProductVariantCreateReducerActionType.changeApplyPriceToAttributeId:
|
||||||
return changeApplyPriceToAttributeId(prevState, action.attributeId);
|
return changeApplyPriceToAttributeId(
|
||||||
|
prevState,
|
||||||
|
action.changeApplyPriceOrStockToAttributeId.attributeId
|
||||||
|
);
|
||||||
case ProductVariantCreateReducerActionType.changeApplyStockToAttributeId:
|
case ProductVariantCreateReducerActionType.changeApplyStockToAttributeId:
|
||||||
return changeApplyStockToAttributeId(prevState, action.attributeId);
|
return changeApplyStockToAttributeId(
|
||||||
|
prevState,
|
||||||
|
action.changeApplyPriceOrStockToAttributeId.attributeId
|
||||||
|
);
|
||||||
case ProductVariantCreateReducerActionType.changeApplyPriceToAllValue:
|
case ProductVariantCreateReducerActionType.changeApplyPriceToAllValue:
|
||||||
return changeApplyPriceToAllValue(prevState, action.value);
|
return changeApplyPriceToAllValue(
|
||||||
|
prevState,
|
||||||
|
action.changeApplyPriceToAllValue.value
|
||||||
|
);
|
||||||
case ProductVariantCreateReducerActionType.changeApplyStockToAllValue:
|
case ProductVariantCreateReducerActionType.changeApplyStockToAllValue:
|
||||||
return changeApplyStockToAllValue(
|
return changeApplyStockToAllValue(
|
||||||
prevState,
|
prevState,
|
||||||
action.quantity,
|
action.changeApplyStockToAllValue.quantity,
|
||||||
action.warehouseIndex
|
action.changeApplyStockToAllValue.warehouseIndex
|
||||||
);
|
);
|
||||||
case ProductVariantCreateReducerActionType.changeVariantData:
|
case ProductVariantCreateReducerActionType.changeVariantData:
|
||||||
return changeVariantData(
|
return changeVariantData(
|
||||||
prevState,
|
prevState,
|
||||||
action.field,
|
action.changeVariantData.field,
|
||||||
action.value,
|
action.changeVariantData.value,
|
||||||
action.variantIndex
|
action.changeVariantData.variantIndex
|
||||||
);
|
);
|
||||||
case ProductVariantCreateReducerActionType.changeVariantStockData:
|
case ProductVariantCreateReducerActionType.changeVariantStockData:
|
||||||
return changeVariantStockData(
|
return changeVariantStockData(
|
||||||
prevState,
|
prevState,
|
||||||
action.stock,
|
action.changeVariantStockData.stock,
|
||||||
action.variantIndex
|
action.changeVariantStockData.variantIndex
|
||||||
);
|
);
|
||||||
case ProductVariantCreateReducerActionType.deleteVariant:
|
case ProductVariantCreateReducerActionType.deleteVariant:
|
||||||
return deleteVariant(prevState, action.variantIndex);
|
return deleteVariant(prevState, action.deleteVariant.variantIndex);
|
||||||
case ProductVariantCreateReducerActionType.reload:
|
case ProductVariantCreateReducerActionType.reload:
|
||||||
return action.data ? action.data : createVariantMatrix(prevState);
|
return action.reload.data || createVariantMatrix(prevState);
|
||||||
default:
|
default:
|
||||||
return prevState;
|
return prevState;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue