Skip to content

Commit

Permalink
#1201 - [Backoffice] - Unable to add or edit Product Options due to r…
Browse files Browse the repository at this point in the history
…ecent bugs that came with the latest code (#1225)

* #1201 - [Backoffice] - Unable to add or edit Product Options due to recent bugs that came with the latest code

* #1201 - [Backoffice] - Unable to add or edit Product Options due to recent bugs that came with the latest code
  • Loading branch information
VanCongBang authored Oct 23, 2024
1 parent 9e83bcd commit 12ccc8f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions backoffice/pages/catalog/products/[id]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ const EditProduct: NextPage = () => {
}
};

useEffect(() => {
if (Object.keys(errors).length) {
setTabKey('general');
setTimeout(() => {
document.getElementById(Object.keys(errors)[0])?.scrollIntoView();
}, 0);
}
}, [errors]);

if (isLoading) return <p>Loading...</p>;
if (!product) {
return <p>No product</p>;
Expand Down
13 changes: 12 additions & 1 deletion backoffice/pages/catalog/products/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { mapFormProductToProductPayload } from '../../../modules/catalog/models/
import { createProductAttributeValueOfProduct } from '../../../modules/catalog/services/ProductAttributeValueService';
import { createProduct } from '../../../modules/catalog/services/ProductService';
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';

const ProductCreate: NextPage = () => {
const router = useRouter();
Expand All @@ -37,6 +38,7 @@ const ProductCreate: NextPage = () => {
isAllowedToOrder: true,
},
});
const [tabKey, setTabKey] = useState('general');

const onSubmitForm: SubmitHandler<FormProduct> = async (data) => {
try {
Expand Down Expand Up @@ -64,12 +66,21 @@ const ProductCreate: NextPage = () => {
}
};

useEffect(() => {
if (Object.keys(errors).length) {
setTabKey('general');
setTimeout(() => {
document.getElementById(Object.keys(errors)[0])?.scrollIntoView();
}, 0);
}
}, [errors]);

return (
<div className="create-product">
<h2>Create Product</h2>

<form onSubmit={handleSubmit(onSubmitForm)}>
<Tabs defaultActiveKey={'general'} className="mb-3">
<Tabs className="mb-3" activeKey={tabKey} onSelect={(e: any) => setTabKey(e)}>
<Tab eventKey={'general'} title="General Information">
<ProductGeneralInformation register={register} errors={errors} setValue={setValue} />
</Tab>
Expand Down

0 comments on commit 12ccc8f

Please sign in to comment.