diff --git a/src/components/Boards/Boards.stories.tsx b/src/components/Boards/Boards.stories.tsx
index c04cda2..6bb74a6 100644
--- a/src/components/Boards/Boards.stories.tsx
+++ b/src/components/Boards/Boards.stories.tsx
@@ -27,5 +27,6 @@ export const Default = () => (
},
]}
onAddBoard={noop}
+ onUpdateBoard={noop}
/>
);
diff --git a/src/components/Boards/Boards.tsx b/src/components/Boards/Boards.tsx
index 0f6ce70..3df0b98 100644
--- a/src/components/Boards/Boards.tsx
+++ b/src/components/Boards/Boards.tsx
@@ -15,6 +15,7 @@ interface Props {
name: string;
}[];
onAddBoard: () => void;
+ onUpdateBoard: (args: { id: string; value: string }) => void;
}
export default function(props: Props) {
@@ -37,6 +38,7 @@ export default function(props: Props) {
id={board.id}
name={board.name}
link={`boards/${board.id}`}
+ onSubmit={props.onUpdateBoard}
/>
))}
diff --git a/src/components/Boards/BoardsContainer.tsx b/src/components/Boards/BoardsContainer.tsx
index 036e20e..c38b62d 100644
--- a/src/components/Boards/BoardsContainer.tsx
+++ b/src/components/Boards/BoardsContainer.tsx
@@ -1,15 +1,18 @@
import React from 'react';
+import { useHistory } from 'react-router-dom';
+
import Boards from './Boards';
import useGroups from '../../lib/hooks/useGroups';
import useUpdateGroups from '../../lib/hooks/useUpdateGroups';
import { GroupType } from '../../lib/types';
export default function BoardsContainer() {
+ const history = useHistory();
const { data, loading, error } = useGroups();
const updateBoard = useUpdateGroups();
- function onAddBoard() {
- updateBoard({
+ async function onAddBoard() {
+ const result = await updateBoard({
type: GroupType.Board,
name: `Board - ${new Date().toLocaleDateString('en-US', {
year: 'numeric',
@@ -19,6 +22,16 @@ export default function BoardsContainer() {
minute: 'numeric',
})}`,
});
+
+ history.push(`boards/${result.id}`);
+ }
+
+ function onUpdateBoard({ id, value }: { id: string; value: string }) {
+ updateBoard({
+ id,
+ type: GroupType.Board,
+ name: value,
+ });
}
if (loading) {
@@ -29,5 +42,11 @@ export default function BoardsContainer() {
return
Error Loading Boards
;
}
- return ;
+ return (
+
+ );
}
diff --git a/src/components/Tile/Tile.stories.tsx b/src/components/Tile/Tile.stories.tsx
index fb7b94b..c7e0d95 100644
--- a/src/components/Tile/Tile.stories.tsx
+++ b/src/components/Tile/Tile.stories.tsx
@@ -5,4 +5,4 @@ export default {
title: 'Tile',
};
-export const Default = () => ;
+export const Default = () => ;
diff --git a/src/components/Tile/Tile.tsx b/src/components/Tile/Tile.tsx
index 44454d2..2875b3a 100644
--- a/src/components/Tile/Tile.tsx
+++ b/src/components/Tile/Tile.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useEffect, useState } from 'react';
import CardActions from '@material-ui/core/CardActions';
import Button from '@material-ui/core/Button';
import Grid from '@material-ui/core/Grid';
@@ -7,37 +7,108 @@ import Avatar from '@material-ui/core/Avatar';
import CardActionArea from '@material-ui/core/CardActionArea';
import Card from '@material-ui/core/Card';
import * as S from './Tile.styles';
+import Input from '@material-ui/core/Input';
+import { useTheme } from '@material-ui/core/styles';
+import FormControl from '@material-ui/core/FormControl';
interface Props {
id: string;
name: string;
link?: string;
+ onSubmit?: (args: { id: string; value: string }) => void;
}
export default function Tile(props: Props) {
+ const theme = useTheme();
+ const [isEditing, setIsEditing] = useState(false);
+ const [name, setName] = useState(props.name);
+ const [nextName, setNextName] = useState(name);
+
+ useEffect(() => {
+ setName(props.name);
+ }, [props.name]);
+
+ const handleOnEditClick = () => {
+ setIsEditing(true);
+ };
+
+ const handleNameChange = (e: React.ChangeEvent) => {
+ setNextName(e.target.value);
+ };
+
+ const handleCancelClick = () => {
+ setName(name);
+ setNextName(name);
+ setIsEditing(false);
+ };
+
+ const handleConfirmClick = () => {
+ if (props.onSubmit) {
+ props.onSubmit({ id: props.id, value: nextName });
+ }
+ setName(nextName);
+ setIsEditing(false);
+ };
+
const headerNode = (
{props.name ? props.name[0].toUpperCase() : ''}}
- title={props.name}
+ title={
+ isEditing ? (
+
+
+
+ ) : (
+ name
+ )
+ }
/>
);
return (
-
- {props.link ? (
-
- {headerNode}
-
- ) : (
- headerNode
- )}
-
-
-
-
+
+
);