mirror of
https://github.com/ditkrg/AuthorizationServerDemos.git
synced 2026-01-23 03:36:52 +00:00
Renders out the vehicles
This commit is contained in:
parent
6de163d1f4
commit
c6e7d1ae28
@ -1,73 +1,14 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React from "react";
|
||||||
import * as apiService from "../services/apiService";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import { prettifyJson } from "../utils/jsonUtils";
|
|
||||||
import Navbar from "./components/Navbar";
|
import Navbar from "./components/Navbar";
|
||||||
import Main from "./components/Main";
|
import Main from "./components/Main";
|
||||||
|
import VehiclesMain from "./components/VehiclesMain";
|
||||||
|
|
||||||
const YourVehicles = () => {
|
const YourVehicles = () => {
|
||||||
const user = useSelector((state) => state.auth.user);
|
|
||||||
const [vehicleData, setVehicleData] = useState(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getVehicles();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
async function getVehicles() {
|
|
||||||
console.log(user);
|
|
||||||
const vehicles = await apiService.getVehiclesFromApi(user.access_token);
|
|
||||||
setVehicleData(vehicles);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getType(type) {
|
|
||||||
switch (type) {
|
|
||||||
case 1:
|
|
||||||
return "Sedan";
|
|
||||||
case 2:
|
|
||||||
return "SUV";
|
|
||||||
case 3:
|
|
||||||
return "Pickup";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-screen">
|
<div className="h-screen overflow-hidden">
|
||||||
<Navbar />
|
<Navbar />
|
||||||
<Main
|
<Main Component={VehiclesMain} />
|
||||||
Component={() => <h1>hello world! this is the "Your Vehicles Page"</h1>}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
// <>
|
|
||||||
// <h1>Traffic Police</h1>
|
|
||||||
// <p>Hello, {user.profile.given_name}.</p>
|
|
||||||
|
|
||||||
// <h3>Your Vehicles:</h3>
|
|
||||||
// {vehicleData ? (
|
|
||||||
// <ul>
|
|
||||||
// {vehicleData.map((v) => (
|
|
||||||
// <li key={v.id}>
|
|
||||||
// {v.color} {v.model} ({v.licensePlate}) - {getType(v.type)}
|
|
||||||
// </li>
|
|
||||||
// ))}
|
|
||||||
// </ul>
|
|
||||||
// ) : (
|
|
||||||
// <p>No vehicles yet :(</p>
|
|
||||||
// )}
|
|
||||||
// <pre>
|
|
||||||
// <code>
|
|
||||||
// {prettifyJson(vehicleData ? vehicleData : "No vehicles yet :(")}
|
|
||||||
// </code>
|
|
||||||
// </pre>
|
|
||||||
// <p>
|
|
||||||
// <a
|
|
||||||
// target="_blank"
|
|
||||||
// rel="noopener noreferrer"
|
|
||||||
// href="https://github.com/tappyy/react-IS4-auth-demo"
|
|
||||||
// >
|
|
||||||
// Github Repo
|
|
||||||
// </a>
|
|
||||||
// </p>
|
|
||||||
// </>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
import React from 'react';
|
import React from "react";
|
||||||
|
|
||||||
const Button = ({onClickEvent}) => (
|
const Button = ({ onClickEvent, text }) => (
|
||||||
<button onClick={onClickEvent} className="bg-blue-custom border-0 font-inter font-semibold rounded text-xl m-0">
|
<button
|
||||||
Login
|
onClick={onClickEvent}
|
||||||
|
className="bg-blue-custom border-0 font-inter font-semibold rounded text-xl m-0"
|
||||||
|
>
|
||||||
|
{text}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
12
React/src/pages/components/Heading1.js
Normal file
12
React/src/pages/components/Heading1.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
const Heading1 = ({ text, classes = "", styles = {} }) => (
|
||||||
|
<h1
|
||||||
|
className={`font-playfair text-black-custom text-6xl mb-12 ${classes}`}
|
||||||
|
style={{ ...styles }}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</h1>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Heading1;
|
||||||
@ -2,6 +2,7 @@ import React from "react";
|
|||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import { storeUser } from "../../actions/authActions";
|
import { storeUser } from "../../actions/authActions";
|
||||||
import store from "../../store";
|
import store from "../../store";
|
||||||
|
import Heading1 from "./Heading1";
|
||||||
|
|
||||||
const LoginWindow = () => {
|
const LoginWindow = () => {
|
||||||
const onUserLogin = () => {
|
const onUserLogin = () => {
|
||||||
@ -12,13 +13,12 @@ const LoginWindow = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="xl:w-1/3 lg:w-5/12 md:w-2/4 sm:w-9/12 w-11/12 flex flex-col justify-center shadow md:px-32 sm:px-28 md:py-40 sm:py-36 px-20 py-16">
|
<div className="xl:w-1/3 lg:w-5/12 md:w-2/4 sm:w-9/12 w-11/12 flex flex-col justify-center shadow md:px-32 sm:px-28 md:py-40 sm:py-36 px-20 py-16">
|
||||||
<h1 className="font-playfair text-black-custom text-6xl mb-12">
|
<Heading1 text={"Traffic Police Service"} />
|
||||||
Traffic Police Service
|
|
||||||
</h1>
|
|
||||||
<p className="text-black-custom font-light text-3xl mb-20">
|
<p className="text-black-custom font-light text-3xl mb-20">
|
||||||
Login to your account to view your dashboard and register a new vehicle.
|
Login to your account to view your dashboard and register a new vehicle.
|
||||||
</p>
|
</p>
|
||||||
<Button onClickEvent={onUserLogin} />
|
<Button onClickEvent={onUserLogin} text={"Login"} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
import React from 'react';
|
import React from "react";
|
||||||
|
|
||||||
const Main = ({ Component }) => {
|
const Main = ({ Component, styles = {} }) => {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center h-4/5">
|
<div
|
||||||
|
className="flex flex-col items-center justify-center h-4/5"
|
||||||
|
style={{ ...styles }}
|
||||||
|
>
|
||||||
<Component />
|
<Component />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
131
React/src/pages/components/VehiclesMain.js
Normal file
131
React/src/pages/components/VehiclesMain.js
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import * as apiService from "../../services/apiService";
|
||||||
|
import { prettifyJson } from "../../utils/jsonUtils";
|
||||||
|
import Heading1 from "./Heading1";
|
||||||
|
import Button from "./Button";
|
||||||
|
|
||||||
|
const VehiclesMain = () => {
|
||||||
|
const user = useSelector((state) => state.auth.user);
|
||||||
|
|
||||||
|
// Initial state must be null ** Temporary **
|
||||||
|
const [vehicleData, setVehicleData] = useState([
|
||||||
|
{
|
||||||
|
id: Math.floor(Math.random() * 200) + 1,
|
||||||
|
color: "White",
|
||||||
|
model: "Toyota Camry",
|
||||||
|
licensePlate: "14324235",
|
||||||
|
type: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Math.floor(Math.random() * 200) + 1,
|
||||||
|
color: "Black",
|
||||||
|
model: "Honda Accord",
|
||||||
|
licensePlate: "8765658",
|
||||||
|
type: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Math.floor(Math.random() * 200) + 1,
|
||||||
|
color: "Beige",
|
||||||
|
model: "Toyota Corolla",
|
||||||
|
licensePlate: "235464",
|
||||||
|
type: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Math.floor(Math.random() * 200) + 1,
|
||||||
|
color: "Grey",
|
||||||
|
model: "Toyota Yaris",
|
||||||
|
licensePlate: "1878767",
|
||||||
|
type: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Math.floor(Math.random() * 200) + 1,
|
||||||
|
color: "White",
|
||||||
|
model: "Toyota Camry",
|
||||||
|
licensePlate: "9956443",
|
||||||
|
type: 1,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: Math.floor(Math.random() * 200) + 1,
|
||||||
|
color: "White",
|
||||||
|
model: "Toyota Camry",
|
||||||
|
licensePlate: "9956443",
|
||||||
|
type: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Math.floor(Math.random() * 200) + 1,
|
||||||
|
color: "White",
|
||||||
|
model: "Toyota Camry",
|
||||||
|
licensePlate: "9956443",
|
||||||
|
type: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Math.floor(Math.random() * 200) + 1,
|
||||||
|
color: "White",
|
||||||
|
model: "Toyota Camry",
|
||||||
|
licensePlate: "9956443",
|
||||||
|
type: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Math.floor(Math.random() * 200) + 1,
|
||||||
|
color: "White",
|
||||||
|
model: "Toyota Camry",
|
||||||
|
licensePlate: "9956443",
|
||||||
|
type: 1,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getVehicles();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function getVehicles() {
|
||||||
|
console.log(user);
|
||||||
|
const vehicles = await apiService.getVehiclesFromApi(user.access_token);
|
||||||
|
setVehicleData(vehicles);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getType(type) {
|
||||||
|
switch (type) {
|
||||||
|
case 1:
|
||||||
|
return "Sedan";
|
||||||
|
case 2:
|
||||||
|
return "SUV";
|
||||||
|
case 3:
|
||||||
|
return "Pickup";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<Heading1
|
||||||
|
text={"Traffic Police Service"}
|
||||||
|
styles={{ marginBottom: "0", marginTop: "20%" }}
|
||||||
|
/>
|
||||||
|
{/* <p>Hello, {user.profile.given_name}.</p> */}
|
||||||
|
{vehicleData ? (
|
||||||
|
<>
|
||||||
|
<h3 className="font-light font-inter text-black-custom my-20 self-start">
|
||||||
|
Your Vehicles:
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{vehicleData.map((v) => (
|
||||||
|
<li key={v.id}>
|
||||||
|
{v.color} {v.model} ({v.licensePlate}) - {getType(v.type)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<h3 className="font-light font-inter text-black-custom my-32 self-center">
|
||||||
|
No vehicles yet.
|
||||||
|
</h3>
|
||||||
|
)}
|
||||||
|
<Button text={"Register A Vehicle"} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default VehiclesMain;
|
||||||
Loading…
Reference in New Issue
Block a user