Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState, useEffect } from 'react';
- import history from '@history';
- import { useForm, useDeepCompareEffect } from '@fuse/hooks';
- import { makeStyles, withStyles } from '@material-ui/core/styles';
- import { useDispatch, useSelector } from 'react-redux';
- import { useParams } from 'react-router-dom';
- import Icon from '@material-ui/core/Icon';
- import TextField from '@material-ui/core/TextField';
- import EditIcon from '@material-ui/icons/Edit';
- import DeleteIcon from '@material-ui/icons/Delete';
- import FuseLoading from '@fuse/core/FuseLoading';
- import MenuItem from '@material-ui/core/MenuItem';
- import { fromObject } from 'http-cache-semantics';
- import Table from '@material-ui/core/Table';
- import TableBody from '@material-ui/core/TableBody';
- import TableCell from '@material-ui/core/TableCell';
- import TableContainer from '@material-ui/core/TableContainer';
- import TableHead from '@material-ui/core/TableHead';
- import TableRow from '@material-ui/core/TableRow';
- import * as Actions from '../../store/actions';
- // import AddNewProto from './AddNewProto';
- // import EditProto from './EditProto';
- const useStyles = makeStyles(theme => ({
- mainBlock: {
- marginRight: '32px',
- width: '50%',
- display: 'table',
- [theme.breakpoints.down('xs')]: {
- marginRight: '0',
- minWidth: '100%'
- }
- },
- cardWrapper: {
- marginBottom: '32px',
- flex: 1,
- display: 'flex',
- flexDirection: 'column',
- border: '1px solid #E0E0E0',
- borderRadius: '4px',
- backgroundColor: theme.palette.background.paper,
- [theme.breakpoints.down('xs')]: {
- marginRight: '0',
- minWidth: '100%'
- }
- },
- cardHeader: {
- height: '60px',
- padding: '18px 24px',
- display: 'flex',
- justifyContent: 'space-between',
- color: theme.palette.secondary.main,
- borderBottom: '1px solid #E0E0E0',
- [theme.breakpoints.down('xs')]: {
- height: 'fit-content',
- flexWrap: 'wrap'
- }
- },
- cardHeaderEditButton: {
- display: 'flex',
- alignItems: 'center',
- cursor: 'pointer',
- color: theme.palette.primary.main,
- [theme.breakpoints.down('xs')]: {
- marginTop: '10px'
- }
- },
- cardHeaderCancelButton: {
- marginRight: '10px',
- display: 'flex',
- alignItems: 'center',
- cursor: 'pointer',
- color: theme.palette.error.main,
- [theme.breakpoints.down('xs')]: {
- marginTop: '10px'
- }
- },
- cardHeaderAddButton: {
- display: 'flex',
- alignItems: 'center',
- cursor: 'pointer',
- color: theme.palette.primary.main
- },
- cardHeaderSaveButton: {
- display: 'flex',
- alignItems: 'center',
- cursor: 'pointer',
- color: theme.palette.success.main,
- [theme.breakpoints.down('xs')]: {
- marginTop: '10px'
- }
- },
- cardContent: {
- padding: '23px',
- display: 'flex',
- flexWrap: 'wrap',
- justifyContent: 'space-between'
- },
- cardTable: {
- padding: '0 23px 48px 23px',
- [theme.breakpoints.down('xs')]: {
- padding: '5px'
- }
- }
- }));
- const StyledTableCell = withStyles(theme => ({
- head: {
- color: theme.palette.secondary.main,
- paddingLeft: 0
- },
- body: {
- color: theme.palette.secondary.main,
- paddingLeft: 0
- }
- }))(TableCell);
- const ActionsTableCell = withStyles(theme => ({
- body: {
- color: theme.palette.secondary.main,
- width: '100px'
- }
- }))(TableCell);
- export default function Handbook(props) {
- const [isEditName, setIsEditName] = useState(false);
- const [isEditKey, setIsEditKey] = useState(false);
- const [currentForm, setCurrentForm] = useState('');
- const [stageEditIndex, setStageEditIndex] = useState('');
- const { form, handleChange, setForm, setInForm } = useForm({
- name: '',
- key: '',
- item: []
- });
- const classes = useStyles(props);
- const dispatch = useDispatch();
- const routeParams = useParams();
- const handbook = useSelector(({ settings }) => settings.handbooks.handbook);
- // const stagesList = useSelector(({ settings }) => settings.projectProto.stageProtosList);
- const isGetHandbookError = useSelector(({ settings }) => settings.handbooks.isGetHandbookError);
- const isHandbookPending = useSelector(({ settings }) => settings.handbooks.isHandbookPending);
- // const isStagePending = useSelector(({ settings }) => settings.projectProto.isStagePending);
- const isDataPending = isHandbookPending;
- useEffect(() => {
- const { key } = routeParams;
- dispatch(Actions.getHandbook(key));
- // dispatch(Actions.getStageProtos());
- }, []);
- useEffect(() => {
- setForm(handbook);
- }, [handbook]);
- useEffect(() => {
- if (isGetHandbookError) {
- history.push('/error-404');
- }
- }, [isGetHandbookError]);
- const saveData = () => {
- if (form.name !== handbook.name || form.key !== handbook.key) {
- const data = {
- name: form.name,
- key: form.key
- };
- // dispatch(Actions.updateProjectProto(proto.id, data));
- }
- setIsEditName(false);
- };
- const openAddForm = () => {
- setStageEditIndex('');
- setCurrentForm('addNew');
- };
- const openEditForm = index => {
- setStageEditIndex(index);
- setCurrentForm('edit');
- };
- // const deleteStageFromProto = index => {
- // const stageId = form.item[index].id;
- // dispatch(Actions.deleteStageOfProject(proto.id, stageId));
- // };
- return isDataPending ? (
- <FuseLoading />
- ) : (
- <div className="md:p-32 p-12 flex flex-wrap">
- <div className={classes.mainBlock}>
- <div className={classes.cardWrapper}>
- <div className={classes.cardHeader}>
- <h4>Информация о справочнике</h4>
- {!isEditName || !isEditKey ? (
- <span
- className={classes.cardHeaderEditButton}
- onClick={() => setIsEditName(true)}
- role="button"
- >
- <Icon>edit</Icon>
- Редактировать
- </span>
- ) : (
- <div className="flex justify-between">
- <span className={classes.cardHeaderSaveButton} onClick={saveData}>
- <Icon>check</Icon>
- Сохранить
- </span>
- </div>
- )}
- </div>
- <div className={classes.cardContent}>
- <TextField
- className="mb-20"
- label="Наименование справочника"
- type="text"
- name="name"
- value={form.name}
- onChange={handleChange}
- variant="outlined"
- fullWidth
- required
- disabled={!isEditName}
- />
- <TextField
- className="mb-20"
- label="Код справочника"
- type="text"
- name="key"
- value={form.key}
- onChange={handleChange}
- variant="outlined"
- fullWidth
- required
- disabled={!isEditKey}
- />
- </div>
- </div>
- <div className={classes.cardWrapper}>
- <div className={classes.cardHeader}>
- <h4>Этапы</h4>
- <span className={classes.cardHeaderAddButton} onClick={openAddForm} role="button">
- <Icon>add</Icon>
- Добавить этап
- </span>
- </div>
- <div className={classes.cardTable}>
- <TableContainer>
- <Table color="secondary" aria-label="simple table">
- <TableHead>
- <TableRow>
- <StyledTableCell>Наименование</StyledTableCell>
- <StyledTableCell>Порядок</StyledTableCell>
- <StyledTableCell>Действия</StyledTableCell>
- </TableRow>
- </TableHead>
- <TableBody>
- {form.item &&
- form.item.map((row, index) => (
- <TableRow key={row.id}>
- <StyledTableCell component="th" scope="row">
- {row.name}
- </StyledTableCell>
- <StyledTableCell>{row.order}</StyledTableCell>
- <ActionsTableCell>
- <EditIcon
- className="w-16 text-black cursor-pointer"
- onClick={() => openEditForm(index)}
- />
- <DeleteIcon
- className="md:ml-32 ml-12 text-black w-16 cursor-pointer"
- //onClick={() => deleteStageFromProto(index)}
- />
- </ActionsTableCell>
- </TableRow>
- ))}
- </TableBody>
- </Table>
- </TableContainer>
- </div>
- </div>
- </div>
- {/* {currentForm === 'addNew' && ( */}
- {/* <AddNewProto stages={stagesList} protoId={proto.id} setCurrentForm={setCurrentForm} /> */}
- {/* )} */}
- {/* {currentForm === 'edit' && ( */}
- {/* <EditProto */}
- {/* stage={form.item[stageEditIndex]} */}
- {/* protoId={proto.id} */}
- {/* setCurrentForm={setCurrentForm} */}
- {/* /> */}
- {/* )} */}
- </div>
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement