'use client' import React, { type Dispatch, type SetStateAction, memo, useEffect, useState } from 'react' import { Button, Column, Icon, Overline, Row, Text } from '../../atoms' import { NavigationButtons, Options, Pulse, ToggleSwitch } from '../../molecules' import { CustomLinkAside } from '../Aside/helpers' import { Portal } from '../Portal' import { getGlobalStyle } from '../../../utils' import packageJson from '../../../package.json' import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd' import Link from 'next/link' import clsx from 'clsx' import styles from './styles.module.css' type DashboardPath = | `/dashboard/${string}/${string}` // para /dashboard/[business]/[id] | `/dashboard/${string}` // para /dashboard/[business] | '/dashboard' interface MemoAsideProps { collapsed?: boolean isCollapsedMenu?: boolean dataStore?: any handleClick?: any handleOpenDeliveryTime?: any isMobile?: boolean loading?: boolean salesOpen?: boolean connected: boolean setCollapsed?: any setShowComponentModal?: any version: string logicalVersion: string modules?: any[] setSalesOpen?: Dispatch> onDragEnd?: (result: any) => void isElectron?: boolean handleCollapsedMenu?: () => void pathname: DashboardPath | string setIsDragDisabled?: Dispatch> } const MemoAside: React.FC = ({ isElectron = false, isMobile = false, pathname, version = '0.0.0', logicalVersion = '0.0.0', setCollapsed, salesOpen, connected = false, collapsed = false, isCollapsedMenu = false, dataStore = { storeName: '', idStore: '', uState: 1 }, modules = [], handleClick = (state: boolean) => { return state }, handleOpenDeliveryTime = () => { }, setSalesOpen = (state: boolean) => { return state }, handleCollapsedMenu = () => { return null }, setShowComponentModal = (state: boolean) => { return state }, onDragEnd = (result: any) => { return result } }) => { const [show, setShow] = useState(false) const [isDragDisabled, setIsDragDisabled] = useState(false) const [active, setActive] = useState(false) interface DataStore { storeName: string idStore: string uState: number | string } const { storeName, uState }: DataStore = dataStore ?? { storeName: '', idStore: '', uState: 1 } const handleOpenCreateProduct = (): void => { setShowComponentModal(3) handleClick(3) setShow(!show) } const modulesArray = modules?.map((module) => { return module }) useEffect(() => { function handleKeyDown(event: KeyboardEvent): void { if (event.ctrlKey && event.key === 's') { event.preventDefault() setSalesOpen((prevState: boolean) => !(prevState)) } } document.addEventListener('keydown', handleKeyDown) return () => { document.removeEventListener('keydown', handleKeyDown) } }, [salesOpen]) const handleMenu = (index: boolean | number): void => { setActive((prev: boolean | number) => { const state = index === prev ? false : index return state }) } const handleClickAction = (path: string): void => { const action: Record void> = { '?time=true': handleOpenDeliveryTime, '?goals=true': handleOpenDeliveryTime } action[path]?.() } const isDashboardRoute = (pathname: DashboardPath | string): boolean => { return pathname.startsWith('/dashboard') } const hidden = isDashboardRoute(pathname) return ( <> {isMobile && { return setCollapsed(!collapsed) }} show={collapsed} zIndex={getGlobalStyle('--z-index-99999')} /> } {/* {!isMobile && // { setShow(!show) }} // show={show} // zIndex={getGlobalStyle('--z-index-999')}get // /> } */}
{null} {isElectron && }
{!hidden && } {!hidden && }
{!isCollapsedMenu && typeof dataStore?.storeName === 'string' && dataStore.storeName.trim() !== '' && typeof dataStore?.idStore === 'string' && dataStore.idStore.trim() !== '' && {storeName} } {uState === '1' && En pausa programada } {!isCollapsedMenu && }
{(provided) => (
{modulesArray?.map((module, index) => { const subModules = module?.subModules ?? [] const existSubModules = Boolean(subModules.length > 0) const action = module?.mPath?.startsWith('?') const mPath = action === true ? '' : module?.mPath as string const isActive = `/${mPath}` === pathname return ( {(provided: { innerRef: React.LegacyRef | undefined, draggableProps: React.JSX.IntrinsicAttributes & React.ClassAttributes & React.HTMLAttributes, dragHandleProps: React.JSX.IntrinsicAttributes & React.ClassAttributes & React.HTMLAttributes }) => (
{(!existSubModules) && { handleClickAction(module.mPath as string) }} mPath={mPath} isActive={isActive} action={action} mIcon={module?.mIcon} mName={module?.mName} /> } {(existSubModules && !isCollapsedMenu) && {module.mName} }
{(existSubModules && !isCollapsedMenu) && { handleMenu(index) }} index={active} icon='IconTicket' label={module.mName} > {subModules?.map((item: any) => { return (
) })}
}
)}
) })} {provided.placeholder}
)}
setIsDragDisabled(!isDragDisabled)} successColor='green' />
version: {version} UI: {packageJson.version} logical: {logicalVersion}
) } export const Aside = memo(MemoAside)