diff --git a/src/Interfaces.d.ts b/src/Interfaces.d.ts new file mode 100644 index 0000000..b19c01c --- /dev/null +++ b/src/Interfaces.d.ts @@ -0,0 +1,14 @@ + + + +export interface IpropsWithSessionData { + sessionData?: { + expires: string; + user: { + email: string; + is: string; + image: string; + name: string; + } + } +} \ No newline at end of file diff --git a/src/components/nim/devicetype/CreateDeviceType.tsx b/src/components/nim/devicetype/CreateDeviceType.tsx index 202e436..5de93ac 100644 --- a/src/components/nim/devicetype/CreateDeviceType.tsx +++ b/src/components/nim/devicetype/CreateDeviceType.tsx @@ -2,12 +2,10 @@ import { api } from "~/utils/api"; import { useState } from "react"; import Select from 'react-select'; import { useRouter } from "next/router"; -import { url } from "inspector"; -const CreateDeviceType: React.FC = (props) => { - const sessionData = props.sessionData +const CreateDeviceType: React.FC = () => { const [newDeviceType, setNewDeviceType] = useState(""); const [newDescription, setNewDescription] = useState(""); const [manufacturerId, setManufacturerId] = useState("0"); @@ -17,27 +15,27 @@ const CreateDeviceType: React.FC = (props) => { return ( - <>

-

- Manufacturers -

-

Create Manufacturer

+

Create Device

{ try{ event.preventDefault(); addDeviceType.mutate({ - name: newDeviceType, - description: newDescription, - manufacturerId: manufacturerId, - }); - setNewDeviceType(""); - router.push("/nim/devicetype"); + name: newDeviceType, + description: newDescription, + manufacturerId: manufacturerId, + }, + { + onSuccess: () => { + router.push("/nim/devicetype") + } + } + ); } catch (error) { console.log(error) @@ -69,7 +67,6 @@ const CreateDeviceType: React.FC = (props) => { return; } setManufacturerId(event.value) - console.log(manufacturerId) }} /> @@ -94,7 +91,6 @@ const CreateDeviceType: React.FC = (props) => {
- ); }; diff --git a/src/components/nim/devicetype/DeviceTypeTable.tsx b/src/components/nim/devicetype/DeviceTypeTable.tsx index 593616e..e0547a5 100644 --- a/src/components/nim/devicetype/DeviceTypeTable.tsx +++ b/src/components/nim/devicetype/DeviceTypeTable.tsx @@ -2,17 +2,15 @@ import { api } from "~/utils/api"; import { useState } from "react"; import Link from "next/link"; -const DeviceTypeTable: React.FC = (props) => { - const sessionData = props.sessionData +const DeviceTypeTable: React.FC = () => { const devicetype = api.devicetype.getAll.useQuery(); - const manufacturer = api.manufacturer.getAll.useQuery(); - console.log(devicetype.data) + return (

- Manufacturers + Devices

@@ -49,11 +47,3 @@ const DeviceTypeTable: React.FC = (props) => { export default DeviceTypeTable; - -function findManufacturerName(manufacturerId){ - for(let i = 0; i < manufacturer.data.length; i++){ - if(manufacturer.data[i].id == manufacturerId){ - return manufacturer.data[i].name - } - } -} \ No newline at end of file diff --git a/src/components/nim/manufacturer/CreateManufacturer.tsx b/src/components/nim/manufacturer/CreateManufacturer.tsx index d275011..8354041 100644 --- a/src/components/nim/manufacturer/CreateManufacturer.tsx +++ b/src/components/nim/manufacturer/CreateManufacturer.tsx @@ -1,33 +1,37 @@ import { api } from "~/utils/api"; import { useState } from "react"; +import { useRouter } from "next/router"; -const CreateManufacturer: React.FC = (props) => { - const sessionData = props.sessionData +const CreateManufacturer: React.FC = () => { const [newManufacturer, setNewManufacturer] = useState(""); const [newDescription, setNewDescription] = useState(""); const addManufacturer = api.manufacturer.addManufacturer.useMutation(); + const router = useRouter(); return (

-

- Manufacturers -

Create Manufacturer

{ try{event.preventDefault(); - addManufacturer.mutate({ - name: newManufacturer, - description: newDescription, - }); + addManufacturer.mutate({ + name: newManufacturer, + description: newDescription, + }, + { + onSuccess: () => { + router.push("/nim/manufacturer") + } + } + ); } catch (error) { - console.log(error) + console.log(error) } }} > diff --git a/src/components/nim/manufacturer/ManufacturersTable.tsx b/src/components/nim/manufacturer/ManufacturersTable.tsx index bc44936..9d6d8bf 100644 --- a/src/components/nim/manufacturer/ManufacturersTable.tsx +++ b/src/components/nim/manufacturer/ManufacturersTable.tsx @@ -2,8 +2,7 @@ import { api } from "~/utils/api"; import { useState } from "react"; import Link from "next/link"; -const ManufacturersTable: React.FC = (props) => { - const sessionData = props.sessionData +const ManufacturersTable: React.FC = () => { const manufacturer = api.manufacturer.getAll.useQuery(); diff --git a/src/pages/nim/devicetype/add.tsx b/src/pages/nim/devicetype/add.tsx index 687953b..fba666c 100644 --- a/src/pages/nim/devicetype/add.tsx +++ b/src/pages/nim/devicetype/add.tsx @@ -13,7 +13,7 @@ const Home: NextPage = () => { return ( <> - Manufacturer + Add Device @@ -22,7 +22,7 @@ const Home: NextPage = () => { ? : } - {sessionData ? : <>} + {sessionData ? : <>}