[go: nahoru, domu]

Skip to content

Commit

Permalink
fuxed bib fybctuib
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatXliner committed Mar 2, 2024
1 parent c2212ad commit fa96aa8
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 234 deletions.
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");
}

Loading

0 comments on commit fa96aa8

Please sign in to comment.