// import dependencies import { Tab } from '@mui/material'; import React, { useRef, useState } from 'react'; import { TabContext, TabList, TabPanel } from '@mui/lab'; import { colors, Page, Menu, MenuItem, ListItemIcon, ListItemText, Modal, Divider, Typography, InputAdornment, IconButton, Icon, View, Color, Box, TextField, Stack, Button, IconPicker, LoadingButton } from '../'; // let context let DashupContext = null; // create menu component const DashupUIPageConfig = (props = {}) => { // destruct const { type, page, dashup, setPage, getPageStruct } = props; // get struct const struct = getPageStruct(); // tabs let [tab, setTab] = useState(null); const [icon, setIcon] = useState(false); const [color, setColor] = useState(false); const [colorMenu, setColorMenu] = useState(false); const [importing, setImporting] = useState(false); const [defaulting, setDefaulting] = useState(!!(!Object.keys(props.page?.get('data')).length && props.missingRequire?.length && struct?.data?.default)); // ref const colorRef = useRef(null); // on import const onImport = async (e) => { // prevent default e.preventDefault(); e.stopPropagation(); // loading setImporting(true); // load from url const { data } = await eden.router.post(`/api/${dashup.get('_id')}/page/${page.get('_id')}/default`, { default : struct.data.default, section : dashup.get('section') ? dashup.get('section').get('_id') : null, }); // replace info props.dashup.set('pages', data.pages); // exported setImporting(false); setDefaulting(false); // hide (props.onClose || props.onHide)(); // refresh props.onRefresh(); }; // check struct if (!struct) return null; // tabs const tabs = struct.data?.tabs || ['Config', 'Connects']; // check tab if (!tab) tab = `${tabs[0]}`.toLowerCase(); // return jsx return ( <> setPage('name', e.target.value) } defaultValue={ page.get('name') } fullWidth /> setPage('description', e.target.value) } defaultValue={ page.get('description') } fullWidth multiline /> { defaulting ? ( { struct.data?.default?.title } { struct.data?.default?.pages.map((sPage) => { // return jsx return ( ), } } /> ); }) } ) : ( setTab(v.toLowerCase()) }> { tabs.map((t, i) => { // return jsx return ; }) } { tabs.map((t, i) => { // return jsx return ( { `${tab}`.toLowerCase() === 'connects' ? ( ) : (props[tab] || ( )) } ); }) } ) } { !!(props.missingRequire || []).length && struct?.data?.default && ( { defaulting ? ( ) : ( ) } { !!defaulting && ( onImport(e) } disabled={ !!importing } loading={ !!importing } variant="contained" color="primary"> { importing ? 'Importing...' : 'Use Default Pages' } ) } ) } setColorMenu(null) } anchorEl={ colorRef?.current } > !setIcon(true) && setColorMenu(false) }> Change Icon !setColor(true) && setColorMenu(false) }> Change Color { !!icon && setIcon(false) } onChange={ (icon) => setPage('icon', icon) } /> } { !!color && setColor(false) } onChange={ (hex) => setPage('color', hex.hex === 'transparent' ? null : hex) } /> } ); }; // return wrap const DashupUIPageConfigWrap = (props = {}) => { // return jsx return ( { (data) => { // return jsx return ; } } ); }; // export default page menu export default (ctx) => { // use context DashupContext = ctx; // return actual component return DashupUIPageConfigWrap; };