* 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 data = getData();
|
||||||
const submit = () => onSubmit(data);
|
const submit = () => onSubmit(data);
|
||||||
|
|
||||||
const disabled =
|
const shouldEnableSave = () => {
|
||||||
(!opts.selectedProductType?.hasVariants &&
|
if (!data.name || !data.productType) {
|
||||||
(data.channelListings.some(
|
return false;
|
||||||
channel =>
|
}
|
||||||
validatePrice(channel.price) || validateCostPrice(channel.costPrice)
|
|
||||||
) ||
|
if (
|
||||||
!data.category)) ||
|
data.isPreorder &&
|
||||||
(data.isPreorder &&
|
|
||||||
data.hasPreorderEndDate &&
|
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 {
|
return {
|
||||||
change: handleChange,
|
change: handleChange,
|
||||||
|
|
|
@ -386,15 +386,35 @@ function useProductUpdateForm(
|
||||||
const submit = async () =>
|
const submit = async () =>
|
||||||
handleFormSubmit(getSubmitData(), handleSubmit, setChanged);
|
handleFormSubmit(getSubmitData(), handleSubmit, setChanged);
|
||||||
|
|
||||||
const disabled =
|
const shouldEnableSave = () => {
|
||||||
(!opts.hasVariants &&
|
if (!data.name) {
|
||||||
data.channelListings.some(
|
return false;
|
||||||
channel =>
|
}
|
||||||
validatePrice(channel.price) || validateCostPrice(channel.costPrice)
|
|
||||||
)) ||
|
if (
|
||||||
(data.isPreorder &&
|
data.isPreorder &&
|
||||||
data.hasPreorderEndDate &&
|
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 {
|
return {
|
||||||
change: handleChange,
|
change: handleChange,
|
||||||
|
|
Loading…
Reference in a new issue