forked from MildTomato/supabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.js
63 lines (56 loc) · 1.94 KB
/
manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { useContext, useEffect, useState } from "react";
import { AppContext } from "lib/constants";
import { supabase } from "lib/api";
import styles from "styles/Map.module.css";
import dynamic from "next/dynamic";
import SignIn from "components/SignIn";
import PageLayout from "components/PageLayout";
const MapView = dynamic(() => import("components/MapView"), { ssr: false });
const center = {
lat: 1.3489728457596013,
lng: 103.77043978311998,
};
const zoomLevel = 12;
export default function Page() {
const { session } = useContext(AppContext);
const [userRole, setRole] = useState(null);
const [username, setUsername] = useState(null);
useEffect(() => {
setRole(session?.user?.user_metadata?.role);
setUsername(session?.user?.user_metadata?.username);
}, [session]);
async function onSignOut() {
const { error } = await supabase.auth.signOut();
if (error) console.log("Error logging out:", error.message);
}
return (
<PageLayout title="Manager View">
<h1 className={styles.title}>Manager View</h1>
<p className={styles.description}>
As manager, you can view all drivers' locations as long as the drivers
are ONLINE
</p>
<div className={styles.grid}>
{!session && <SignIn role="MANAGER" />}
{session && (
<div className={styles.card}>
{userRole?.toUpperCase() == "MANAGER" && (
<MapView center={center} zoom={zoomLevel} />
)}
{userRole?.toUpperCase() == "DRIVER" && (
<p className={styles.error}>
Sorry, you need to sign in as manager
</p>
)}
<div className={styles.profile_container}>
Signed in as {username} [{userRole}]<br />
<button className={styles.sign_out} onClick={onSignOut}>
Sign out
</button>
</div>
</div>
)}
</div>
</PageLayout>
);
}