Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/next-14.2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
armanmoztar authored Sep 18, 2024
2 parents da1100e + 9f5efd6 commit d1e8dd0
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 82 deletions.
47 changes: 16 additions & 31 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,20 @@ model users {

/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
model applications {
id String @id @db.Uuid
id String @id @db.Uuid
status String?
reviewer_id String? @db.Uuid
reviewer_id String? @db.Uuid
notes String?
created_at DateTime? @default(now()) @db.Timestamptz(6)
created_at DateTime? @default(now()) @db.Timestamptz(6)
meta Json?
level String? @default("unassigned")
interviewer_id String? @db.Uuid
level String? @default("unassigned")
interviewer_id String? @db.Uuid
team_id BigInt?
submissions submissions @relation(fields: [id], references: [id], onDelete: Cascade)
users_applications_interviewer_idTousers users? @relation("applications_interviewer_idTousers", fields: [interviewer_id], references: [id])
users_applications_reviewer_idTousers users? @relation("applications_reviewer_idTousers", fields: [reviewer_id], references: [id], onUpdate: Restrict)
teams teams? @relation(fields: [team_id], references: [id])
pending_members pending_members[]
notified_on DateTime? @db.Timestamptz(6)
submissions submissions @relation(fields: [id], references: [id], onDelete: Cascade)
users_applications_interviewer_idTousers users? @relation("applications_interviewer_idTousers", fields: [interviewer_id], references: [id])
users_applications_reviewer_idTousers users? @relation("applications_reviewer_idTousers", fields: [reviewer_id], references: [id], onUpdate: Restrict)
teams teams? @relation(fields: [team_id], references: [id])
@@schema("public")
}
Expand Down Expand Up @@ -380,20 +380,6 @@ model members {
@@schema("public")
}

/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
model pending_members {
user_id String @db.Uuid
status String?
meta Json?
created_at DateTime? @default(now()) @db.Timestamptz(6)
team_id BigInt
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
applications applications @relation(fields: [user_id], references: [id], onDelete: Cascade, map: "pending_member_id_fkey")
teams teams @relation(fields: [team_id], references: [id], onDelete: Cascade, map: "pending_member_team_id_fkey")
@@schema("public")
}

/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
model roles {
id String @id @db.Uuid
Expand Down Expand Up @@ -448,13 +434,12 @@ model team_role {

/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
model teams {
id BigInt @id @default(autoincrement())
name String @unique
started_at DateTime? @default(now()) @db.Timestamptz(6)
ended_at DateTime? @db.Timestamptz(6)
applications applications[]
pending_members pending_members[]
team_members team_members[]
id BigInt @id @default(autoincrement())
name String @unique
started_at DateTime? @default(now()) @db.Timestamptz(6)
ended_at DateTime? @db.Timestamptz(6)
applications applications[]
team_members team_members[]
@@schema("public")
}
Expand Down
34 changes: 34 additions & 0 deletions src/app/portal/admin/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,28 @@ export async function updateSubmissionField(
}
}

export async function sendStatusEmailToUser(
submissionId: string,
value: string,
) {
const submission = await db.submissions.findFirst({
where: {
id: submissionId,
},
});

if (!submission) {
console.log("Submission not found");
return;
}

await sendStatusEmail({
status: value,
formId: submission.form_id,
userId: submission.user_id,
});
}

export async function getAdminMembers() {
const res = await db.roles.findMany({
where: {
Expand Down Expand Up @@ -276,4 +298,16 @@ async function sendStatusEmail({
html: template,
cc: details?.email as string,
});
if (!app.applications) {
console.log("Application not found");
return;
}
await db.applications.update({
where: {
id: app.applications.id,
},
data: {
notified_on: new Date(),
},
});
}
15 changes: 6 additions & 9 deletions src/app/portal/admin/forms/[id]/submissions/columns.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ColumnDef, Row } from "@tanstack/react-table";
import { useContext, useEffect, useState } from "react";
import MultiSelect from "@/components/general/multiSelect";
import { updateSubmissionField } from "@/app/portal/admin/actions";
import {
sendStatusEmailToUser,
updateSubmissionField,
} from "@/app/portal/admin/actions";
import { toast } from "sonner";
import FloatingTextArea from "@/components/primitives/floatingTextArea";
import { Button } from "@/components/primitives/button";
Expand Down Expand Up @@ -300,13 +303,7 @@ function NotifyButtonForEmail({ row }: { row: any }) {
<button
onClick={async () => {
setEmailState("loading");
await updateSubmissionField(
row.original.id,
"status",
"applications",
row.original.status,
true,
);
await sendStatusEmailToUser(row.original.id, row.original.status);
setEmailState("sent");
}}
className={
Expand All @@ -328,7 +325,7 @@ function NotifyButtonForEmail({ row }: { row: any }) {
{emailState === "idle" && (
<span className={"text-xs flex items-center gap-2"}>
<MailIcon className={"w-3 h-3"} />
Notify via Email
{row.original.notified_on ? "Resend Email" : "Notify via Email"}
</span>
)}
</button>
Expand Down
1 change: 1 addition & 0 deletions src/app/portal/admin/forms/[id]/submissions/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function DataTable<TData, TValue>({
"popover",
"status",
"team_id",
"notified_on",
"level",
"reviewer_id",
"interviewer_id",
Expand Down
2 changes: 1 addition & 1 deletion src/app/portal/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Unauthorized } from "@/components/layouts/inaccessiblePageWrapper";
export default function Layout({ children }: { children: React.ReactNode }) {
const { user, userMetadata } = useContext(userContext);
if (!user) {
redirect("/portal/auth");
redirect("/auth");
}
if (
!userMetadata ||
Expand Down
2 changes: 1 addition & 1 deletion src/app/portal/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default async function Layout({
const { data, error } = await supabase.auth.getUser();

if (!data.user || error) {
redirect("/portal/auth");
redirect("/auth");
}

const userMetadata = await getUserMetadata(data.user.id);
Expand Down
4 changes: 2 additions & 2 deletions src/components/layouts/genericGreeter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export default function GenericGreeter({
/>
</div>
{includeStyle ? (
<div className="text-4xl flex-col flex flex-1 gap-6 w-full overflow-hidden lg:pt-32 justify-center items-center">
<div className="text-4xl flex-col flex flex-1 gap-6 w-full overflow-hidden lg:pt-10 justify-center items-center">
<div
className={
" z-40 border-background-600 h-full overflow-y-scroll max-h-[80svh] p-4 xl:p-10 rounded-xl flex-col w-full flex gap-10 justify-center items-center"
" z-40 border-background-600 h-full overflow-y-scroll max-h-[90svh] p-4 xl:p-10 rounded-xl flex-col w-full flex gap-10 justify-center items-center"
}
>
{children}
Expand Down
81 changes: 43 additions & 38 deletions src/lib/utils/supabase/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,58 @@ export async function updateSession(request: NextRequest) {

let supabaseResponse = NextResponse.next({
request,
// headers,
});

const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return request.cookies.getAll();
},
setAll(cookiesToSet) {
cookiesToSet.forEach(({ name, value }) =>
request.cookies.set(name, value),
);
supabaseResponse = NextResponse.next({
request,
});
cookiesToSet.forEach(({ name, value, options }) =>
supabaseResponse.cookies.set(name, value, options),
);
},
},
},
);

// check origin URL, if the same base URL, allow the request
if (request.nextUrl.origin.startsWith(process.env.NEXT_PUBLIC_BASE_URL!)) {
return supabaseResponse;
}
// // check origin URL, if the same base URL, allow the request
// if (request.nextUrl.origin.startsWith(process.env.NEXT_PUBLIC_BASE_URL!)) {
// return supabaseResponse;
// }

// IMPORTANT: Avoid writing any logic between createServerClient and
// supabase.auth.getUser(). A simple mistake could make it very hard to debug
// issues with users being randomly logged out.

const {
data: { user },
} = await supabase.auth.getUser();
try {
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return request.cookies.getAll();
},
setAll(cookiesToSet) {
cookiesToSet.forEach(({ name, value }) =>
request.cookies.set(name, value),
);
supabaseResponse = NextResponse.next({
request,
});
cookiesToSet.forEach(({ name, value, options }) =>
supabaseResponse.cookies.set(name, value, options),
);
},
},
},
);
const {
data: { user },
} = await supabase.auth.getUser();

if (
!user &&
!request.nextUrl.pathname.startsWith("/login") &&
!request.nextUrl.pathname.startsWith("/auth")
) {
// no user, potentially respond by redirecting the user to the login page
if (
!user &&
!request.nextUrl.pathname.startsWith("/login") &&
!request.nextUrl.pathname.startsWith("/auth")
) {
// no user, potentially respond by redirecting the user to the login page
const url = request.nextUrl.clone();
url.pathname = "/auth";
return NextResponse.redirect(url);
}
} catch (error) {
console.error("Error fetching user", error);
const url = request.nextUrl.clone();
url.pathname = "/auth";
url.pathname = "/";
return NextResponse.redirect(url);
}

Expand Down

0 comments on commit d1e8dd0

Please sign in to comment.