mirror of
https://github.com/lemeow125/Borrowing-TrackerFrontend.git
synced 2024-11-17 06:19:27 +08:00
Added clearance status to drawer for students
This commit is contained in:
parent
9747166f49
commit
86bb9d549b
3 changed files with 96 additions and 1 deletions
|
@ -19,6 +19,7 @@ import {
|
||||||
TransactionListType,
|
TransactionListType,
|
||||||
TransactionUpdateType,
|
TransactionUpdateType,
|
||||||
TransactionType,
|
TransactionType,
|
||||||
|
ClearanceType,
|
||||||
} from "../Types/Types";
|
} from "../Types/Types";
|
||||||
|
|
||||||
const debug = true;
|
const debug = true;
|
||||||
|
@ -184,6 +185,18 @@ export function ResetPasswordConfirmAPI(info: ResetPasswordConfirmType) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function ClearanceAPI() {
|
||||||
|
const config = await GetConfig();
|
||||||
|
return instance
|
||||||
|
.get("api/v1/accounts/clearance/", config)
|
||||||
|
.then((response) => {
|
||||||
|
return response.data as ClearanceType;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
console.log("Error retrieving clearance status for user");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Equipment APIs
|
// Equipment APIs
|
||||||
|
|
||||||
export async function EquipmentAPI(id: number) {
|
export async function EquipmentAPI(id: number) {
|
||||||
|
|
|
@ -3,7 +3,12 @@ import AccountCircleIcon from "@mui/icons-material/AccountCircle";
|
||||||
import HomeIcon from "@mui/icons-material/Home";
|
import HomeIcon from "@mui/icons-material/Home";
|
||||||
import LogoutIcon from "@mui/icons-material/Logout";
|
import LogoutIcon from "@mui/icons-material/Logout";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { UserAPI, setAccessToken, setRefreshToken } from "../API/API";
|
import {
|
||||||
|
ClearanceAPI,
|
||||||
|
UserAPI,
|
||||||
|
setAccessToken,
|
||||||
|
setRefreshToken,
|
||||||
|
} from "../API/API";
|
||||||
import DrawerButton from "../DrawerButton/DrawerButton";
|
import DrawerButton from "../DrawerButton/DrawerButton";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { auth_toggle } from "../Plugins/Redux/Slices/AuthSlice/AuthSlice";
|
import { auth_toggle } from "../Plugins/Redux/Slices/AuthSlice/AuthSlice";
|
||||||
|
@ -11,6 +16,12 @@ import { toast } from "react-toastify";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
export default function Drawer() {
|
export default function Drawer() {
|
||||||
const user = useQuery({ queryKey: ["user"], queryFn: UserAPI });
|
const user = useQuery({ queryKey: ["user"], queryFn: UserAPI });
|
||||||
|
const clearance = useQuery({
|
||||||
|
enabled:
|
||||||
|
user.isFetched && !user?.data?.is_teacher && !user?.data?.is_technician,
|
||||||
|
queryKey: ["clearance"],
|
||||||
|
queryFn: ClearanceAPI,
|
||||||
|
});
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
return (
|
return (
|
||||||
|
@ -62,6 +73,72 @@ export default function Drawer() {
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{user.isFetched &&
|
||||||
|
user.data &&
|
||||||
|
!user.data.is_teacher &&
|
||||||
|
!user?.data?.is_technician ? (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
backgroundColor: "white",
|
||||||
|
marginTop: "16px",
|
||||||
|
width: "100%",
|
||||||
|
height: "2px",
|
||||||
|
marginBottom: 8,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div style={styles.flex_row}>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
...styles.text_light,
|
||||||
|
...styles.text_M,
|
||||||
|
...{
|
||||||
|
textAlign: "left",
|
||||||
|
paddingLeft: "8px",
|
||||||
|
},
|
||||||
|
margin: 0,
|
||||||
|
alignSelf: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Status:
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
...styles.text_light,
|
||||||
|
...styles.text_M,
|
||||||
|
...{
|
||||||
|
textAlign: "left",
|
||||||
|
paddingLeft: "8px",
|
||||||
|
color:
|
||||||
|
clearance.data?.cleared === "Cleared"
|
||||||
|
? colors.green
|
||||||
|
: colors.red,
|
||||||
|
margin: 0,
|
||||||
|
alignSelf: "center",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{clearance.data?.cleared}
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
...styles.text_light,
|
||||||
|
...styles.text_S,
|
||||||
|
...{
|
||||||
|
textAlign: "left",
|
||||||
|
paddingLeft: "8px",
|
||||||
|
},
|
||||||
|
margin: 0,
|
||||||
|
alignSelf: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{`(${clearance.data?.uncleared_transactions} pending)`}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
|
|
@ -130,3 +130,8 @@ export type TransactionListType = Array<TransactionType>;
|
||||||
export type TransactionUpdateType = {
|
export type TransactionUpdateType = {
|
||||||
transaction_status: string;
|
transaction_status: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ClearanceType = {
|
||||||
|
cleared: string;
|
||||||
|
uncleared_transactions: number;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue