Skip to content

Commit

Permalink
timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
armintalaie committed Sep 18, 2024
1 parent 3ee9a23 commit 0fbdf73
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 40 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

0 comments on commit 0fbdf73

Please sign in to comment.