* disable save in product edit & create when name is empty * code review refactor * Fix disabled button Co-authored-by: Magdalena Markusik <magdalena@markusik.com> * fix incorrect logic * fix incorrect logic * fix disable form on product variant Co-authored-by: Magdalena Markusik <magdalena@markusik.com> Co-authored-by: Magdalena Markusik <magdalena@markusik.com>
This commit is contained in:
parent
95c85a72ed
commit
c6e6aeff50
2 changed files with 56 additions and 17 deletions
|
@ -327,16 +327,35 @@ function useProductCreateForm(
|
|||
const data = getData();
|
||||
const submit = () => onSubmit(data);
|
||||
|
||||
const disabled =
|
||||
(!opts.selectedProductType?.hasVariants &&
|
||||
(data.channelListings.some(
|
||||
channel =>
|
||||
validatePrice(channel.price) || validateCostPrice(channel.costPrice)
|
||||
) ||
|
||||
!data.category)) ||
|
||||
(data.isPreorder &&
|
||||
const shouldEnableSave = () => {
|
||||
if (!data.name || !data.productType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
data.isPreorder &&
|
||||
data.hasPreorderEndDate &&
|
||||
!!form.errors.preorderEndDateTime);
|
||||
!!form.errors.preorderEndDateTime
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts.selectedProductType?.hasVariants) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const hasInvalidChannelListingPrices = data.channelListings.some(
|
||||
channel =>
|
||||
validatePrice(channel.price) || validateCostPrice(channel.costPrice)
|
||||
);
|
||||
|
||||
if (hasInvalidChannelListingPrices) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const disabled = !shouldEnableSave();
|
||||
|
||||
return {
|
||||
change: handleChange,
|
||||
|
|
|
@ -386,15 +386,35 @@ function useProductUpdateForm(
|
|||
const submit = async () =>
|
||||
handleFormSubmit(getSubmitData(), handleSubmit, setChanged);
|
||||
|
||||
const disabled =
|
||||
(!opts.hasVariants &&
|
||||
data.channelListings.some(
|
||||
channel =>
|
||||
validatePrice(channel.price) || validateCostPrice(channel.costPrice)
|
||||
)) ||
|
||||
(data.isPreorder &&
|
||||
const shouldEnableSave = () => {
|
||||
if (!data.name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
data.isPreorder &&
|
||||
data.hasPreorderEndDate &&
|
||||
!!form.errors.preorderEndDateTime);
|
||||
!!form.errors.preorderEndDateTime
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts.hasVariants) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const hasInvalidChannelListingPrices = data.channelListings.some(
|
||||
channel =>
|
||||
validatePrice(channel.price) || validateCostPrice(channel.costPrice)
|
||||
);
|
||||
|
||||
if (hasInvalidChannelListingPrices) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const disabled = !shouldEnableSave();
|
||||
|
||||
return {
|
||||
change: handleChange,
|
||||
|
|
Loading…
Reference in a new issue