1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

Remove react-beautiful-dnd

This commit is contained in:
vincent 2022-07-25 19:42:24 +02:00 committed by Sylvain
parent 4f90cb5d80
commit 81cc8db0f5
3 changed files with 51 additions and 2 deletions

View File

@ -0,0 +1,41 @@
import React from 'react';
import { ProductCategory } from '../../../models/product-category';
import { ManageProductCategory } from './manage-product-category';
import { FabButton } from '../../base/fab-button';
import { DotsSixVertical } from 'phosphor-react';
interface ProductCategoriesItemProps {
productCategories: Array<ProductCategory>,
category: ProductCategory,
onSuccess: (message: string) => void,
onError: (message: string) => void,
}
/**
* Renders a draggable category item
*/
export const ProductCategoriesItem: React.FC<ProductCategoriesItemProps> = ({ productCategories, category, onSuccess, onError }) => {
return (
<div key={category.id} className='product-categories-item'>
<div className='itemInfo'>
<p className='itemInfo-name'>{category.name}</p>
<span className='itemInfo-count'>[count]</span>
</div>
<div className='action'>
<div className='manage'>
<ManageProductCategory action='update'
productCategories={productCategories}
productCategory={category}
onSuccess={onSuccess} onError={onError} />
<ManageProductCategory action='delete'
productCategories={productCategories}
productCategory={category}
onSuccess={onSuccess} onError={onError} />
</div>
<div>
<FabButton icon={<DotsSixVertical size={16} />} className='draghandle' />
</div>
</div>
</div>
);
};

View File

@ -32,15 +32,22 @@ export const ProductCategoryForm: React.FC<ProductCategoryFormProps> = ({ action
const { register, watch, setValue, control, handleSubmit, formState } = useForm<ProductCategory>({ defaultValues: { ...productCategory } });
// filter all first level product categorie
const parents = productCategories.filter(c => !c.parent_id);
let parents = productCategories.filter(c => !c.parent_id);
if (action === 'update') {
parents = parents.filter(c => c.id !== productCategory.id);
}
/**
* Convert all parents to the react-select format
*/
const buildOptions = (): Array<selectOption> => {
return parents.map(t => {
const options = parents.map(t => {
return { value: t.id, label: t.name };
});
if (action === 'update') {
options.unshift({ value: null, label: t('app.admin.store.product_category_form.no_parent') });
}
return options;
};
// Create slug from category's name

View File

@ -1914,6 +1914,7 @@ en:
name: "Name of category"
slug: "Name of URL"
select_parent_product_category: "Choose a parent category (N1)"
no_parent: "No parent"
create:
error: "Unable to create the category: "
success: "The new category has been created."