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 { useState } from "react";
|
||||||
import Select from 'react-select';
|
import Select from 'react-select';
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { url } from "inspector";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const CreateDeviceType: React.FC = (props) => {
|
const CreateDeviceType: React.FC = () => {
|
||||||
const sessionData = props.sessionData
|
|
||||||
const [newDeviceType, setNewDeviceType] = useState("");
|
const [newDeviceType, setNewDeviceType] = useState("");
|
||||||
const [newDescription, setNewDescription] = useState("");
|
const [newDescription, setNewDescription] = useState("");
|
||||||
const [manufacturerId, setManufacturerId] = useState("0");
|
const [manufacturerId, setManufacturerId] = useState("0");
|
||||||
|
|
@ -17,15 +15,11 @@ const CreateDeviceType: React.FC = (props) => {
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<div className="flex flex-col items-center justify-center gap-4">
|
<div className="flex flex-col items-center justify-center gap-4">
|
||||||
<p className="text-center text-2xl text-white">
|
<p className="text-center text-2xl text-white">
|
||||||
</p>
|
</p>
|
||||||
<h2 className="py-4 text-2xl font-bold text-white">
|
|
||||||
Manufacturers
|
|
||||||
</h2>
|
|
||||||
<div className="flex flex-col items-center justify-center gap-4">
|
<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
|
<form
|
||||||
className="form-control w-full max-w-xs"
|
className="form-control w-full max-w-xs"
|
||||||
onSubmit={(event) => {
|
onSubmit={(event) => {
|
||||||
|
|
@ -35,9 +29,13 @@ const CreateDeviceType: React.FC = (props) => {
|
||||||
name: newDeviceType,
|
name: newDeviceType,
|
||||||
description: newDescription,
|
description: newDescription,
|
||||||
manufacturerId: manufacturerId,
|
manufacturerId: manufacturerId,
|
||||||
});
|
},
|
||||||
setNewDeviceType("");
|
{
|
||||||
router.push("/nim/devicetype");
|
onSuccess: () => {
|
||||||
|
router.push("/nim/devicetype")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
|
@ -69,7 +67,6 @@ const CreateDeviceType: React.FC = (props) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setManufacturerId(event.value)
|
setManufacturerId(event.value)
|
||||||
console.log(manufacturerId)
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
@ -94,7 +91,6 @@ const CreateDeviceType: React.FC = (props) => {
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,15 @@ import { api } from "~/utils/api";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
const DeviceTypeTable: React.FC = (props) => {
|
const DeviceTypeTable: React.FC = () => {
|
||||||
const sessionData = props.sessionData
|
|
||||||
const devicetype = api.devicetype.getAll.useQuery();
|
const devicetype = api.devicetype.getAll.useQuery();
|
||||||
const manufacturer = api.manufacturer.getAll.useQuery();
|
|
||||||
console.log(devicetype.data)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center w-3/4">
|
<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">
|
<div className="flex flex-row items-center justify-between w-full my-2">
|
||||||
<h2 className="py-4 text-2xl font-bold text-white">
|
<h2 className="py-4 text-2xl font-bold text-white">
|
||||||
Manufacturers
|
Devices
|
||||||
</h2>
|
</h2>
|
||||||
<Link href="/nim/devicetype/add"><button className="btn btn-outline btn-success">Add New</button></Link>
|
<Link href="/nim/devicetype/add"><button className="btn btn-outline btn-success">Add New</button></Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -49,11 +47,3 @@ const DeviceTypeTable: React.FC = (props) => {
|
||||||
|
|
||||||
export default DeviceTypeTable;
|
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 { api } from "~/utils/api";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
|
|
||||||
const CreateManufacturer: React.FC = (props) => {
|
const CreateManufacturer: React.FC = () => {
|
||||||
const sessionData = props.sessionData
|
|
||||||
const [newManufacturer, setNewManufacturer] = useState("");
|
const [newManufacturer, setNewManufacturer] = useState("");
|
||||||
const [newDescription, setNewDescription] = useState("");
|
const [newDescription, setNewDescription] = useState("");
|
||||||
const addManufacturer = api.manufacturer.addManufacturer.useMutation();
|
const addManufacturer = api.manufacturer.addManufacturer.useMutation();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center gap-4">
|
<div className="flex flex-col items-center justify-center gap-4">
|
||||||
<p className="text-center text-2xl text-white">
|
<p className="text-center text-2xl text-white">
|
||||||
</p>
|
</p>
|
||||||
<h2 className="py-4 text-2xl font-bold text-white">
|
|
||||||
Manufacturers
|
|
||||||
</h2>
|
|
||||||
<div className="flex flex-col items-center justify-center gap-4">
|
<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 Manufacturer</h2>
|
||||||
<form
|
<form
|
||||||
|
|
@ -24,7 +22,13 @@ const CreateManufacturer: React.FC = (props) => {
|
||||||
addManufacturer.mutate({
|
addManufacturer.mutate({
|
||||||
name: newManufacturer,
|
name: newManufacturer,
|
||||||
description: newDescription,
|
description: newDescription,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
|
onSuccess: () => {
|
||||||
|
router.push("/nim/manufacturer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ import { api } from "~/utils/api";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
const ManufacturersTable: React.FC = (props) => {
|
const ManufacturersTable: React.FC = () => {
|
||||||
const sessionData = props.sessionData
|
|
||||||
const manufacturer = api.manufacturer.getAll.useQuery();
|
const manufacturer = api.manufacturer.getAll.useQuery();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ const Home: NextPage = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Manufacturer</title>
|
<title>Add Device</title>
|
||||||
<meta name="description" content="Generated by create-t3-app" />
|
<meta name="description" content="Generated by create-t3-app" />
|
||||||
<link rel="icon" href="/favicon.ico" />
|
<link rel="icon" href="/favicon.ico" />
|
||||||
</Head>
|
</Head>
|
||||||
|
|
@ -22,7 +22,7 @@ const Home: NextPage = () => {
|
||||||
? <Navbar />
|
? <Navbar />
|
||||||
: <Navbar sessionData={sessionData}/>
|
: <Navbar sessionData={sessionData}/>
|
||||||
}
|
}
|
||||||
{sessionData ? <CreateDeviceType sessionData={sessionData}/>: <></>}
|
{sessionData ? <CreateDeviceType/>: <></>}
|
||||||
<div className="container flex flex-col items-center py-3 gap-6 ">
|
<div className="container flex flex-col items-center py-3 gap-6 ">
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue