From fbee07dd93623fa1bb53825ccf0c34aad2e74ca5 Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Fri, 22 Dec 2023 18:32:53 +0000 Subject: [PATCH] refactor: enhance ninjas page --- apps/app/components/Ninja/index.js | 41 +++++- apps/app/components/NinjaForm/index.js | 181 +++++++++++++------------ apps/app/pages/ninjas/index.tsx | 46 ++++++- 3 files changed, 167 insertions(+), 101 deletions(-) diff --git a/apps/app/components/Ninja/index.js b/apps/app/components/Ninja/index.js index 48806c9e..140aab8c 100644 --- a/apps/app/components/Ninja/index.js +++ b/apps/app/components/Ninja/index.js @@ -1,29 +1,58 @@ -import { Avatar, Card } from "antd"; +import React, { useState } from "react"; +import { Avatar, Button, Card, Popconfirm, Space } from "antd"; import { EditOutlined } from "@ant-design/icons"; import Belt from "~/components/Belt"; import Link from "next/link"; +import NinjaForm from "~/components/NinjaForm"; const { Meta } = Card; function Ninja(ninja) { + const [showNinjaForm, setShowNinjaForm] = useState(false); + const [showPopconfirm, setShowPopconfirm] = useState(false); + + const handleButtonClick = () => { + setShowNinjaForm(false); + setShowPopconfirm(true); + }; + + const handleConfirm = () => { + setShowNinjaForm(true); + setShowPopconfirm(false); + }; + + const handleCancel = () => { + setShowPopconfirm(false); + }; + return ( - - - - , + + - - - - - + + + + + + + + + + + + + + + ); } diff --git a/apps/app/pages/ninjas/index.tsx b/apps/app/pages/ninjas/index.tsx index 53371f30..5425e459 100644 --- a/apps/app/pages/ninjas/index.tsx +++ b/apps/app/pages/ninjas/index.tsx @@ -1,39 +1,73 @@ import { useEffect, useState } from "react"; import Link from "next/link"; -import { Button, Col, Row, Typography } from "antd"; -import { PlusOutlined } from "@ant-design/icons"; +import { Button, Col, Popconfirm, Row, Typography } from "antd"; +import { PlusCircleFilled, PlusOutlined } from "@ant-design/icons"; import { withAuth } from "~/components/Auth"; import AppLayout from "~/layouts/AppLayout"; import * as api from "bokkenjs"; +import NinjaForm from "~/components/NinjaForm"; import Ninja from "~/components/Ninja"; import { notifyError } from "~/components/Notification"; +import { set } from "lodash-es"; const { Title } = Typography; function Ninjas() { const [ninjas, setNinjas] = useState([]); + const [showNinjaForm, setShowNinjaForm] = useState(false); + const [showPopconfirm, setShowPopconfirm] = useState(false); - useEffect(() => { + const fetchNinjas = () => { api .getNinjas() .then((response: any) => setNinjas(response.data)) .catch((error) => { notifyError("Ocorreu um erro", "Não foi possível obter os seus ninjas"); }); + }; + + useEffect(() => { + fetchNinjas(); }, []); + const handleButtonClick = () => { + setShowNinjaForm(false); + setShowPopconfirm(true); + }; + + const handleConfirm = () => { + setShowNinjaForm(true); + setShowPopconfirm(false); + }; + + const handleCancel = () => { + setShowPopconfirm(false); + }; + return ( Os Meus Ninjas - +