Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Youllou committed Dec 17, 2024
1 parent 1dcbe76 commit 95b43a1
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/app/api/inspections/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function POST(request: Request) {
});
}

export async function GET(request: Request){
export async function GET(request: Request) {
const authHeader = request.headers.get("Authorization");
if (!authHeader) {
return new Response(
Expand Down
129 changes: 80 additions & 49 deletions src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,97 @@
"use client"
"use client";
import FertilizerList from "@/components/InspectionList/InspectionList";
import { Grid2 as Grid, InputAdornment, TextField, Typography } from "@mui/material";
import {
Grid2 as Grid,
InputAdornment,
TextField,
Typography,
} from "@mui/material";
import { Search, LocationOn } from "@mui/icons-material";
import { useState } from "react";

const Dashboard = () => {

const [search, setSearch] = useState("");

return <Grid container
spacing={2}
className={"p-5 h-full"}
return (
<Grid container spacing={2} className={"p-5 h-full"}>
<Grid size={{ xs: 12, sm: 4, md: 3 }}>
<Grid
container
className={"p-2 border-gray-200 border-2 rounded-md h-fit"}
>
<Grid size={{xs:12, sm:4, md:3}} >
<Grid container className={"p-2 border-gray-200 border-2 rounded-md h-fit"} >
<Grid size={12}>
<Typography component={"h2"} className={"!font-black "}>Username</Typography>
<Grid size={12}>
<Typography component={"h2"} className={"!font-black "}>
Username
</Typography>
</Grid>
<Grid size={4}>
<b>Mail:</b>
</Grid>
<Grid size={8}>User email</Grid>
<Grid size={4}>
<b>Role:</b>
</Grid>
<Grid size={8}>User role</Grid>
<Grid size={4}>
<b>
<LocationOn />:
</b>
</Grid>
<Grid size={8}>User location</Grid>
</Grid>
<Grid size={4}><b>Mail:</b></Grid><Grid size={8}>User email</Grid>
<Grid size={4}><b>Role:</b></Grid><Grid size={8}>User role</Grid>
<Grid size={4}><b><LocationOn/>:</b></Grid><Grid size={8}>User location</Grid>
</Grid>
<Grid container className={"p-2 border-gray-200 border-2 rounded-md h-fit mt-2 w-11/12"}>
<Grid size={12}>
<Typography component={"h4"} className={"!font-semiboldl "}>Number of inspections</Typography>
<Grid
container
className={
"p-2 border-gray-200 border-2 rounded-md h-fit mt-2 w-11/12"
}
>
<Grid size={12}>
<Typography component={"h4"} className={"!font-semiboldl "}>
Number of inspections
</Typography>
</Grid>
</Grid>
</Grid>
</Grid>
<Grid size={{xs:12, sm:8, md:9}} className={"border-gray-200 border-2 rounded-md p-2 lg:h-300"}>
<Grid container spacing={2} className={"h-full"}>
<Grid size={{xs:12, sm:6, md:4}} >
<Typography component={"h2"} className={"!font-black"}>My inspections</Typography>
</Grid>
<Grid size={{xs:12, sm:6, md:8}} >
<TextField
placeholder={"Search"}
variant={"filled"}
value={search}
onChange={(e)=>setSearch(e.target.value)}
fullWidth
slotProps={{
htmlInput: {
className: "!p-0 after:!transition-none "
},
input: {
className:"p-2",
startAdornment:(
<InputAdornment position={"start"} className={"!m-0"}>
<Search/>
</InputAdornment>
)
}
}}
/>
</Grid>
<hr className={"w-full"}/>
<Grid size={{xs:12}}>
<FertilizerList search={search}/>
<Grid
size={{ xs: 12, sm: 8, md: 9 }}
className={"border-gray-200 border-2 rounded-md p-2 lg:h-300"}
>
<Grid container spacing={2} className={"h-full"}>
<Grid size={{ xs: 12, sm: 6, md: 4 }}>
<Typography component={"h2"} className={"!font-black"}>
My inspections
</Typography>
</Grid>
<Grid size={{ xs: 12, sm: 6, md: 8 }}>
<TextField
placeholder={"Search"}
variant={"filled"}
value={search}
onChange={(e) => setSearch(e.target.value)}
fullWidth
slotProps={{
htmlInput: {
className: "!p-0 after:!transition-none ",
},
input: {
className: "p-2",
startAdornment: (
<InputAdornment position={"start"} className={"!m-0"}>
<Search />
</InputAdornment>
),
},
}}
/>
</Grid>
<hr className={"w-full"} />
<Grid size={{ xs: 12 }}>
<FertilizerList search={search} />
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
);
};

export default Dashboard;
62 changes: 37 additions & 25 deletions src/components/InspectionList/InspectionList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use client"
"use client";
import { Stack } from "@mui/material";
import InspectionPreview from "@/types/InspectionPreview";
import InspectionElement from "@/components/InspectionList/InspectionElement";
Expand All @@ -11,41 +11,53 @@ interface InspectionListProps {
search: string;
}

const InspectionList = ({search}:InspectionListProps)=>{

const [inspectList, setInspectList] = useState([] as InspectionPreview[])
const [shownList, setShownList] = useState([] as InspectionPreview[])
const InspectionList = ({ search }: InspectionListProps) => {
const [inspectList, setInspectList] = useState([] as InspectionPreview[]);
const [shownList, setShownList] = useState([] as InspectionPreview[]);

const router = useRouter();

const handleInspectionClick = (id: string) => {
router.push(`/label-data-validation/${id}`);
}
};

useEffect(() => {
const username = atob(Cookies.get("token") ?? "");
const password = "";
const authHeader = "Basic " + btoa(`${username}:${password}`);
axios.get("/api/inspections",
{
headers: {
Authorization: authHeader
},
}).then((response) => {
setInspectList(response.data);
setShownList(response.data);
});
axios
.get("/api/inspections", {
headers: {
Authorization: authHeader,
},
})
.then((response) => {
setInspectList(response.data);
setShownList(response.data);
});
}, []);
useEffect(() => {
setShownList(inspectList.filter((inspection) => {
return inspection.product_name!.toLowerCase().includes(search.toLowerCase());
}));
setShownList(
inspectList.filter((inspection) => {
return inspection
.product_name!.toLowerCase()
.includes(search.toLowerCase());
}),
);
}, [inspectList, search]);
return <Stack spacing={2} className={"h-[80vh] overflow-y-scroll p-5 pl-0"}>
{shownList.map((inspection) => {
return <InspectionElement inspection={inspection} key={inspection.id} handleClick={()=>handleInspectionClick(inspection.id)}/>
})}
</Stack>
}
return (
<Stack spacing={2} className={"h-[80vh] overflow-y-scroll p-5 pl-0"}>
{shownList.map((inspection) => {
return (
<InspectionElement
inspection={inspection}
key={inspection.id}
handleClick={() => handleInspectionClick(inspection.id)}
/>
);
})}
</Stack>
);
};

export default InspectionList
export default InspectionList;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('InspectionElement', () => {
it('TODO', () => {
expect(false).toBe(true)
})
})
describe("InspectionElement", () => {
it("TODO", () => {
expect(false).toBe(true);
});
});
10 changes: 5 additions & 5 deletions src/components/InspectionList/__tests__/InspectionList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('InspectionList', () => {
it('TODO', () => {
expect(false).toBe(true)
})
})
describe("InspectionList", () => {
it("TODO", () => {
expect(false).toBe(true);
});
});
14 changes: 7 additions & 7 deletions src/types/InspectionPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ type InspectionPreview = {
id: string;
upload_date: string;
updated_at: string;
sample_id: string|null;
picture_set_id: string|null;
sample_id: string | null;
picture_set_id: string | null;
label_info_id: string;
product_name: string|null;
manufacturer_info_id: string|null;
product_name: string | null;
manufacturer_info_id: string | null;
company_info_id: string;
company_name: string|null;
}
export default InspectionPreview;
company_name: string | null;
};
export default InspectionPreview;

0 comments on commit 95b43a1

Please sign in to comment.