diff --git a/src/App.tsx b/src/App.tsx index c049b34..da91a93 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -34,7 +34,6 @@ function App() { } /> } /> } /> - } /> } /> } /> } /> diff --git a/src/component/Navigation/Navigation.tsx b/src/component/Navigation/Navigation.tsx index 37a1e94..1bb260e 100644 --- a/src/component/Navigation/Navigation.tsx +++ b/src/component/Navigation/Navigation.tsx @@ -146,17 +146,6 @@ const Navigation: React.FC = ({ -
  • -
    - - Create Site - -
    -
  • = ({ onClick={toggleDrawer} className="w-60" > - List Sites + Sites
  • diff --git a/src/pages/admin/CreateSite.tsx b/src/pages/admin/CreateSite.tsx deleted file mode 100644 index fe7c719..0000000 --- a/src/pages/admin/CreateSite.tsx +++ /dev/null @@ -1,106 +0,0 @@ -import axios from "axios"; -import { useState } from "react"; -import { useNavigate } from "react-router-dom"; - -function CreateSite() { - const [site, setSite] = useState({ - name: "", - desc: "", - address: "", - }); - const navigate = useNavigate(); - - const handleInputChange = ( - e: React.ChangeEvent< - HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement - >, - ) => { - const { name, value } = e.target; - setSite({ ...site, [name]: value }); - }; - - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); - - // Créer les query parameters - const params = new URLSearchParams({ - name: site.name, - description: site.description, - address: site.address, - }); - - axios.post(`/api/sites?${params.toString()}`).then((res) => { - if (res.status === 200) { - navigate(`/site/${res.data.id}`); - } - }); - }; - return ( -
    -
    -

    - Create Site -

    - -
    -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - -
    -
    -
    -
    - ); -} - -export default CreateSite; diff --git a/src/pages/admin/Sites.tsx b/src/pages/admin/Sites.tsx index aa3fb1e..e61dab0 100644 --- a/src/pages/admin/Sites.tsx +++ b/src/pages/admin/Sites.tsx @@ -1,10 +1,15 @@ import axios from "axios"; import { useEffect, useState } from "react"; -import { Site } from "../../type/SiteType"; function Sites() { const [sites, setSites] = useState([]); const [reload, setReload] = useState(0); + const [showCreateForm, setShowCreateForm] = useState(false); + const [site, setSite] = useState({ + name: "", + desc: "", + address: "", + }); useEffect(() => { axios.get("/api/sites").then((res) => { @@ -12,29 +17,113 @@ function Sites() { }); }, [reload]); - const handleEditSite = (siteId: number) => { + const handleEditSite = (siteId) => { alert(`Edit site with ID: ${siteId}`); }; - /*const deleteSites = () => { - axios.delete("/api/sites").then(() => { - setReload(reload + 1); + const handleInputChange = (e) => { + const { name, value } = e.target; + setSite({ ...site, [name]: value }); + }; + + const handleSubmit = (e) => { + e.preventDefault(); + + const params = new URLSearchParams({ + name: site.name, + description: site.desc, + address: site.address, }); - };*/ + + axios.post(`/api/sites?${params.toString()}`).then((res) => { + if (res.status === 200) { + setSite({ name: "", desc: "", address: "" }); + setShowCreateForm(false); + setReload(reload + 1); + } + }); + }; return (
    -

    +

    Manage Sites

    - {/**/} +
    - {/* Users Table */} + {/* Create Site Form */} + {showCreateForm && ( +
    +

    + Create New Site +

    +
    +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + +
    +
    +
    + )} + + {/* Sites Table */}
    @@ -43,12 +132,11 @@ function Sites() { - - {sites.map((site: Site, index: number) => ( + {sites.map((site, index) => ( @@ -56,7 +144,7 @@ function Sites() {
    Name Address RolesInstances Actions
    {index + 1} {site.name}{site.listJi}