Добавление открытия / закрытия модалки создания задачи (#78)
* Добавить открытие\закрытие модалки создания задачи #63 написал каркас функции и рендеринга, настроил открытие и закрытие модалки
This commit is contained in:
@ -97,6 +97,7 @@
|
|||||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||||
"@typescript-eslint/no-unused-vars": "warn",
|
"@typescript-eslint/no-unused-vars": "warn",
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
"@typescript-eslint/ban-types": "off",
|
||||||
"array-bracket-spacing": ["warn", "never"],
|
"array-bracket-spacing": ["warn", "never"],
|
||||||
"block-spacing": ["warn", "never"],
|
"block-spacing": ["warn", "never"],
|
||||||
"brace-style": ["warn", "1tbs", {"allowSingleLine": true}],
|
"brace-style": ["warn", "1tbs", {"allowSingleLine": true}],
|
||||||
|
|||||||
@ -10,19 +10,19 @@ import {NavLink} from 'react-router-dom';
|
|||||||
import {ROUTES} from '_consts/common';
|
import {ROUTES} from '_consts/common';
|
||||||
import ToggleMenu from '../toggle-menu';
|
import ToggleMenu from '../toggle-menu';
|
||||||
import {BOTH_MENU_LINKS} from '../../consts';
|
import {BOTH_MENU_LINKS} from '../../consts';
|
||||||
import PopupList from '../popup-list/PopupList';
|
import PopupList from '../popup-list';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) =>
|
const useStyles = makeStyles((theme: Theme) =>
|
||||||
createStyles({
|
createStyles({
|
||||||
iconRight: {
|
iconRight: {
|
||||||
marginRight: theme.spacing(2),
|
marginRight: theme.spacing(2)
|
||||||
},
|
},
|
||||||
appBar: {
|
appBar: {
|
||||||
top: 'auto',
|
top: 'auto',
|
||||||
bottom: 0,
|
bottom: 0
|
||||||
},
|
},
|
||||||
grow: {
|
grow: {
|
||||||
flexGrow: 1,
|
flexGrow: 1
|
||||||
},
|
},
|
||||||
fabButton: {
|
fabButton: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
@ -30,9 +30,9 @@ const useStyles = makeStyles((theme: Theme) =>
|
|||||||
top: -30,
|
top: -30,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
margin: '0 auto',
|
margin: '0 auto'
|
||||||
},
|
}
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -44,52 +44,31 @@ const BothMenu: React.FC<Props> = ({trigger}) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Slide appear={false} direction="up" in={!trigger}>
|
<Slide appear={false} direction="up" in={!trigger}>
|
||||||
<AppBar
|
<AppBar position="fixed" color="primary" className={classes.appBar}>
|
||||||
position="fixed"
|
|
||||||
color="primary"
|
|
||||||
className={classes.appBar}
|
|
||||||
>
|
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<IconButton
|
<IconButton className={classes.iconRight} edge="start" color="inherit">
|
||||||
className={classes.iconRight}
|
|
||||||
edge="start"
|
|
||||||
color="inherit"
|
|
||||||
>
|
|
||||||
<NavLink to={ROUTES.CHAOS_BOX}>
|
<NavLink to={ROUTES.CHAOS_BOX}>
|
||||||
<MoveToInboxIcon />
|
<MoveToInboxIcon />
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton edge="end" color="inherit">
|
||||||
edge="end"
|
|
||||||
color="inherit"
|
|
||||||
>
|
|
||||||
<NavLink to={ROUTES.PROJECTS}>
|
<NavLink to={ROUTES.PROJECTS}>
|
||||||
<ListAltIcon />
|
<ListAltIcon />
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<PopupList>
|
<PopupList>
|
||||||
<Fab
|
<Fab color="secondary" className={classes.fabButton}>
|
||||||
color="secondary"
|
|
||||||
className={classes.fabButton}
|
|
||||||
>
|
|
||||||
<AddIcon />
|
<AddIcon />
|
||||||
</Fab>
|
</Fab>
|
||||||
</PopupList>
|
</PopupList>
|
||||||
<div className={classes.grow} />
|
<div className={classes.grow} />
|
||||||
<IconButton
|
<IconButton className={classes.iconRight} edge="start" color="inherit">
|
||||||
className={classes.iconRight}
|
|
||||||
edge="start"
|
|
||||||
color="inherit"
|
|
||||||
>
|
|
||||||
<NavLink to={ROUTES.CALENDAR}>
|
<NavLink to={ROUTES.CALENDAR}>
|
||||||
<CalendarTodayIcon />
|
<CalendarTodayIcon />
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<ToggleMenu items={BOTH_MENU_LINKS}>
|
<ToggleMenu items={BOTH_MENU_LINKS}>
|
||||||
<IconButton
|
<IconButton edge="end" color="inherit">
|
||||||
edge="end"
|
|
||||||
color="inherit"
|
|
||||||
>
|
|
||||||
<MoreIcon />
|
<MoreIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</ToggleMenu>
|
</ToggleMenu>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import React, {FC, memo} from 'react';
|
import React, {FC, memo, useCallback} from 'react';
|
||||||
|
import {useHistory} from 'react-router-dom';
|
||||||
import {format} from 'date-fns';
|
import {format} from 'date-fns';
|
||||||
import {useFormik} from 'formik';
|
import {useFormik} from 'formik';
|
||||||
import Dialog from '@material-ui/core/Dialog';
|
import Dialog from '@material-ui/core/Dialog';
|
||||||
@ -7,6 +8,8 @@ import DialogContent from '@material-ui/core/DialogContent';
|
|||||||
import DialogTitle from '@material-ui/core/DialogTitle';
|
import DialogTitle from '@material-ui/core/DialogTitle';
|
||||||
import {Task} from '_types/common';
|
import {Task} from '_types/common';
|
||||||
import {VIEW_DATE_TIME} from '_consts/common';
|
import {VIEW_DATE_TIME} from '_consts/common';
|
||||||
|
import {buildPath} from '_utils/buildPath';
|
||||||
|
import {PageType} from '_enums/common';
|
||||||
import {Button, TextField} from '@material-ui/core';
|
import {Button, TextField} from '@material-ui/core';
|
||||||
import {LABELS} from '../../consts';
|
import {LABELS} from '../../consts';
|
||||||
|
|
||||||
@ -17,18 +20,23 @@ type Props = {
|
|||||||
const now = format(new Date(), VIEW_DATE_TIME);
|
const now = format(new Date(), VIEW_DATE_TIME);
|
||||||
|
|
||||||
const CreateTaskModal: FC<Props> = ({isOpen}) => {
|
const CreateTaskModal: FC<Props> = ({isOpen}) => {
|
||||||
|
const history = useHistory();
|
||||||
const form = useFormik<Partial<Task>>({
|
const form = useFormik<Partial<Task>>({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
title: '',
|
title: '',
|
||||||
body: '',
|
body: '',
|
||||||
start_at: now,
|
start_at: now,
|
||||||
end_at: '',
|
end_at: ''
|
||||||
},
|
},
|
||||||
onSubmit: () => {
|
onSubmit: () => {
|
||||||
// В аргументах приходят values. Ждем задачи со сторами для формы
|
// В аргументах приходят values. Ждем задачи со сторами для формы
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleClose = useCallback(() => {
|
||||||
|
history.push(buildPath({pageType: PageType.Main}));
|
||||||
|
}, [history]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpen}>
|
<Dialog open={isOpen}>
|
||||||
<form onSubmit={form.handleSubmit}>
|
<form onSubmit={form.handleSubmit}>
|
||||||
@ -61,7 +69,7 @@ const CreateTaskModal: FC<Props> = ({isOpen}) => {
|
|||||||
onChange={form.handleChange}
|
onChange={form.handleChange}
|
||||||
margin="dense"
|
margin="dense"
|
||||||
InputLabelProps={{
|
InputLabelProps={{
|
||||||
shrink: true,
|
shrink: true
|
||||||
}}
|
}}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
@ -73,13 +81,13 @@ const CreateTaskModal: FC<Props> = ({isOpen}) => {
|
|||||||
onChange={form.handleChange}
|
onChange={form.handleChange}
|
||||||
margin="dense"
|
margin="dense"
|
||||||
InputLabelProps={{
|
InputLabelProps={{
|
||||||
shrink: true,
|
shrink: true
|
||||||
}}
|
}}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button color="primary" type="button">
|
<Button onClick={handleClose} color="primary" type="button">
|
||||||
{LABELS.CANCEL}
|
{LABELS.CANCEL}
|
||||||
</Button>
|
</Button>
|
||||||
<Button color="primary" type="submit">
|
<Button color="primary" type="submit">
|
||||||
|
|||||||
@ -23,9 +23,9 @@ const useStyles = makeStyles(() =>
|
|||||||
container: {
|
container: {
|
||||||
height: '100hv',
|
height: '100hv',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column'
|
||||||
},
|
}
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const Page: React.FC = () => {
|
const Page: React.FC = () => {
|
||||||
|
|||||||
26
src/app/components/popup-list-item/PopupListItem.tsx
Normal file
26
src/app/components/popup-list-item/PopupListItem.tsx
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import {ListItem, ListItemText} from '@material-ui/core';
|
||||||
|
import React, {memo, useCallback} from 'react';
|
||||||
|
import {useHistory} from 'react-router-dom';
|
||||||
|
|
||||||
|
type PopupListItemProps = {
|
||||||
|
item: string;
|
||||||
|
url: string;
|
||||||
|
setOpen: (isOpen: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const PopupListItem: React.FC<PopupListItemProps> = ({item, url, setOpen}) => {
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
const handleClick = useCallback(() => {
|
||||||
|
setOpen(false);
|
||||||
|
history.push(url);
|
||||||
|
}, [history, setOpen, url]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ListItem button onClick={handleClick}>
|
||||||
|
<ListItemText primary={item} />
|
||||||
|
</ListItem>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default memo(PopupListItem);
|
||||||
1
src/app/components/popup-list-item/index.ts
Normal file
1
src/app/components/popup-list-item/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export {default} from './PopupListItem';
|
||||||
@ -1,10 +1,9 @@
|
|||||||
import {Dialog, List, ListItem, ListItemText} from '@material-ui/core';
|
import {Dialog, List} from '@material-ui/core';
|
||||||
import React, {Fragment, memo, PropsWithChildren, useCallback} from 'react';
|
import React, {Fragment, memo, PropsWithChildren, useCallback} from 'react';
|
||||||
import {v4} from 'uuid';
|
|
||||||
import {MENU_ADDS} from '../../consts';
|
import {MENU_ADDS} from '../../consts';
|
||||||
|
import PopupListItem from '../popup-list-item';
|
||||||
|
|
||||||
type Props = PropsWithChildren<{
|
type Props = PropsWithChildren<{}>;
|
||||||
}>;
|
|
||||||
|
|
||||||
const PopupList: React.FC<Props> = ({children}) => {
|
const PopupList: React.FC<Props> = ({children}) => {
|
||||||
const [open, setOpen] = React.useState(false);
|
const [open, setOpen] = React.useState(false);
|
||||||
@ -22,15 +21,11 @@ const PopupList: React.FC<Props> = ({children}) => {
|
|||||||
<Dialog onClose={handleClose} aria-labelledby="simple-dialog-title" open={open}>
|
<Dialog onClose={handleClose} aria-labelledby="simple-dialog-title" open={open}>
|
||||||
<List>
|
<List>
|
||||||
{MENU_ADDS.map(item => (
|
{MENU_ADDS.map(item => (
|
||||||
<ListItem button onClick={handleClose} key={v4()}>
|
<PopupListItem item={item.text} url={item.url} setOpen={setOpen} key={item.id} />
|
||||||
<ListItemText primary={item} />
|
|
||||||
</ListItem>
|
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
<div onClick={handleClickOpen}>
|
<div onClick={handleClickOpen}>{children}</div>
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
export {default} from './PopupList';
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
|
import {v4} from 'uuid';
|
||||||
import {ROUTES} from '_consts/common';
|
import {ROUTES} from '_consts/common';
|
||||||
|
import {PageType} from '../core/enums/common';
|
||||||
|
import {buildPath} from '../core/utils/buildPath';
|
||||||
|
import {AddMenu, ModalType} from './enums';
|
||||||
|
|
||||||
export const LABELS = {
|
export const LABELS = {
|
||||||
SEACRH: 'Поиск',
|
SEACRH: 'Поиск',
|
||||||
@ -11,7 +15,7 @@ export const LABELS = {
|
|||||||
TITLE: 'Заголовок',
|
TITLE: 'Заголовок',
|
||||||
DESCRIPTION: 'Описание',
|
DESCRIPTION: 'Описание',
|
||||||
START_AT: 'Начало',
|
START_AT: 'Начало',
|
||||||
END_AT: 'Окончание',
|
END_AT: 'Окончание'
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const BOTH_MENU_LINKS = [
|
export const BOTH_MENU_LINKS = [
|
||||||
@ -29,4 +33,23 @@ export const BOTH_MENU_LINKS = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
export const MENU_ADDS = [LABELS.ADD_TASK, LABELS.ADD_FOLDER, LABELS.ADD_TAG];
|
export const MENU_ADDS = [
|
||||||
|
{
|
||||||
|
id: v4(),
|
||||||
|
text: LABELS.ADD_TASK,
|
||||||
|
type: AddMenu.AddTask,
|
||||||
|
url: buildPath({pageType: PageType.Main, query: {modal: ModalType.CreateTask}})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: v4(),
|
||||||
|
text: LABELS.ADD_FOLDER,
|
||||||
|
type: AddMenu.AddFolder,
|
||||||
|
url: buildPath({pageType: PageType.Main, query: {modal: ModalType.CreateFolder}})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: v4(),
|
||||||
|
text: LABELS.ADD_TAG,
|
||||||
|
type: AddMenu.AddTag,
|
||||||
|
url: buildPath({pageType: PageType.Main, query: {modal: ModalType.CreateTag}})
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|||||||
@ -1,3 +1,11 @@
|
|||||||
export enum ModalType {
|
export enum ModalType {
|
||||||
CreateTask = 'createTask',
|
CreateTask = 'createTask',
|
||||||
|
CreateFolder = 'createFolder',
|
||||||
|
CreateTag = 'createTag'
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum AddMenu {
|
||||||
|
AddTask = 'addTask',
|
||||||
|
AddFolder = 'addFolder',
|
||||||
|
AddTag = 'addTag'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user