[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request #30 from Team3256/admin-dashboard-fixes
Browse files Browse the repository at this point in the history
Admin dashboard fixes
  • Loading branch information
DragonXDev committed Mar 29, 2024
2 parents 8674517 + 6f358f8 commit 17f6556
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 242 deletions.
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { redirect } from "next/navigation";
import { createClient } from "@/lib/utils/supabase/server";

export async function signup(formData: FormData) {
const supabase = createClient();
const supabase = await createClient();

// type-casting here for convenience
// in practice, you should validate your inputs
Expand Down
152 changes: 76 additions & 76 deletions apps/nextjs/src/app/dashboard/actions.ts
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
import { createClient } from "@/lib/utils/supabase/client";

export async function addAssignment({ match, team, alliance, assignee }) {
const supabase = createClient();
const supabase = createClient();
console.log("sadfsafdfsd");
const { data: profileData, error: profileError } = await supabase
.from("profiles")
.select("id")
.eq("email", assignee)
.single();

const { data: profileData, error: profileError } = await supabase
.from("profiles")
.select("id")
.eq("email", assignee)
.single();
const { data, error } = await supabase
.from("assignments")
.upsert([
{
match: match,
team: team,
alliance: alliance,
assignee: profileData?.id,
event_log: {
auto: { log: [], checkboxes: null },
teleop: { log: [], checkboxes: null },
endgame: { log: [], checkboxes: null },
},
},
])
.select();

const { data, error } = await supabase
.from("assignments")
.insert([
{
match: match,
team: team,
alliance: alliance,
assignee: profileData?.id,
event_log: {
auto: { log: [], checkboxes: null },
teleop: { log: [], checkboxes: null },
endgame: { log: [], checkboxes: null },
},
},
])
.select();

if (error) {
console.error("Error: ", error);
} else {
console.log("Data: ", data);
}
if (error) {
console.error("Error: ", error);
} else {
console.log("Data: ", data);
}
}

export async function addEvents({ event }) {
const supabase = createClient();
const supabase = createClient();

const { data, error } = await supabase
.from("events")
.insert([
{
key: event.key,
name: event.name,
},
])
.select();
const { data, error } = await supabase
.from("events")
.insert([
{
key: event.key,
name: event.name,
},
])
.select();

if (error) {
console.error("Error: ", error);
} else {
console.log("Data: ", data);
}
if (error) {
console.error("Error: ", error);
} else {
console.log("Data: ", data);
}
}

export async function addMatches({ match }) {
const supabase = createClient();
const supabase = createClient();

const { data, error } = await supabase
.from("matches")
.insert([
{
key: match.match_key,
event: match.event,
},
])
.select();
const { data, error } = await supabase
.from("matches")
.insert([
{
key: match.match_key,
event: match.event,
},
])
.select();

if (error) {
console.error("Error: ", error);
} else {
console.log("Data: ", data);
}
if (error) {
console.error("Error: ", error);
} else {
console.log("Data: ", data);
}
}

export async function getEmails(
setMembers: (members: { [key: string]: string[] }) => void,
setMembers: (members: { [key: string]: string[] }) => void,
) {
const supabase = createClient();
const supabase = createClient();

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

if (error) {
console.error("Error: ", error);
} else {
console.log("Data: ", data);
}
if (error) {
console.error("Error: ", error);
} else {
console.log("Data: ", data);
}

const extractedEmails = data.map((obj) => obj.email);
const extractedEmails = data.map((obj) => obj.email);

// Update the state to create an object where each email is a key with an empty array value
setMembers((previousState) => ({
...previousState, // This keeps existing state entries intact
...extractedEmails.reduce((acc, email) => {
acc[email] = [];
return acc;
}, {}),
}));
// Update the state to create an object where each email is a key with an empty array value
setMembers((previousState) => ({
...previousState, // This keeps existing state entries intact
...extractedEmails.reduce((acc, email) => {
acc[email] = [];
return acc;
}, {}),
}));
}
31 changes: 15 additions & 16 deletions apps/nextjs/src/app/signin/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ import { redirect } from "next/navigation";
import { createClient } from "@/lib/utils/supabase/server";

export async function signin(formData: FormData) {
const supabase = createClient();
const supabase = await createClient();

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

const { error } = await supabase.auth.signInWithPassword(data);
console.log("error", error);
if (error) {
// TODO: Form check error
redirect("/error");
}
const { error } = await supabase.auth.signInWithPassword(data);
console.log("error", error);
if (error) {
// TODO: Form check error
redirect("/error");
}

revalidatePath("/", "layout");
redirect("/dashboard");
revalidatePath("/", "layout");
redirect("/dashboard");
}

79 changes: 32 additions & 47 deletions apps/nextjs/src/lib/utils/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ function getBaseUrl() {
// browser should use relative path
return "";

if (process.env.VERCEL_URL)
// reference for vercel.com
return `https://${process.env.VERCEL_URL}`;
if (process.env.VERCEL_URL)
// reference for vercel.com
return `https://${process.env.VERCEL_URL}`;

if (process.env.RENDER_INTERNAL_HOSTNAME)
// reference for render.com
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
if (process.env.RENDER_INTERNAL_HOSTNAME)
// reference for render.com
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;

// assume localhost
return `http://localhost:${process.env.PORT ?? 3000}`;
// assume localhost
return `http://localhost:${process.env.PORT ?? 3000}`;
if (process.env.VERCEL_URL)
// reference for vercel.com
return `https://${process.env.VERCEL_URL}`;
if (process.env.VERCEL_URL)
// reference for vercel.com
return `https://${process.env.VERCEL_URL}`;

if (process.env.RENDER_INTERNAL_HOSTNAME)
// reference for render.com
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
if (process.env.RENDER_INTERNAL_HOSTNAME)
// reference for render.com
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;

// assume localhost
return `http://localhost:${process.env.PORT ?? 3000}`;
// assume localhost
// return `http://localhost:${process.env.PORT ?? 3000}`;
}

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

// You can pass any HTTP headers you wish here
async headers() {
return {
// authorization: getAuthCookie(),
};
},
}),
],
};
},
/**
* @link https://trpc.io/docs/v11/ssr
**/
ssr: false,
// You can pass any HTTP headers you wish here
async headers() {
return {
// authorization: getAuthCookie(),
};
},
}),
],
};
},
/**
* @link https://trpc.io/docs/v11/ssr
**/
ssr: false,
// You can pass any HTTP headers you wish here
async headers() {
return {
// authorization: getAuthCookie(),
};
},
}),
],
};
},
/**
* @link https://trpc.io/docs/v11/ssr
**/
ssr: false,
});

51 changes: 18 additions & 33 deletions packages/api/src/router/scouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { matches } from "@acme/db/schema";
import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc";

const UltimateHistory = z.object({
log: z.array(z.tuple([z.number(), z.number()])),
checkboxes: z.optional(z.record(z.boolean())),
log: z.array(z.tuple([z.number(), z.number()])),
checkboxes: z.optional(z.record(z.boolean())),
});

export const eventLog = z.object({
auto: UltimateHistory,
teleop: UltimateHistory,
endgame: UltimateHistory,
auto: UltimateHistory,
teleop: UltimateHistory,
endgame: UltimateHistory,
});
export const scoutingRouter = createTRPCRouter({
// createMatch: publicProcedure.input(z.object({id:z.string({})}))
Expand Down Expand Up @@ -96,36 +96,21 @@ export const scoutingRouter = createTRPCRouter({
// events,
// team,

// return ctx.db
// .select()
// .from(matches)
// .where(eq(matches.eventId, input.event))
// .then((matches) => {
// alliance,
// }) => {
//
// return { team: };
// },
// );

// });
}),
// return ctx.db
// .select()
// .from(matches)
// .where(eq(matches.eventId, input.event))
// .then((matches) => {

updateMatchLog: publicProcedure
.input(
z.object({
eventLog,
matchKey: z.string(),
team: z.string(),
}),
)
.mutation(async ({ ctx, input }) => {
const { error } = await ctx.supabase
.from("assigmments")
.update({ event_log: input.eventLog })
.eq("match", input.matchKey)
.eq("team", input.team);
if (error !== null) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Error updating match log",
cause: error,
});
}
// });
}),

updateMatchLog: publicProcedure
.input(
Expand Down
Loading

0 comments on commit 17f6556

Please sign in to comment.