From 9bc86d5483cd124a233464505c797735adad6594 Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:34:54 +0900 Subject: [PATCH 01/29] [feat] add makefile --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..224e93f --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +build: + docker compose build + docker compose run --rm api go mod tidy + docker compose run --rm view npm install + From 29435ada542ced3a0b5a0db56d75774c26da55c6 Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:35:09 +0900 Subject: [PATCH 02/29] [feat] add go lib --- api/go.mod | 2 ++ api/go.sum | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/api/go.mod b/api/go.mod index 1cf68ea..c3077a6 100644 --- a/api/go.mod +++ b/api/go.mod @@ -10,6 +10,7 @@ require ( require ( github.com/go-sql-driver/mysql v1.7.0 // indirect + github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/labstack/gommon v0.4.0 // indirect @@ -21,4 +22,5 @@ require ( golang.org/x/net v0.4.0 // indirect golang.org/x/sys v0.3.0 // indirect golang.org/x/text v0.5.0 // indirect + golang.org/x/time v0.2.0 // indirect ) diff --git a/api/go.sum b/api/go.sum index 4157bfa..1a14143 100644 --- a/api/go.sum +++ b/api/go.sum @@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= +github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= @@ -40,6 +42,8 @@ golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/time v0.2.0 h1:52I/1L54xyEQAYdtcSuxtiT84KGYTBGXwayxmIpNJhE= +golang.org/x/time v0.2.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 949c6b2ff9379137b0ccaa54236459648b3b4b44 Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:35:38 +0900 Subject: [PATCH 03/29] =?UTF-8?q?[fix]=20method=E5=86=85=E5=AE=B9=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3,=20cors=E8=A8=AD=E5=AE=9A=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/main.go | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/api/main.go b/api/main.go index fc88a2e..d659371 100644 --- a/api/main.go +++ b/api/main.go @@ -7,6 +7,7 @@ import ( "time" "github.com/labstack/echo/v4" + "github.com/labstack/echo/v4/middleware" "gorm.io/driver/mysql" "gorm.io/gorm" ) @@ -37,35 +38,23 @@ func getTask(c echo.Context) error { } func createTask(c echo.Context) error { - taskName := c.QueryParam("task_name") - content := c.QueryParam("content") - status := c.QueryParam("status") - userName := c.QueryParam("user_name") - task := Task{ - TaskName: taskName, - Content: content, - Status: status, - UserName: userName, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), + task := new(Task) + if err := c.Bind(task); err != nil { + return err } + task.CreatedAt = time.Now() + task.UpdatedAt = time.Now() DB.Create(&task) return c.JSON(http.StatusOK, task) } func updateTask(c echo.Context) error { id := c.Param("id") - taskName := c.QueryParam("task_name") - content := c.QueryParam("content") - status := c.QueryParam("status") - userName := c.QueryParam("user_name") - task := Task{ - TaskName: taskName, - Content: content, - Status: status, - UserName: userName, - UpdatedAt: time.Now(), + task := new(Task) + if err := c.Bind(task); err != nil { + return err } + task.UpdatedAt = time.Now() DB.Model(&task).Where("id = ?", id).Updates(task) return c.JSON(http.StatusOK, task) } @@ -127,6 +116,15 @@ func main() { // TODO: Echoインスタンスを作成する e := echo.New() + + // cors設定 + arrowOrigins := []string{"*"} + e.Use(middleware.Logger()) + e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ + AllowOrigins: arrowOrigins, + AllowMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete}, + })) + e.GET("/", func(c echo.Context) error { return c.String(http.StatusOK, "Hello, World!") }) From 7df18382f00b42c682830b4114670827c82c1af3 Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:35:46 +0900 Subject: [PATCH 04/29] [fix] add env --- view/next.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/view/next.config.js b/view/next.config.js index a843cbe..7c4e27f 100644 --- a/view/next.config.js +++ b/view/next.config.js @@ -1,6 +1,11 @@ /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, + + env: { + SSR_API_URI: 'http://api:1323', + CSR_API_URI: 'http://localhost:1323', + }, } module.exports = nextConfig From 26ae06273d143a2715af42d53245278b1629b8a9 Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:35:59 +0900 Subject: [PATCH 05/29] [feat] add react icons --- view/package-lock.json | 14 ++++++++++++++ view/package.json | 1 + 2 files changed, 15 insertions(+) diff --git a/view/package-lock.json b/view/package-lock.json index 273c029..c2036a4 100644 --- a/view/package-lock.json +++ b/view/package-lock.json @@ -18,6 +18,7 @@ "next": "13.1.6", "react": "18.2.0", "react-dom": "18.2.0", + "react-icons": "^4.8.0", "typescript": "4.9.5" }, "devDependencies": { @@ -19482,6 +19483,14 @@ "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", "dev": true }, + "node_modules/react-icons": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.8.0.tgz", + "integrity": "sha512-N6+kOLcihDiAnj5Czu637waJqSnwlMNROzVZMhfX68V/9bu9qHaMIJC4UdozWoOk57gahFCNHwVvWzm0MTzRjg==", + "peerDependencies": { + "react": "*" + } + }, "node_modules/react-inspector": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/react-inspector/-/react-inspector-5.1.1.tgz", @@ -38416,6 +38425,11 @@ } } }, + "react-icons": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.8.0.tgz", + "integrity": "sha512-N6+kOLcihDiAnj5Czu637waJqSnwlMNROzVZMhfX68V/9bu9qHaMIJC4UdozWoOk57gahFCNHwVvWzm0MTzRjg==" + }, "react-inspector": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/react-inspector/-/react-inspector-5.1.1.tgz", diff --git a/view/package.json b/view/package.json index da91b8d..cd0eb81 100644 --- a/view/package.json +++ b/view/package.json @@ -23,6 +23,7 @@ "next": "13.1.6", "react": "18.2.0", "react-dom": "18.2.0", + "react-icons": "^4.8.0", "typescript": "4.9.5" }, "devDependencies": { From c1ec4e42cd9819f6a90801f69834511a3a7962fb Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:36:14 +0900 Subject: [PATCH 06/29] [fix] change tailwind bg and primary color --- view/tailwind.config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/view/tailwind.config.js b/view/tailwind.config.js index d1d12e2..daa2963 100644 --- a/view/tailwind.config.js +++ b/view/tailwind.config.js @@ -6,9 +6,9 @@ module.exports = { content: ["./src/**/*.{js,ts,jsx,tsx}"], theme: { colors: { - primary: '#007bff', - success: '#28a745', - danger: '#dc3545', + background:'#fb923c', + primary: '#1e293b', + secondary: '#fff', black: colors.black, white: colors.white, slate: colors.slate, From f662d42132eb6babc30655bafcb166248ffd7b9a Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:36:25 +0900 Subject: [PATCH 07/29] [feat] add alias paths --- view/tsconfig.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/view/tsconfig.json b/view/tsconfig.json index 2159bf4..904ef64 100644 --- a/view/tsconfig.json +++ b/view/tsconfig.json @@ -16,7 +16,9 @@ "incremental": true, "baseUrl": ".", "paths": { - "@/*": ["./src/*"] + "@/*": ["./src/*"], + "@components/*": ["./src/components/*"], + "@type/*": ["./src/type/*"], } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], From df4616cc3cb4dbbf398dccd252ed3809f4c6a9cc Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:36:38 +0900 Subject: [PATCH 08/29] [feat] add components in common --- view/src/components/common/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/view/src/components/common/index.ts b/view/src/components/common/index.ts index 0064dee..1ce3240 100644 --- a/view/src/components/common/index.ts +++ b/view/src/components/common/index.ts @@ -1 +1,8 @@ export { Button } from "./Button"; +export { Card } from "./Card"; +export { TaskCard } from "./TaskCard"; +export { TaskListCard } from "./TaskListCard"; +export { Modal } from "./Modal"; +export { TaskAddModal } from "./TaskAddModal"; +export { TaskEditModal } from "./TaskEditModal"; +export { TaskDeleteModal } from "./TaskDeleteModal"; From bf0f67c1cedbdd09d6946b6ce7b0f6b991f4925e Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:36:58 +0900 Subject: [PATCH 09/29] =?UTF-8?q?[fix]=20Button=E3=82=92=E7=B0=A1=E6=98=93?= =?UTF-8?q?=E7=9A=84=E3=81=AA=E3=82=82=E3=81=AE=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/Button/Button.stories.tsx | 6 -- view/src/components/common/Button/Button.tsx | 61 ++----------------- .../components/common/Button/Button.type.ts | 10 ++- 3 files changed, 8 insertions(+), 69 deletions(-) diff --git a/view/src/components/common/Button/Button.stories.tsx b/view/src/components/common/Button/Button.stories.tsx index 5bfaa59..2a74f13 100644 --- a/view/src/components/common/Button/Button.stories.tsx +++ b/view/src/components/common/Button/Button.stories.tsx @@ -8,13 +8,7 @@ export default { export const Default: ComponentStoryObj = { args: { - onClick: () => { - alert("Call me?"); - }, children: "TEST ME", - size: "medium", - theme: "primary", - outlined: false, }, storyName: "Default", }; diff --git a/view/src/components/common/Button/Button.tsx b/view/src/components/common/Button/Button.tsx index 26051e0..327de32 100644 --- a/view/src/components/common/Button/Button.tsx +++ b/view/src/components/common/Button/Button.tsx @@ -1,66 +1,13 @@ -import { useMemo } from "react"; import type { ButtonProps } from "./Button.type"; -const Button = (props: ButtonProps) => { - const { - className, - theme = "primary", - size = "medium", - outlined = false, - children, - fullWidth, - ...rest - } = props; - - // outlinedがtrueの時枠線を表示する - const themeClass = useMemo(() => { - switch (theme) { - case "primary": - if (outlined) { - return "text-primary border-primary"; - } else { - return "bg-primary text-white"; - } - case "success": - if (outlined) { - return "text-success border-success"; - } else { - return "bg-success text-white"; - } - case "danger": - if (outlined) { - return "text-danger border-danger"; - } else { - return "bg-danger text-white"; - } - } - }, [theme, outlined]); - - const sizeClass = useMemo(() => { - switch (size) { - case "small": - return "px-2 py-1 text-sm"; - case "medium": - return "px-4 py-2 text-base"; - case "large": - return "px-6 py-3 text-lg"; - } - }, [size]); - +const Button: React.FC = (props) => { return ( ); }; diff --git a/view/src/components/common/Button/Button.type.ts b/view/src/components/common/Button/Button.type.ts index bb99f88..0e23d92 100644 --- a/view/src/components/common/Button/Button.type.ts +++ b/view/src/components/common/Button/Button.type.ts @@ -1,6 +1,4 @@ -export type ButtonProps = { - theme?: "primary" | "danger" | "success"; - size?: "large" | "medium" | "small"; - outlined?: boolean; - fullWidth?: boolean; -} & JSX.IntrinsicElements["button"]; +export interface ButtonProps { + children: React.ReactNode; + onClick?: () => void; +} From 6f7d7811a0d81534d766702f747b5474505b02f8 Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:37:11 +0900 Subject: [PATCH 10/29] [feat] add Card --- view/src/components/common/Card/Card.tsx | 13 +++++++++++++ view/src/components/common/Card/Card.types.ts | 4 ++++ view/src/components/common/Card/index.ts | 1 + 3 files changed, 18 insertions(+) create mode 100644 view/src/components/common/Card/Card.tsx create mode 100644 view/src/components/common/Card/Card.types.ts create mode 100644 view/src/components/common/Card/index.ts diff --git a/view/src/components/common/Card/Card.tsx b/view/src/components/common/Card/Card.tsx new file mode 100644 index 0000000..90b1771 --- /dev/null +++ b/view/src/components/common/Card/Card.tsx @@ -0,0 +1,13 @@ +import { CardProps } from "./Card.types"; + +export const Card: React.FC = (props) => { + const { children, className } = props; + + return ( +
+ {children} +
+ ); +}; + +export default Card; diff --git a/view/src/components/common/Card/Card.types.ts b/view/src/components/common/Card/Card.types.ts new file mode 100644 index 0000000..43f4ee2 --- /dev/null +++ b/view/src/components/common/Card/Card.types.ts @@ -0,0 +1,4 @@ +export interface CardProps { + children: React.ReactNode; + className?: string; +} diff --git a/view/src/components/common/Card/index.ts b/view/src/components/common/Card/index.ts new file mode 100644 index 0000000..fc91b3d --- /dev/null +++ b/view/src/components/common/Card/index.ts @@ -0,0 +1 @@ +export { default as Card } from "./Card"; From 9afe52f289eaa9a480b9bd50c142b798a8a5f61d Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:37:20 +0900 Subject: [PATCH 11/29] [feat] add Modal --- view/src/components/common/Modal/Modal.tsx | 23 +++++++++++++++++++ .../components/common/Modal/Modal.types.ts | 4 ++++ view/src/components/common/Modal/index.ts | 1 + 3 files changed, 28 insertions(+) create mode 100644 view/src/components/common/Modal/Modal.tsx create mode 100644 view/src/components/common/Modal/Modal.types.ts create mode 100644 view/src/components/common/Modal/index.ts diff --git a/view/src/components/common/Modal/Modal.tsx b/view/src/components/common/Modal/Modal.tsx new file mode 100644 index 0000000..403ba5a --- /dev/null +++ b/view/src/components/common/Modal/Modal.tsx @@ -0,0 +1,23 @@ +import { ModalProps } from "./Modal.types"; +import { AiOutlineCloseCircle } from "react-icons/ai"; + +export const Modal: React.FC = (props) => { + const { children, onClose } = props; + + return ( +
+
+
+
+ +
+
{children}
+
+
+
+ ); +}; + +export default Modal; diff --git a/view/src/components/common/Modal/Modal.types.ts b/view/src/components/common/Modal/Modal.types.ts new file mode 100644 index 0000000..a691617 --- /dev/null +++ b/view/src/components/common/Modal/Modal.types.ts @@ -0,0 +1,4 @@ +export interface ModalProps { + children: React.ReactNode; + onClose: () => void; +} diff --git a/view/src/components/common/Modal/index.ts b/view/src/components/common/Modal/index.ts new file mode 100644 index 0000000..38a0f44 --- /dev/null +++ b/view/src/components/common/Modal/index.ts @@ -0,0 +1 @@ +export { default as Modal } from "./Modal"; From 72de6d6fc505fddbdf5e4b5fbd66293b81dc967c Mon Sep 17 00:00:00 2001 From: imaimai17468 Date: Thu, 30 Mar 2023 00:37:34 +0900 Subject: [PATCH 12/29] [feat] add task add modal --- .../common/TaskAddModal/TaskAddModal.tsx | 90 +++++++++++++++++++ .../common/TaskAddModal/TaskAddModal.types.ts | 8 ++ .../components/common/TaskAddModal/index.ts | 1 + 3 files changed, 99 insertions(+) create mode 100644 view/src/components/common/TaskAddModal/TaskAddModal.tsx create mode 100644 view/src/components/common/TaskAddModal/TaskAddModal.types.ts create mode 100644 view/src/components/common/TaskAddModal/index.ts diff --git a/view/src/components/common/TaskAddModal/TaskAddModal.tsx b/view/src/components/common/TaskAddModal/TaskAddModal.tsx new file mode 100644 index 0000000..2a4144f --- /dev/null +++ b/view/src/components/common/TaskAddModal/TaskAddModal.tsx @@ -0,0 +1,90 @@ +import { useState } from "react"; +import { Modal, Button } from "@components/common"; +import { TaskAddModalProps, SubmitTaskData } from "./TaskAddModal.types"; +import { useRouter } from "next/router"; + +export const TaskAddModal: React.FC = (props) => { + const router = useRouter(); + + const [formData, setFormData] = useState({ + task_name: "", + content: "", + user_name: "", + }); + + const handleFormDataChange = ( + e: + | React.ChangeEvent + | React.ChangeEvent + ) => { + setFormData({ + ...formData, + [e.target.name]: e.target.value, + }); + }; + + const submit = (data: SubmitTaskData) => { + const url = process.env.CSR_API_URI + "/tasks"; + + const submitData = { + task_name: data.task_name, + content: data.content, + user_name: data.user_name, + status: props.status, + } + + fetch(url, { + method: "POST", + mode: "cors", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(submitData), + }); + + props.onClose(); + router.reload(); + }; + + return ( + +

Add Task

+
+
+

Task Name

+ +
+
+

User Name

+ +
+
+

Content

+