Skip to content

Commit

Permalink
remove unnessesary code
Browse files Browse the repository at this point in the history
  • Loading branch information
BohdanMylyi committed Jul 24, 2024
1 parent 1e47e67 commit 8135c28
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
21 changes: 3 additions & 18 deletions src/components/app-button-menu/AppButtonMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ interface AppButtonMenuProps<T> extends Omit<MenuProps, 'open'> {
valueField?: keyof T
showNoneProperty?: boolean
customSx?: { root?: SxProps }
disabled?: boolean
}

const AppButtonMenu = <T extends Pick<CategoryNameInterface, '_id'>>({
Expand All @@ -52,24 +51,13 @@ const AppButtonMenu = <T extends Pick<CategoryNameInterface, '_id'>>({
const { t } = useTranslation()
const [inputValue, setInputValue] = useState<string>('')
const [selectedNames, setSelectedNames] = useState<string[]>([])
const [, setIsNoneSelectedNames] = useState<boolean>(false)
const { anchorEl, openMenu, renderMenu } = useMenu()

const onMenuItemClick = (item: string, id: string) => {
if (item === 'No category') {
if (selectedNames.includes(item)) {
setIsNoneSelectedNames(false)
setSelectedItems([])
} else {
setIsNoneSelectedNames(true)
setSelectedItems([id])
}
if (selectedNames.includes(item)) {
setSelectedItems(selectedItems.filter((selected) => selected !== id))
} else {
if (selectedNames.includes(item)) {
setSelectedItems(selectedItems.filter((selected) => selected !== id))
} else {
setSelectedItems([...selectedItems, id])
}
setSelectedItems([...selectedItems, id])
}
}

Expand Down Expand Up @@ -99,12 +87,9 @@ const AppButtonMenu = <T extends Pick<CategoryNameInterface, '_id'>>({
const menuItems = filteredItems.map((item) => {
const field = String(valueField ? (item as T)[valueField] : item)
const id = item._id
const isDisabled =
selectedNames.includes('No category') && field !== 'No category'
return (
<AppSelectButton
checked={selectedNames.includes(field)}
disabled={isDisabled}
key={item._id}
onMenuItemClick={() => onMenuItemClick(field, id)}
>
Expand Down
8 changes: 3 additions & 5 deletions src/components/app-select-button/AppSelectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ import { styles } from '~/components/app-select-button/AppSelectButton.styles'
interface AppSelectButtonProps {
onMenuItemClick: () => void
checked: boolean
disabled?: boolean
children: ReactNode
}

const AppSelectButton: FC<AppSelectButtonProps> = ({
checked,
children,
onMenuItemClick,
disabled = false
onMenuItemClick
}) => {
return (
<MenuItem disabled={disabled} onClick={onMenuItemClick} sx={styles.text}>
<Checkbox checked={checked} disabled={disabled} />
<MenuItem onClick={onMenuItemClick} sx={styles.text}>
<Checkbox checked={checked} />
{children}
</MenuItem>
)
Expand Down

0 comments on commit 8135c28

Please sign in to comment.