Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

110 preferred ways of communication #113

Merged
merged 8 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@auth/prisma-adapter": "^1.4.0",
"@hookform/resolvers": "^3.3.4",
"@prisma/client": "^5.10.2",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
Expand Down
35 changes: 26 additions & 9 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ datasource db {
url = env("DATABASE_URL")
}

enum CommunicationMethod {
SLACK
EMAIL
WHATSAPP
SIGNAL
PHONE
TEAMS
}

model Survey {
id String @id @default(cuid())
surveyName String @unique
Expand Down Expand Up @@ -47,16 +56,24 @@ model QuestionResult {
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model CommunicationPreference {
id String @id @default(cuid())
userId String
methods CommunicationMethod[] @default([])
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
roles Role[] @relation("UserRole")
accounts Account[]
questionResults QuestionResult[]
sessions Session[]
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
roles Role[] @relation("UserRole")
accounts Account[]
questionResults QuestionResult[]
communicationPreferences CommunicationPreference[]
sessions Session[]
}

model Account {
Expand Down
40 changes: 37 additions & 3 deletions src/app/find-the-expert/[role]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ const ShowTableWrapper = async () => {
const [users, answerOptions] = await Promise.all([
db.user.findMany({
where: { id: { in: userIds } },
select: { id: true, name: true, email: true },
select: {
id: true,
name: true,
email: true,
communicationPreferences: true,
},
}),
db.answerOption.findMany({
where: { id: { in: answerIds } },
Expand All @@ -78,11 +83,21 @@ const ShowTableWrapper = async () => {
]);

// Create a map of user IDs to user objects for easy lookup
const userMap: Record<string, { name: string; email: string }> = {};
const userMap: Record<
string,
{
name: string;
email: string;
communicationPreferences: string[];
}
> = {};
for (const user of users) {
userMap[user.id] = {
name: user.name ?? "Unknown User",
email: user.email ?? "Unknown Email",
communicationPreferences: user.communicationPreferences.map((method) =>
method.methods.toString(),
),
};
}

Expand Down Expand Up @@ -111,6 +126,10 @@ const ShowTableWrapper = async () => {
dataByRoleAndQuestion[roleName]?.[questionText]?.push({
name: userMap[entry.userId]?.name ?? "Unknown User",
email: userMap[entry.userId]?.email ?? "Unknown Email",
communicationPreferences:
userMap[entry.userId]!.communicationPreferences?.length > 0
? userMap[entry.userId]?.communicationPreferences
: ["Do not contact"],
answer: answerOptionMap[entry.answerId] ?? "Unknown Answer",
});

Expand All @@ -132,7 +151,14 @@ const ShowTableWrapper = async () => {

const aggregatedDataByRole: Record<
string,
Record<string, { name: string; counts: number[] }>
Record<
string,
{
name: string;
communicationPreferences: string[];
counts: number[];
}
>
> = {};

for (const entry of userAnswersForRole) {
Expand All @@ -147,10 +173,18 @@ const ShowTableWrapper = async () => {
const answerValue = parseInt(answerOptionMap[entry.answerId] ?? "", 10);
const userName = userMap[entry.userId]?.name ?? "Unknown User";
const userEmail = userMap[entry.userId]?.email ?? "Unknown Email";
let userCommunicationPreferences =
userMap[entry.userId]?.communicationPreferences;
// Check if communicationPreferences is empty
userCommunicationPreferences =
userCommunicationPreferences?.length ?? 0 > 0
? userCommunicationPreferences
: ["Do not contact"] ?? [];
if (!isNaN(answerValue)) {
if (!aggregatedDataByRole[roleName]?.[userEmail]) {
aggregatedDataByRole[roleName]![userEmail] = {
name: userName,
communicationPreferences: userCommunicationPreferences ?? [],
counts: [0, 0, 0, 0],
};
}
Expand Down
10 changes: 10 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export default async function RootLayout({
<ModeToggle />
</div>
{children}
<div className="text-center">
<p className="text-md mb-8">
Your privacy is important to us. We invite you to read our{" "}
<Link className="underline" href={"/privacy"}>
Privacy Statement
</Link>{" "}
to understand how we protect and handle your personal
information.
</p>
</div>
</main>
</TRPCReactProvider>
<Toaster />
Expand Down
22 changes: 18 additions & 4 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ const Home: React.FC = async () => {
</ol>
</div>
<p className="mb-8 text-lg ">
Join us in leveraging the collective expertise of Info Support
to drive innovation and excellence in technology solutions.
We appreciate your willingness to share your expertise with us.
Please be aware that the information you provide regarding your
technical skills will be <strong>visible to colleagues</strong>{" "}
for the three goals described above.
</p>
</div>
{/* If the user is logged in, show the SelectRole component */}
Expand All @@ -122,11 +124,10 @@ const Home: React.FC = async () => {
);
};

// Define a separate component to encapsulate the SelectRole component and database calls
const SelectRoleWrapper: React.FC<{ session: Session }> = async ({
session,
}) => {
const [roles, userRoles] = await Promise.all([
const [roles, userRoles, userCommunicationMethods] = await Promise.all([
db.role.findMany(),
db.user.findUnique({
where: {
Expand All @@ -136,15 +137,28 @@ const SelectRoleWrapper: React.FC<{ session: Session }> = async ({
roles: true,
},
}),
db.user.findUnique({
where: {
id: session.user.id,
},
include: {
communicationPreferences: true,
},
}),
]);

const userSelectedRoles = userRoles?.roles ?? [];
const communicationPreferences =
userCommunicationMethods?.communicationPreferences ?? [];
const methods = communicationPreferences.map((method) => method.methods);
const methodStrings = methods.map((method) => method.toString());

return (
<SelectRole
session={session}
roles={roles}
userSelectedRoles={userSelectedRoles}
methods={methodStrings}
/>
);
};
Expand Down
Loading