diff --git a/src/App.tsx b/src/App.tsx
index 6390173..dbfbdf7 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -6,6 +6,7 @@ import Login from "./pages/login"
import Apply from "./pages/apply"
import { useEffect, useState } from "react"
import { supabase, SessionContext } from "./supabase"
+import Book from "./pages/book"
const router = createBrowserRouter(
createRoutesFromElements(
@@ -13,7 +14,8 @@ const router = createBrowserRouter(
}>
} />
} />
- }/>
+ } />
+ } />
>
)
@@ -27,7 +29,7 @@ export default function App() {
useEffect(() => {
// supabase.auth.getSession().then(({ data: { session } }) => setSession(session))
- supabase.auth.onAuthStateChange((_event, session) => { setSession(session);} )
+ supabase.auth.onAuthStateChange((_event, session) => { setSession(session); console.log(_event, session)} )
}, [])
return (
diff --git a/src/components/navbar.tsx b/src/components/navbar.tsx
index 0e25ced..9e34f4d 100644
--- a/src/components/navbar.tsx
+++ b/src/components/navbar.tsx
@@ -28,7 +28,7 @@ export default function NavBar() {
Home
- Apply
+ Book
{session !== null ? (
- ) : null}
+ ) : (
+ Log In
+ )}
diff --git a/src/pages/apply.tsx b/src/pages/apply.tsx
index 13cef89..581976b 100644
--- a/src/pages/apply.tsx
+++ b/src/pages/apply.tsx
@@ -13,7 +13,7 @@ import { useNavigate } from "react-router-dom";
import { rec_open } from ".";
// import { useEffect, useRef } from 'react';
-const departments = {
+export const departments = {
management: "Management",
mms: "Marketing and Sponsorhips",
cont: "Content",
@@ -310,6 +310,7 @@ export default function Apply() {
const [sig, setSig] = useState(0);
useEffect(() => {
+ // alert(session)
if (session === null) {
navigate("/auth");
return;
diff --git a/src/pages/book.tsx b/src/pages/book.tsx
new file mode 100644
index 0000000..0831039
--- /dev/null
+++ b/src/pages/book.tsx
@@ -0,0 +1,236 @@
+import { ErrorMessage, Field, Form, Formik } from "formik";
+import { createContext, Fragment, useContext, useEffect, useState } from "react";
+import { Navigate } from "react-router-dom";
+import { SessionContext, supabase } from "../supabase";
+import { departments } from "./apply";
+import "./apply.scss";
+import "./mainbg.scss";
+
+
+const CountContext = createContext(0);
+
+// const released: Set = new Set(["cont", "mms"]);
+
+interface App {
+ id: number;
+ dep: string;
+ slot: number | null;
+ shortlisted: boolean;
+};
+
+interface Slot {
+ capacity: number;
+ dep: string;
+ id: number;
+ timing: string;
+};
+
+function SlotSelect({ap, rawSlots}: {ap: App, rawSlots: Slot[]}) {
+ const slots = rawSlots.filter((slot) => {
+ return slot.dep === ap.dep && slot.capacity > 0;
+ });
+
+ if (ap.slot !== null) {
+ const k = rawSlots.find((sl) => sl.id === ap.slot)
+ return (
+ Your slot has been booked for {k!.timing}
+ )
+ }
+
+ if (ap.shortlisted === false) {
+ if (rawSlots.find((slot) => slot.dep === ap.dep) === undefined) return (
+ We are yet to release the result for this department
+ )
+ else return (
+ Unfortunately you weren't shortlisted
+ )
+ }
+
+ if (slots.length === 0) {
+ if (rawSlots.find((slot) => slot.dep === ap.dep) !== undefined) return (
+ No slots left, please contact us.
+ )
+ else return (
+ You were shortlisted, check back later to book your slot
+ )
+ }
+
+ return (
+
+
+ {
+ slots.map(
+ (slot, idx) => (
+
+ )
+ )
+ }
+
+ )
+}
+
+function onSumbitFactory(
+ sig: number,
+ setSig: (arg0: number) => any,
+ app: {
+ id: number;
+ dep: string;
+ slot: number | null;
+ shortlisted: boolean;
+ }[]
+) {
+ async function onSubmit(values: any, formikBag: any) {
+ const promises = Object.entries(values.slots).filter((ent) => ent[1] != "none").map((v) => ({
+ slot_id: parseInt(v[1] as string),
+ applicant: parseInt(v[0]),
+ })).map(
+ (args) => supabase.rpc("bookslot", args).then(
+ (resp) => {
+ console.log(args, resp)
+ if (resp.error !== null) {
+ alert(`Something while booking your slot for \
+${departments[(app.find((a) => a.id === args.applicant)?.dep as unknown) as (keyof typeof departments)]} \
+${resp.error.code} ${resp.error.message}`);
+ console.log(resp, values);
+ }
+ if (resp.data === false) {
+ alert(`Could not book your slot for ${departments[(app.find((a) => a.id === args.applicant)?.dep as unknown) as (keyof typeof departments)]}. Try again`);
+ }
+ }
+ )
+ )
+
+ await Promise.all(promises)
+
+ setSig(sig + 1);
+ Object.keys(values.slots).forEach((sl) => values.slots[sl] = "none");
+ formikBag.resetForm({ values: values });
+
+ }
+ return onSubmit;
+}
+
+export default function Book() {
+ const session = useContext(SessionContext);
+ const [_app, setApp] = useState([])
+
+ // const app = _app.filter((ap) => ap.slot === null && ap.shortlisted === true)
+ const app = _app;
+
+ const [rawSlots, setRawSlots] = useState([])
+
+ const count = app.length;
+
+ const [loaded, setLoaded] = useState(false);
+
+ const [sig, setSig] = useState(0);
+
+ useEffect(() => {
+ if (session === null) return
+ // This stuff should be in a loader
+ supabase
+ .from("applicants")
+ .select("id,dep,slot,shortlisted")
+ .eq("email", session!.user!.email!)
+ .then((records) => {
+ setApp(records.data || [])
+ setLoaded(true);
+ });
+
+ supabase
+ .from("slots")
+ .select()
+ .order("id", {ascending: true})
+ .then((records) => {
+ setRawSlots(records.data || [])
+ })
+
+ }, [session?.user?.email, sig]);
+
+ if (session === null) return // make a protected layout
+
+ // useEffect(() => {
+ // supabase
+ // .from("slots")
+ // .select()
+ // .then((records) => {
+ // setRawSlots(records.data || [])
+ // })
+
+ // }, [sig])
+ const islots: any = {}
+ app.forEach((ap) => islots[ap.id] = "none");
+
+ return (
+
+
+
+ {loaded === false ? "Loading, give us a second" : (session !== null ? (
+
+ {count !== 0 ? (
+
{
+ if (Object.values(values.slots).filter((v) => v !== "none").length === 0) return {slots: "Please select atleast one slot for booking"}
+ return {}
+ }}
+ >
+ {
+ ({isSubmitting, isValidating}) => (
+
+ )
+ }
+
+ ) : (
+
+ It seems like you haven't applied. You can't participate in the interviews.
+
+ )}
+
+ ) : (
+
+ Not logged in
+
+ ))}
+
+
+
+ );
+ }
\ No newline at end of file
diff --git a/src/pages/login.tsx b/src/pages/login.tsx
index 8109488..fc94cb4 100644
--- a/src/pages/login.tsx
+++ b/src/pages/login.tsx
@@ -20,7 +20,8 @@ export default function Login() {
useEffect(() => {
if (session !== null) {
- navigate("/apply");
+ // navigate("/apply");
+ navigate("/book");
}
})
diff --git a/src/supabase.types.ts b/src/supabase.types.ts
index b6c2cf3..f96d102 100644
--- a/src/supabase.types.ts
+++ b/src/supabase.types.ts
@@ -11,32 +11,38 @@ export type Database = {
Tables: {
applicants: {
Row: {
- contact: string | null
+ contact: string
created_at: string
dep: string
email: string
formdata: Json
id: number
+ name: string
+ regno: string
shortlisted: boolean
slot: number | null
}
Insert: {
- contact?: string | null
+ contact?: string
created_at?: string
dep: string
- email: string
+ email?: string
formdata?: Json
id?: number
+ name?: string
+ regno?: string
shortlisted?: boolean
slot?: number | null
}
Update: {
- contact?: string | null
+ contact?: string
created_at?: string
dep?: string
email?: string
formdata?: Json
id?: number
+ name?: string
+ regno?: string
shortlisted?: boolean
slot?: number | null
}
@@ -50,27 +56,54 @@ export type Database = {
},
]
}
+ bookedpvt: {
+ Row: {
+ contact: string | null
+ dep: string | null
+ email: string | null
+ id: number
+ name: string | null
+ regno: string | null
+ timing: string | null
+ }
+ Insert: {
+ contact?: string | null
+ dep?: string | null
+ email?: string | null
+ id?: number
+ name?: string | null
+ regno?: string | null
+ timing?: string | null
+ }
+ Update: {
+ contact?: string | null
+ dep?: string | null
+ email?: string | null
+ id?: number
+ name?: string | null
+ regno?: string | null
+ timing?: string | null
+ }
+ Relationships: []
+ }
slots: {
Row: {
capacity: number
dep: string
id: number
- length: number
- start: string
+ timing: string
}
Insert: {
capacity?: number
dep: string
id?: number
- length?: number
- start: string
+ timing: string
}
Update: {
capacity?: number
dep?: string
id?: number
- length?: number
- start?: string
+ timing?: string
}
Relationships: []
}
@@ -79,7 +112,13 @@ export type Database = {
[_ in never]: never
}
Functions: {
- [_ in never]: never
+ bookslot: {
+ Args: {
+ slot_id: number
+ applicant: number
+ }
+ Returns: boolean
+ }
}
Enums: {
[_ in never]: never