plankanban#27 UI changes, front-end refactoring
parent
d06c0c8b06
commit
8590d4f06c
@ -1,104 +0,0 @@
|
|||||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { Button, Form, Menu } from 'semantic-ui-react';
|
|
||||||
import { withPopup } from '../../lib/popup';
|
|
||||||
import { Input, Popup, FilePicker } from '../../lib/custom-ui';
|
|
||||||
|
|
||||||
import { useForm } from '../../hooks';
|
|
||||||
|
|
||||||
import styles from './AddPopup.module.scss';
|
|
||||||
|
|
||||||
const AddStep = React.memo(({ onCreate, onImport, onClose }) => {
|
|
||||||
const [t] = useTranslation();
|
|
||||||
|
|
||||||
const [data, handleFieldChange] = useForm({
|
|
||||||
name: '',
|
|
||||||
file: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const [selectedFile, setSelectedFile] = useState(null);
|
|
||||||
|
|
||||||
const nameField = useRef(null);
|
|
||||||
|
|
||||||
const handleSubmit = useCallback(() => {
|
|
||||||
const cleanData = {
|
|
||||||
...data,
|
|
||||||
type: 'kanban',
|
|
||||||
name: data.name.trim(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!cleanData.name) {
|
|
||||||
nameField.current.select();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.file) {
|
|
||||||
onImport(cleanData);
|
|
||||||
} else {
|
|
||||||
onCreate(cleanData);
|
|
||||||
}
|
|
||||||
|
|
||||||
onClose();
|
|
||||||
}, [onClose, data, onImport, onCreate]);
|
|
||||||
|
|
||||||
const handleFileSelect = useCallback(
|
|
||||||
(file) => {
|
|
||||||
handleFieldChange(null, {
|
|
||||||
name: 'file',
|
|
||||||
value: file,
|
|
||||||
});
|
|
||||||
setSelectedFile(file);
|
|
||||||
},
|
|
||||||
[handleFieldChange, setSelectedFile],
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
nameField.current.focus();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Popup.Header>
|
|
||||||
{t('common.createBoard', {
|
|
||||||
context: 'title',
|
|
||||||
})}
|
|
||||||
</Popup.Header>
|
|
||||||
<Popup.Content>
|
|
||||||
<Form onSubmit={handleSubmit}>
|
|
||||||
<Input
|
|
||||||
fluid
|
|
||||||
ref={nameField}
|
|
||||||
name="name"
|
|
||||||
value={data.name}
|
|
||||||
className={styles.field}
|
|
||||||
onChange={handleFieldChange}
|
|
||||||
/>
|
|
||||||
<Menu secondary vertical className={styles.menu}>
|
|
||||||
<FilePicker onSelect={handleFileSelect} accept=".json">
|
|
||||||
<Menu.Item className={styles.menuItem}>
|
|
||||||
{selectedFile
|
|
||||||
? selectedFile.name
|
|
||||||
: t('common.uploadTrelloFile', {
|
|
||||||
context: 'title',
|
|
||||||
})}
|
|
||||||
</Menu.Item>
|
|
||||||
</FilePicker>
|
|
||||||
</Menu>
|
|
||||||
<Button
|
|
||||||
positive
|
|
||||||
content={selectedFile ? t('action.importTrelloBoard') : t('action.createBoard')}
|
|
||||||
/>
|
|
||||||
</Form>
|
|
||||||
</Popup.Content>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep.propTypes = {
|
|
||||||
onCreate: PropTypes.func.isRequired,
|
|
||||||
onImport: PropTypes.func.isRequired,
|
|
||||||
onClose: PropTypes.func.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default withPopup(AddStep);
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
:global(#app) {
|
|
||||||
.field {
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu {
|
|
||||||
margin: 0px 0px 4px;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,114 @@
|
|||||||
|
import React, { useCallback, useEffect, useRef } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { Button, Form, Icon } from 'semantic-ui-react';
|
||||||
|
import { useDidUpdate, useToggle } from '../../../lib/hooks';
|
||||||
|
import { withPopup } from '../../../lib/popup';
|
||||||
|
import { Input, Popup } from '../../../lib/custom-ui';
|
||||||
|
|
||||||
|
import { useForm, useSteps } from '../../../hooks';
|
||||||
|
import ImportStep from './ImportStep';
|
||||||
|
|
||||||
|
import styles from './AddPopup.module.scss';
|
||||||
|
|
||||||
|
const StepTypes = {
|
||||||
|
IMPORT: 'IMPORT',
|
||||||
|
};
|
||||||
|
|
||||||
|
const AddStep = React.memo(({ onCreate, onClose }) => {
|
||||||
|
const [t] = useTranslation();
|
||||||
|
|
||||||
|
const [data, handleFieldChange, setData] = useForm({
|
||||||
|
name: '',
|
||||||
|
import: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [step, openStep, handleBack] = useSteps();
|
||||||
|
const [focusNameFieldState, focusNameField] = useToggle();
|
||||||
|
|
||||||
|
const nameField = useRef(null);
|
||||||
|
|
||||||
|
const handleImportSelect = useCallback(
|
||||||
|
(nextImport) => {
|
||||||
|
setData((prevData) => ({
|
||||||
|
...prevData,
|
||||||
|
import: nextImport,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
[setData],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleImportBack = useCallback(() => {
|
||||||
|
handleBack();
|
||||||
|
focusNameField();
|
||||||
|
}, [handleBack, focusNameField]);
|
||||||
|
|
||||||
|
const handleSubmit = useCallback(() => {
|
||||||
|
const cleanData = {
|
||||||
|
...data,
|
||||||
|
type: 'kanban',
|
||||||
|
name: data.name.trim(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!cleanData.name) {
|
||||||
|
nameField.current.select();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
onCreate(cleanData);
|
||||||
|
onClose();
|
||||||
|
}, [onClose, data, onCreate]);
|
||||||
|
|
||||||
|
const handleImportClick = useCallback(() => {
|
||||||
|
openStep(StepTypes.IMPORT);
|
||||||
|
}, [openStep]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
nameField.current.focus();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useDidUpdate(() => {
|
||||||
|
nameField.current.focus();
|
||||||
|
}, [focusNameFieldState]);
|
||||||
|
|
||||||
|
if (step && step.type === StepTypes.IMPORT) {
|
||||||
|
return <ImportStep onSelect={handleImportSelect} onBack={handleImportBack} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Popup.Header>
|
||||||
|
{t('common.createBoard', {
|
||||||
|
context: 'title',
|
||||||
|
})}
|
||||||
|
</Popup.Header>
|
||||||
|
<Popup.Content>
|
||||||
|
<Form onSubmit={handleSubmit}>
|
||||||
|
<Input
|
||||||
|
fluid
|
||||||
|
ref={nameField}
|
||||||
|
name="name"
|
||||||
|
value={data.name}
|
||||||
|
className={styles.field}
|
||||||
|
onChange={handleFieldChange}
|
||||||
|
/>
|
||||||
|
<Button positive content={t('action.createBoard')} />
|
||||||
|
<Button type="button" className={styles.importButton} onClick={handleImportClick}>
|
||||||
|
<Icon
|
||||||
|
name={data.import ? data.import.type : 'arrow down'}
|
||||||
|
className={styles.importButtonIcon}
|
||||||
|
/>
|
||||||
|
{data.import ? data.import.file.name : t('action.import')}
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
</Popup.Content>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep.propTypes = {
|
||||||
|
onCreate: PropTypes.func.isRequired,
|
||||||
|
onClose: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default withPopup(AddStep);
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
:global(#app) {
|
||||||
|
.field {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.importButton {
|
||||||
|
background: transparent;
|
||||||
|
box-shadow: none;
|
||||||
|
color: #6b808c;
|
||||||
|
float: right;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-right: 0;
|
||||||
|
max-width: 49%;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: left;
|
||||||
|
text-decoration: underline;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
transition: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(9, 30, 66, 0.08);
|
||||||
|
color: #092d42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.importButtonIcon {
|
||||||
|
font-size: 13px;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
import React, { useCallback } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { Button } from 'semantic-ui-react';
|
||||||
|
import { FilePicker, Popup } from '../../../lib/custom-ui';
|
||||||
|
|
||||||
|
import styles from './ImportStep.module.scss';
|
||||||
|
|
||||||
|
const ImportStep = React.memo(({ onSelect, onBack }) => {
|
||||||
|
const [t] = useTranslation();
|
||||||
|
|
||||||
|
const handleFileSelect = useCallback(
|
||||||
|
(type, file) => {
|
||||||
|
onSelect({
|
||||||
|
type,
|
||||||
|
file,
|
||||||
|
});
|
||||||
|
|
||||||
|
onBack();
|
||||||
|
},
|
||||||
|
[onSelect, onBack],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Popup.Header onBack={onBack}>
|
||||||
|
{t('common.importBoard', {
|
||||||
|
context: 'title',
|
||||||
|
})}
|
||||||
|
</Popup.Header>
|
||||||
|
<Popup.Content>
|
||||||
|
<FilePicker onSelect={(file) => handleFileSelect('trello', file)} accept=".json">
|
||||||
|
<Button
|
||||||
|
fluid
|
||||||
|
type="button"
|
||||||
|
icon="trello"
|
||||||
|
content={t('common.fromTrello')}
|
||||||
|
className={styles.button}
|
||||||
|
/>
|
||||||
|
</FilePicker>
|
||||||
|
</Popup.Content>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
ImportStep.propTypes = {
|
||||||
|
onSelect: PropTypes.func.isRequired,
|
||||||
|
onBack: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ImportStep;
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
:global(#app) {
|
||||||
|
.button {
|
||||||
|
background: transparent;
|
||||||
|
box-shadow: none;
|
||||||
|
color: #6b808c;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-top: 8px;
|
||||||
|
padding: 6px 11px;
|
||||||
|
text-align: left;
|
||||||
|
transition: none;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(9, 30, 66, 0.08);
|
||||||
|
color: #092d42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
import AddPopup from './AddPopup';
|
||||||
|
|
||||||
|
export default AddPopup;
|
||||||
Loading…
Reference in New Issue