Skip to content

Commit 17f6556

Browse files
authoredMar 29, 2024··
Merge pull request #30 from Team3256/admin-dashboard-fixes
Admin dashboard fixes
2 parents 8674517 + 6f358f8 commit 17f6556

File tree

6 files changed

+142
-242
lines changed

6 files changed

+142
-242
lines changed
 

‎apps/nextjs/src/app/actions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { redirect } from "next/navigation";
66
import { createClient } from "@/lib/utils/supabase/server";
77

88
export async function signup(formData: FormData) {
9-
const supabase = createClient();
9+
const supabase = await createClient();
1010

1111
// type-casting here for convenience
1212
// in practice, you should validate your inputs
+76-76
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,100 @@
11
import { createClient } from "@/lib/utils/supabase/client";
22

33
export async function addAssignment({ match, team, alliance, assignee }) {
4-
const supabase = createClient();
4+
const supabase = createClient();
5+
console.log("sadfsafdfsd");
6+
const { data: profileData, error: profileError } = await supabase
7+
.from("profiles")
8+
.select("id")
9+
.eq("email", assignee)
10+
.single();
511

6-
const { data: profileData, error: profileError } = await supabase
7-
.from("profiles")
8-
.select("id")
9-
.eq("email", assignee)
10-
.single();
12+
const { data, error } = await supabase
13+
.from("assignments")
14+
.upsert([
15+
{
16+
match: match,
17+
team: team,
18+
alliance: alliance,
19+
assignee: profileData?.id,
20+
event_log: {
21+
auto: { log: [], checkboxes: null },
22+
teleop: { log: [], checkboxes: null },
23+
endgame: { log: [], checkboxes: null },
24+
},
25+
},
26+
])
27+
.select();
1128

12-
const { data, error } = await supabase
13-
.from("assignments")
14-
.insert([
15-
{
16-
match: match,
17-
team: team,
18-
alliance: alliance,
19-
assignee: profileData?.id,
20-
event_log: {
21-
auto: { log: [], checkboxes: null },
22-
teleop: { log: [], checkboxes: null },
23-
endgame: { log: [], checkboxes: null },
24-
},
25-
},
26-
])
27-
.select();
28-
29-
if (error) {
30-
console.error("Error: ", error);
31-
} else {
32-
console.log("Data: ", data);
33-
}
29+
if (error) {
30+
console.error("Error: ", error);
31+
} else {
32+
console.log("Data: ", data);
33+
}
3434
}
3535

3636
export async function addEvents({ event }) {
37-
const supabase = createClient();
37+
const supabase = createClient();
3838

39-
const { data, error } = await supabase
40-
.from("events")
41-
.insert([
42-
{
43-
key: event.key,
44-
name: event.name,
45-
},
46-
])
47-
.select();
39+
const { data, error } = await supabase
40+
.from("events")
41+
.insert([
42+
{
43+
key: event.key,
44+
name: event.name,
45+
},
46+
])
47+
.select();
4848

49-
if (error) {
50-
console.error("Error: ", error);
51-
} else {
52-
console.log("Data: ", data);
53-
}
49+
if (error) {
50+
console.error("Error: ", error);
51+
} else {
52+
console.log("Data: ", data);
53+
}
5454
}
5555

5656
export async function addMatches({ match }) {
57-
const supabase = createClient();
57+
const supabase = createClient();
5858

59-
const { data, error } = await supabase
60-
.from("matches")
61-
.insert([
62-
{
63-
key: match.match_key,
64-
event: match.event,
65-
},
66-
])
67-
.select();
59+
const { data, error } = await supabase
60+
.from("matches")
61+
.insert([
62+
{
63+
key: match.match_key,
64+
event: match.event,
65+
},
66+
])
67+
.select();
6868

69-
if (error) {
70-
console.error("Error: ", error);
71-
} else {
72-
console.log("Data: ", data);
73-
}
69+
if (error) {
70+
console.error("Error: ", error);
71+
} else {
72+
console.log("Data: ", data);
73+
}
7474
}
7575

7676
export async function getEmails(
77-
setMembers: (members: { [key: string]: string[] }) => void,
77+
setMembers: (members: { [key: string]: string[] }) => void,
7878
) {
79-
const supabase = createClient();
79+
const supabase = createClient();
8080

81-
// const { data, error } = await supabase.from("users").select("email");
82-
const { data, error } = await supabase.from("profiles").select("email");
81+
// const { data, error } = await supabase.from("users").select("email");
82+
const { data, error } = await supabase.from("profiles").select("email");
8383

84-
if (error) {
85-
console.error("Error: ", error);
86-
} else {
87-
console.log("Data: ", data);
88-
}
84+
if (error) {
85+
console.error("Error: ", error);
86+
} else {
87+
console.log("Data: ", data);
88+
}
8989

90-
const extractedEmails = data.map((obj) => obj.email);
90+
const extractedEmails = data.map((obj) => obj.email);
9191

92-
// Update the state to create an object where each email is a key with an empty array value
93-
setMembers((previousState) => ({
94-
...previousState, // This keeps existing state entries intact
95-
...extractedEmails.reduce((acc, email) => {
96-
acc[email] = [];
97-
return acc;
98-
}, {}),
99-
}));
92+
// Update the state to create an object where each email is a key with an empty array value
93+
setMembers((previousState) => ({
94+
...previousState, // This keeps existing state entries intact
95+
...extractedEmails.reduce((acc, email) => {
96+
acc[email] = [];
97+
return acc;
98+
}, {}),
99+
}));
100100
}

‎apps/nextjs/src/app/signin/actions.ts

+15-16
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@ import { redirect } from "next/navigation";
66
import { createClient } from "@/lib/utils/supabase/server";
77

88
export async function signin(formData: FormData) {
9-
const supabase = createClient();
9+
const supabase = await createClient();
1010

11-
// type-casting here for convenience
12-
// in practice, you should validate your inputs
13-
const data = {
14-
email: formData.get("email") as string,
15-
password: formData.get("password") as string,
16-
};
11+
// type-casting here for convenience
12+
// in practice, you should validate your inputs
13+
const data = {
14+
email: formData.get("email") as string,
15+
password: formData.get("password") as string,
16+
};
1717

18-
const { error } = await supabase.auth.signInWithPassword(data);
19-
console.log("error", error);
20-
if (error) {
21-
// TODO: Form check error
22-
redirect("/error");
23-
}
18+
const { error } = await supabase.auth.signInWithPassword(data);
19+
console.log("error", error);
20+
if (error) {
21+
// TODO: Form check error
22+
redirect("/error");
23+
}
2424

25-
revalidatePath("/", "layout");
26-
redirect("/dashboard");
25+
revalidatePath("/", "layout");
26+
redirect("/dashboard");
2727
}
28-

‎apps/nextjs/src/lib/utils/trpc.ts

+32-47
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ function getBaseUrl() {
99
// browser should use relative path
1010
return "";
1111

12-
if (process.env.VERCEL_URL)
13-
// reference for vercel.com
14-
return `https://${process.env.VERCEL_URL}`;
15-
if (process.env.VERCEL_URL)
16-
// reference for vercel.com
17-
return `https://${process.env.VERCEL_URL}`;
18-
19-
if (process.env.RENDER_INTERNAL_HOSTNAME)
20-
// reference for render.com
21-
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
22-
if (process.env.RENDER_INTERNAL_HOSTNAME)
23-
// reference for render.com
24-
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
25-
26-
// assume localhost
27-
return `http://localhost:${process.env.PORT ?? 3000}`;
28-
// assume localhost
29-
return `http://localhost:${process.env.PORT ?? 3000}`;
12+
if (process.env.VERCEL_URL)
13+
// reference for vercel.com
14+
return `https://${process.env.VERCEL_URL}`;
15+
if (process.env.VERCEL_URL)
16+
// reference for vercel.com
17+
return `https://${process.env.VERCEL_URL}`;
18+
19+
if (process.env.RENDER_INTERNAL_HOSTNAME)
20+
// reference for render.com
21+
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
22+
if (process.env.RENDER_INTERNAL_HOSTNAME)
23+
// reference for render.com
24+
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
25+
26+
// assume localhost
27+
return `http://localhost:${process.env.PORT ?? 3000}`;
28+
// assume localhost
29+
// return `http://localhost:${process.env.PORT ?? 3000}`;
3030
}
3131

3232
export const trpc = createTRPCNext<AppRouter>({
@@ -42,33 +42,18 @@ export const trpc = createTRPCNext<AppRouter>({
4242
**/
4343
url: `${getBaseUrl()}/api/trpc`,
4444

45-
// You can pass any HTTP headers you wish here
46-
async headers() {
47-
return {
48-
// authorization: getAuthCookie(),
49-
};
50-
},
51-
}),
52-
],
53-
};
54-
},
55-
/**
56-
* @link https://trpc.io/docs/v11/ssr
57-
**/
58-
ssr: false,
59-
// You can pass any HTTP headers you wish here
60-
async headers() {
61-
return {
62-
// authorization: getAuthCookie(),
63-
};
64-
},
65-
}),
66-
],
67-
};
68-
},
69-
/**
70-
* @link https://trpc.io/docs/v11/ssr
71-
**/
72-
ssr: false,
45+
// You can pass any HTTP headers you wish here
46+
async headers() {
47+
return {
48+
// authorization: getAuthCookie(),
49+
};
50+
},
51+
}),
52+
],
53+
};
54+
},
55+
/**
56+
* @link https://trpc.io/docs/v11/ssr
57+
**/
58+
ssr: false,
7359
});
74-

‎packages/api/src/router/scouting.ts

+18-33
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import { matches } from "@acme/db/schema";
88
import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc";
99

1010
const UltimateHistory = z.object({
11-
log: z.array(z.tuple([z.number(), z.number()])),
12-
checkboxes: z.optional(z.record(z.boolean())),
11+
log: z.array(z.tuple([z.number(), z.number()])),
12+
checkboxes: z.optional(z.record(z.boolean())),
1313
});
1414

1515
export const eventLog = z.object({
16-
auto: UltimateHistory,
17-
teleop: UltimateHistory,
18-
endgame: UltimateHistory,
16+
auto: UltimateHistory,
17+
teleop: UltimateHistory,
18+
endgame: UltimateHistory,
1919
});
2020
export const scoutingRouter = createTRPCRouter({
2121
// createMatch: publicProcedure.input(z.object({id:z.string({})}))
@@ -96,36 +96,21 @@ export const scoutingRouter = createTRPCRouter({
9696
// events,
9797
// team,
9898

99-
// return ctx.db
100-
// .select()
101-
// .from(matches)
102-
// .where(eq(matches.eventId, input.event))
103-
// .then((matches) => {
99+
// alliance,
100+
// }) => {
101+
//
102+
// return { team: };
103+
// },
104+
// );
104105

105-
// });
106-
}),
106+
// return ctx.db
107+
// .select()
108+
// .from(matches)
109+
// .where(eq(matches.eventId, input.event))
110+
// .then((matches) => {
107111

108-
updateMatchLog: publicProcedure
109-
.input(
110-
z.object({
111-
eventLog,
112-
matchKey: z.string(),
113-
team: z.string(),
114-
}),
115-
)
116-
.mutation(async ({ ctx, input }) => {
117-
const { error } = await ctx.supabase
118-
.from("assigmments")
119-
.update({ event_log: input.eventLog })
120-
.eq("match", input.matchKey)
121-
.eq("team", input.team);
122-
if (error !== null) {
123-
throw new TRPCError({
124-
code: "INTERNAL_SERVER_ERROR",
125-
message: "Error updating match log",
126-
cause: error,
127-
});
128-
}
112+
// });
113+
}),
129114

130115
updateMatchLog: publicProcedure
131116
.input(

‎packages/api/src/router/tba.ts

-69
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { z } from "zod";
55
import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc";
66

77
export const tbaRouter = createTRPCRouter({
8-
<<<<<<< HEAD
98
teamEvents: publicProcedure
109
.input(z.object({ teamKey: z.string() }))
1110
.input(z.object({ year: z.number() }))
@@ -74,72 +73,4 @@ export const tbaRouter = createTRPCRouter({
7473
);
7574
return extractedData2;
7675
}),
77-
=======
78-
teamEvents: publicProcedure
79-
.input(z.object({ teamKey: z.string(), year: z.number() }))
80-
.query(async ({ input }) => {
81-
const response = await axios.get(
82-
`https://www.thebluealliance.com/api/v3/team/${input.teamKey}/events/${input.year}`,
83-
{
84-
headers: {
85-
"X-TBA-Auth-Key":
86-
"5CnvqgQnVEtePAqwFls3PnlxxKFW88o67RAP6zPlZXGtWV6B6Mx7mSkBlfonEp4c",
87-
},
88-
},
89-
);
90-
91-
const extractedData = (
92-
response.data as { event_code: string; key: string }[]
93-
).map((event: { event_code: string; key: string }) => ({
94-
event_code: event.event_code,
95-
key: event.key,
96-
}));
97-
98-
return extractedData as { event_code: string; key: string }[];
99-
}),
100-
eventMatches: publicProcedure
101-
.input(z.object({ teamKey: z.string() }))
102-
.query(async ({ input }) => {
103-
const response = await axios.get(
104-
`https://www.thebluealliance.com/api/v3/event/${input}/matches`,
105-
{
106-
headers: {
107-
"X-TBA-Auth-Key":
108-
"5CnvqgQnVEtePAqwFls3PnlxxKFW88o67RAP6zPlZXGtWV6B6Mx7mSkBlfonEp4c",
109-
},
110-
},
111-
);
112-
const extractedData2 = (
113-
response.data as {
114-
match_number: string;
115-
key: string;
116-
alliances: {
117-
red: { team_keys: [string, string, string] };
118-
blue: { team_keys: [string, string, string] };
119-
};
120-
}[]
121-
).map(
122-
(match: {
123-
match_number: string;
124-
key: string;
125-
alliances: {
126-
red: { team_keys: [string, string, string] };
127-
blue: { team_keys: [string, string, string] };
128-
};
129-
}) => ({
130-
match_num: match.match_number,
131-
match_key: match.key,
132-
alliances: match.alliances,
133-
// predicted_time: match.predicted_time,
134-
}),
135-
);
136-
return extractedData2 as {
137-
match_num: string;
138-
alliances: {
139-
red: { team_keys: [string, string, string] };
140-
blue: { team_keys: [string, string, string] };
141-
};
142-
}[];
143-
}),
144-
>>>>>>> main
14576
});

0 commit comments

Comments
 (0)
Please sign in to comment.