diff --git a/package.json b/package.json index a1528e2..6683836 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "@tailwindcss/vite": "^4.0.14", + "@tanstack/react-form": "^1.1.2", "@tanstack/react-query": "^5.69.0", "@tanstack/react-table": "^8.21.2", "axios": "^1.8.4", diff --git a/src/components/layouts/Dashboard/Header.tsx b/src/components/layouts/Dashboard/Header.tsx index c33190f..8732f72 100644 --- a/src/components/layouts/Dashboard/Header.tsx +++ b/src/components/layouts/Dashboard/Header.tsx @@ -16,7 +16,7 @@ const Header: React.FC = ({ toggleSidebar, }) => { return ( -
+
{/* Mobile Sidebar Toggle */}
@@ -84,13 +84,13 @@ const Header: React.FC = ({ className="dropdown-content bg-base-100 rounded-box w-52" > Hi, {user?.name} - - + + Profile - - Settings + + Settings + +
+ +
+ ); +}; +export default DeviceForm; \ No newline at end of file diff --git a/src/pages/device/DevicePage.tsx b/src/pages/device/DevicePage.tsx index e98aaf8..7a591ba 100644 --- a/src/pages/device/DevicePage.tsx +++ b/src/pages/device/DevicePage.tsx @@ -20,19 +20,33 @@ import { Pencil } from "lucide-react"; import dayjs from "dayjs"; import id from "dayjs/locale/id"; import Dropdown from "@/components/actions/Dropdown/Dropdown"; +import { useNavigate } from "react-router"; dayjs.locale(id); export default function DevicePage() { const { data: devices, isLoading, isError, error } = useDevices(); + // State untuk sorting dan filtering - const [sorting, setSorting] = useState([]); + const [sorting] = useState([]); const [globalFilter, setGlobalFilter] = useState(""); const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10, // Default 10 data per halaman }); + const navigate = useNavigate(); + + // Replace handleCreateDevice with navigation + const handleCreateDevice = () => { + navigate("/devices/create"); + }; + + // Replace handleEditDevice with navigation + const handleEditDevice = (deviceId: string) => { + navigate(`/devices/${deviceId}/edit`); + }; + const columnHelper = createColumnHelper(); const columns = useMemo( @@ -41,33 +55,30 @@ export default function DevicePage() { id: "actions", header: "", cell: ({ row }) => ( - - + + - - - - - - - - + + + + + + + handleEditDevice(row.original.id)}> - Edit - - - + Edit + + + ), size: 10, }), @@ -143,10 +154,12 @@ export default function DevicePage() { }); return ( -
+

Devices

- +
diff --git a/src/pages/device/EditDevicePage.tsx b/src/pages/device/EditDevicePage.tsx new file mode 100644 index 0000000..3bb58cc --- /dev/null +++ b/src/pages/device/EditDevicePage.tsx @@ -0,0 +1,27 @@ +import { useParams } from 'react-router'; +import DeviceForm from './DeviceForm'; +import { useDeviceById } from '@/features/devices/api/devices'; +import Loading from '@/components/feedback/Loading'; + +export default function EditDevicePage() { + const { id } = useParams<{ id: string }>(); + + const { data: device, isLoading } = useDeviceById(id as string); + + if (isLoading) return ; + + return ( +
+
+

Edit Device

+
+ +
+ window.history.back()} + /> +
+
+ ); +} diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 8acfc76..375eb93 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -7,6 +7,8 @@ import UsersListPage from '@/pages/users/UsersListPage'; import UserFormPage from '@/pages/users/UserFormPage'; import NotFoundPage from '@/pages/NotFoundPage'; import DevicePage from '@/pages/device/DevicePage'; +import CreateDevicePage from '@/pages/device/CreateDevicePage'; +import EditDevicePage from '@/pages/device/EditDevicePage'; const router = createBrowserRouter([ // Public routes @@ -33,6 +35,16 @@ const router = createBrowserRouter([ { path: '/devices', element: , + // children: [ + // ] + }, + { + path: '/devices/create', + element: , + }, + { + path: '/devices/:id/edit', + element: , }, { path: '/users',