Fix types
This commit is contained in:
parent
c7494e8404
commit
2626c16941
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
|
||||
|
||||
export interface IpropsWithSessionData {
|
||||
sessionData?: {
|
||||
expires: string;
|
||||
user: {
|
||||
email: string;
|
||||
is: string;
|
||||
image: string;
|
||||
name: string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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,15 +15,11 @@ const CreateDeviceType: React.FC = (props) => {
|
|||
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col items-center justify-center gap-4">
|
||||
<p className="text-center text-2xl text-white">
|
||||
</p>
|
||||
<h2 className="py-4 text-2xl font-bold text-white">
|
||||
Manufacturers
|
||||
</h2>
|
||||
<div className="flex flex-col items-center justify-center gap-4">
|
||||
<h2 className="py-4 text-2xl font-bold text-white">Create Manufacturer</h2>
|
||||
<h2 className="py-4 text-2xl font-bold text-white">Create Device</h2>
|
||||
<form
|
||||
className="form-control w-full max-w-xs"
|
||||
onSubmit={(event) => {
|
||||
|
|
@ -35,9 +29,13 @@ const CreateDeviceType: React.FC = (props) => {
|
|||
name: newDeviceType,
|
||||
description: newDescription,
|
||||
manufacturerId: manufacturerId,
|
||||
});
|
||||
setNewDeviceType("");
|
||||
router.push("/nim/devicetype");
|
||||
},
|
||||
{
|
||||
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) => {
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div className="flex flex-col items-center justify-center w-3/4">
|
||||
<div className="flex flex-row items-center justify-between w-full my-2">
|
||||
<h2 className="py-4 text-2xl font-bold text-white">
|
||||
Manufacturers
|
||||
Devices
|
||||
</h2>
|
||||
<Link href="/nim/devicetype/add"><button className="btn btn-outline btn-success">Add New</button></Link>
|
||||
</div>
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,18 @@
|
|||
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 (
|
||||
<div className="flex flex-col items-center justify-center gap-4">
|
||||
<p className="text-center text-2xl text-white">
|
||||
</p>
|
||||
<h2 className="py-4 text-2xl font-bold text-white">
|
||||
Manufacturers
|
||||
</h2>
|
||||
<div className="flex flex-col items-center justify-center gap-4">
|
||||
<h2 className="py-4 text-2xl font-bold text-white">Create Manufacturer</h2>
|
||||
<form
|
||||
|
|
@ -24,7 +22,13 @@ const CreateManufacturer: React.FC = (props) => {
|
|||
addManufacturer.mutate({
|
||||
name: newManufacturer,
|
||||
description: newDescription,
|
||||
});
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
router.push("/nim/manufacturer")
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ const Home: NextPage = () => {
|
|||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Manufacturer</title>
|
||||
<title>Add Device</title>
|
||||
<meta name="description" content="Generated by create-t3-app" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
|
|
@ -22,7 +22,7 @@ const Home: NextPage = () => {
|
|||
? <Navbar />
|
||||
: <Navbar sessionData={sessionData}/>
|
||||
}
|
||||
{sessionData ? <CreateDeviceType sessionData={sessionData}/>: <></>}
|
||||
{sessionData ? <CreateDeviceType/>: <></>}
|
||||
<div className="container flex flex-col items-center py-3 gap-6 ">
|
||||
</div>
|
||||
</main>
|
||||
|
|
|
|||
Loading…
Reference in New Issue