Skip to content

Commit

Permalink
Merge pull request #255 from alphasolutionsrepo/development
Browse files Browse the repository at this point in the history
fixed editing of a category and list of more than 20 categories
  • Loading branch information
crhistianramirez authored Mar 15, 2024
2 parents 77c4b1c + c1fdf60 commit 90dae5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/components/categories/CategoryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function CategoryForm({category, headerComponent, parentId, onSuccess}: C
const {handleSubmit, control, reset} = useForm<ICategory>({
resolver: yupResolver(validationSchema) as any,
defaultValues: category || defaultValues,
values: category,
mode: "onBlur"
})

Expand Down Expand Up @@ -79,10 +80,10 @@ export function CategoryForm({category, headerComponent, parentId, onSuccess}: C
}

async function onSubmit(fields: ICategory) {
if (isCreating) {
await createCategory(fields)
} else {
if (control._defaultValues?.ID) {
await updateCategory(fields)
} else {
await createCategory(fields)
}
}

Expand Down Expand Up @@ -129,7 +130,7 @@ export function CategoryForm({category, headerComponent, parentId, onSuccess}: C
name="Description"
label="Description"
control={control}
validationSchema={validationSchema}
validationSchema={validationSchema}
/>
<SwitchControl
name="Active"
Expand All @@ -138,6 +139,7 @@ export function CategoryForm({category, headerComponent, parentId, onSuccess}: C
size="lg"
control={control}
validationSchema={validationSchema}

/>
<ButtonGroup>
<HStack justifyContent="space-between" w="100%" mb={5}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,22 @@ const CategoriesList = (props) => {

const initCategoriesData = useCallback(
async (catalogid: string) => {
const categoriesList = await Categories.List<ICategory>(catalogid,{depth:"all"})
const categoriesList = await Categories.List<ICategory>(catalogid,{depth:"99", pageSize:100})
let cl = categoriesList.Items;
let i = 2;
while (cl.length < categoriesList.Meta.TotalCount) {
const l = (await Categories.List<ICategory>(catalogid,{depth:"99", pageSize:100, page:i}));
cl = cl.concat( l.Items);
i++;
}
if (selectedNode) {
const selectedCategoryId = selectedNode.data.ID
const selectedCategoryExists = categoriesList.Items.find((category) => category.ID === selectedCategoryId)
const selectedCategoryExists = cl.find((category) => category.ID === selectedCategoryId)
if (!selectedCategoryExists) {
setSelectedNode(null)
}
}
setCategoriesTreeView(await buildTreeView(categoriesList.Items))
setCategoriesTreeView(await buildTreeView(cl))
},
[selectedNode]
)
Expand Down Expand Up @@ -74,7 +81,7 @@ const CategoriesList = (props) => {

return treeViewData
}
const handleSelect = (node: ocNodeModel) => setSelectedNode(node)
const handleSelect = (node: ocNodeModel) => { setSelectedNode(node);}

const handleCategoryCreate = (category: Category) => {
setParentIdToCreate(category?.ID)
Expand All @@ -86,6 +93,7 @@ const CategoriesList = (props) => {
await initCategoriesData(router.query.catalogid as string)
}


return (
<>
<Box padding="20px">
Expand Down Expand Up @@ -118,7 +126,7 @@ const CategoriesList = (props) => {
/>
</GridItem>
<GridItem pl="2" area={"main"}>
{selectedNode ? (
{selectedNode?.id ? (
<CategoryForm
category={selectedNode.data}
onSuccess={onCategoryCreateSuccess}
Expand All @@ -131,7 +139,7 @@ const CategoriesList = (props) => {
) : (
<CategoryForm
onSuccess={onCategoryCreateSuccess}
category={{Name: "", Description: "", Active: false, ParentID: ""}}
category={{Name: "", Description: "", Active: true, ParentID: ""}}
headerComponent={
<Heading as="h5" size="md" marginLeft={10} marginTop={5}>
Create root category
Expand Down

0 comments on commit 90dae5d

Please sign in to comment.