-
+ {
+ createQuestion({
+ company: data.company,
+ content: data.questionContent,
+ location: data.location,
+ questionType: data.questionType,
+ seenAt: data.date,
+ });
+ }}
+ />
- {Array.from({ length: 10 }).map((_, index) => (
+ {(questions ?? []).map((question) => (
))}
diff --git a/apps/portal/src/server/router/questions-answer-comment-router.ts b/apps/portal/src/server/router/questions-answer-comment-router.ts
index b4578cc5..51d17d34 100644
--- a/apps/portal/src/server/router/questions-answer-comment-router.ts
+++ b/apps/portal/src/server/router/questions-answer-comment-router.ts
@@ -12,57 +12,52 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
answerId: z.string(),
}),
async resolve({ ctx, input }) {
- const questionAnswerCommentsData = await ctx.prisma.questionsAnswerComment.findMany({
- include: {
- user: {
- select: {
- name: true,
+ const questionAnswerCommentsData =
+ await ctx.prisma.questionsAnswerComment.findMany({
+ include: {
+ user: {
+ select: {
+ name: true,
+ },
+ },
+ votes: true,
},
- },
- votes: true,
- },
- orderBy: {
- createdAt: 'desc',
- },
- where: {
- ...input,
- },
- });
- return questionAnswerCommentsData.map((data) => {
- const votes:number = data.votes.reduce(
- (previousValue:number, currentValue) => {
- let result:number = previousValue;
-
- switch(currentValue.vote) {
- case Vote.UPVOTE:
- result += 1
- break;
- case Vote.DOWNVOTE:
- result -= 1
- break;
- }
- return result;
- },
- 0
+ orderBy: {
+ createdAt: 'desc',
+ },
+ where: {
+ ...input,
+ },
+ });
+ return questionAnswerCommentsData.map((data) => {
+ const votes: number = data.votes.reduce(
+ (previousValue: number, currentValue) => {
+ let result: number = previousValue;
+
+ switch (currentValue.vote) {
+ case Vote.UPVOTE:
+ result += 1;
+ break;
+ case Vote.DOWNVOTE:
+ result -= 1;
+ break;
+ }
+ return result;
+ },
+ 0,
);
- let userName = "";
-
- if (data.user) {
- userName = data.user.name!;
- }
-
-
- const answerComment: AnswerComment = {
- content: data.content,
- id: data.id,
- numVotes: votes,
- updatedAt: data.updatedAt,
- user: userName,
- };
- return answerComment;
- });
- }
+ const answerComment: AnswerComment = {
+ content: data.content,
+ createdAt: data.createdAt,
+ id: data.id,
+ numVotes: votes,
+ updatedAt: data.updatedAt,
+ user: data.user?.name ?? '',
+ };
+ return answerComment;
+ });
+ },
})
.mutation('create', {
input: z.object({
@@ -88,11 +83,12 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const answerCommentToUpdate = await ctx.prisma.questionsAnswerComment.findUnique({
- where: {
- id: input.id,
- },
- });
+ const answerCommentToUpdate =
+ await ctx.prisma.questionsAnswerComment.findUnique({
+ where: {
+ id: input.id,
+ },
+ });
if (answerCommentToUpdate?.id !== userId) {
throw new TRPCError({
@@ -118,11 +114,12 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const answerCommentToDelete = await ctx.prisma.questionsAnswerComment.findUnique({
- where: {
- id: input.id,
- },
- });
+ const answerCommentToDelete =
+ await ctx.prisma.questionsAnswerComment.findUnique({
+ where: {
+ id: input.id,
+ },
+ });
if (answerCommentToDelete?.id !== userId) {
throw new TRPCError({
@@ -144,11 +141,11 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const {answerCommentId} = input
+ const { answerCommentId } = input;
return await ctx.prisma.questionsAnswerCommentVote.findUnique({
where: {
- answerCommentId_userId : {answerCommentId,userId },
+ answerCommentId_userId: { answerCommentId, userId },
},
});
},
@@ -176,13 +173,14 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const {id, vote} = input
+ const { id, vote } = input;
- const voteToUpdate = await ctx.prisma.questionsAnswerCommentVote.findUnique({
- where: {
- id: input.id,
- },
- });
+ const voteToUpdate =
+ await ctx.prisma.questionsAnswerCommentVote.findUnique({
+ where: {
+ id: input.id,
+ },
+ });
if (voteToUpdate?.id !== userId) {
throw new TRPCError({
@@ -208,10 +206,12 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const voteToDelete = await ctx.prisma.questionsAnswerCommentVote.findUnique({
- where: {
- id: input.id,
- },});
+ const voteToDelete =
+ await ctx.prisma.questionsAnswerCommentVote.findUnique({
+ where: {
+ id: input.id,
+ },
+ });
if (voteToDelete?.id !== userId) {
throw new TRPCError({
@@ -226,4 +226,4 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
},
});
},
- });
\ No newline at end of file
+ });
diff --git a/apps/portal/src/server/router/questions-answer-router.ts b/apps/portal/src/server/router/questions-answer-router.ts
index 61a5b6c5..21095bf7 100644
--- a/apps/portal/src/server/router/questions-answer-router.ts
+++ b/apps/portal/src/server/router/questions-answer-router.ts
@@ -14,17 +14,17 @@ export const questionsAnswerRouter = createProtectedRouter()
async resolve({ ctx, input }) {
const answersData = await ctx.prisma.questionsAnswer.findMany({
include: {
- _count: {
- select: {
- comments: true,
+ _count: {
+ select: {
+ comments: true,
+ },
},
- },
- user: {
- select: {
- name: true,
+ user: {
+ select: {
+ name: true,
+ },
},
- },
- votes: true,
+ votes: true,
},
orderBy: {
createdAt: 'desc',
@@ -32,43 +32,93 @@ export const questionsAnswerRouter = createProtectedRouter()
where: {
...input,
},
- });
- return answersData.map((data) => {
- const votes:number = data.votes.reduce(
- (previousValue:number, currentValue) => {
- let result:number = previousValue;
-
- switch(currentValue.vote) {
- case Vote.UPVOTE:
- result += 1
- break;
- case Vote.DOWNVOTE:
- result -= 1
- break;
- }
- return result;
- },
- 0
- );
+ });
+ return answersData.map((data) => {
+ const votes: number = data.votes.reduce(
+ (previousValue: number, currentValue) => {
+ let result: number = previousValue;
- let userName = "";
+ switch (currentValue.vote) {
+ case Vote.UPVOTE:
+ result += 1;
+ break;
+ case Vote.DOWNVOTE:
+ result -= 1;
+ break;
+ }
+ return result;
+ },
+ 0,
+ );
- if (data.user) {
- userName = data.user.name!;
+ const answer: Answer = {
+ content: data.content,
+ createdAt: data.createdAt,
+ id: data.id,
+ numComments: data._count.comments,
+ numVotes: votes,
+ user: data.user?.name ?? '',
+ };
+ return answer;
+ });
+ },
+ })
+ .query('getAnswerById', {
+ input: z.object({
+ answerId: z.string(),
+ }),
+ async resolve({ ctx, input }) {
+ const answerData = await ctx.prisma.questionsAnswer.findUnique({
+ include: {
+ _count: {
+ select: {
+ comments: true,
+ },
+ },
+ user: {
+ select: {
+ name: true,
+ },
+ },
+ votes: true,
+ },
+ where: {
+ id: input.answerId,
+ },
+ });
+ if (!answerData) {
+ throw new TRPCError({
+ code: 'NOT_FOUND',
+ message: 'Answer not found',
+ });
}
+ const votes: number = answerData.votes.reduce(
+ (previousValue: number, currentValue) => {
+ let result: number = previousValue;
+ switch (currentValue.vote) {
+ case Vote.UPVOTE:
+ result += 1;
+ break;
+ case Vote.DOWNVOTE:
+ result -= 1;
+ break;
+ }
+ return result;
+ },
+ 0,
+ );
const answer: Answer = {
- content: data.content,
- createdAt: data.createdAt,
- id: data.id,
- numComments: data._count.comments,
+ content: answerData.content,
+ createdAt: answerData.createdAt,
+ id: answerData.id,
+ numComments: answerData._count.comments,
numVotes: votes,
- user: userName,
+ user: answerData.user?.name ?? '',
};
return answer;
- });
- }
+ },
})
.mutation('create', {
input: z.object({
@@ -93,7 +143,7 @@ export const questionsAnswerRouter = createProtectedRouter()
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const {content, id} = input
+ const { content, id } = input;
const answerToUpdate = await ctx.prisma.questionsAnswer.findUnique({
where: {
@@ -128,7 +178,8 @@ export const questionsAnswerRouter = createProtectedRouter()
const answerToDelete = await ctx.prisma.questionsAnswer.findUnique({
where: {
id: input.id,
- },});
+ },
+ });
if (answerToDelete?.id !== userId) {
throw new TRPCError({
@@ -150,11 +201,11 @@ export const questionsAnswerRouter = createProtectedRouter()
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const {answerId} = input
+ const { answerId } = input;
return await ctx.prisma.questionsAnswerVote.findUnique({
where: {
- answerId_userId : { answerId, userId },
+ answerId_userId: { answerId, userId },
},
});
},
@@ -182,7 +233,7 @@ export const questionsAnswerRouter = createProtectedRouter()
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const {id, vote} = input
+ const { id, vote } = input;
const voteToUpdate = await ctx.prisma.questionsAnswerVote.findUnique({
where: {
@@ -217,7 +268,8 @@ export const questionsAnswerRouter = createProtectedRouter()
const voteToDelete = await ctx.prisma.questionsAnswerVote.findUnique({
where: {
id: input.id,
- },});
+ },
+ });
if (voteToDelete?.id !== userId) {
throw new TRPCError({
@@ -232,4 +284,4 @@ export const questionsAnswerRouter = createProtectedRouter()
},
});
},
- });
\ No newline at end of file
+ });
diff --git a/apps/portal/src/server/router/questions-question-comment-router.ts b/apps/portal/src/server/router/questions-question-comment-router.ts
index 12f2bc21..82345f06 100644
--- a/apps/portal/src/server/router/questions-question-comment-router.ts
+++ b/apps/portal/src/server/router/questions-question-comment-router.ts
@@ -12,56 +12,51 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
questionId: z.string(),
}),
async resolve({ ctx, input }) {
- const questionCommentsData = await ctx.prisma.questionsQuestionComment.findMany({
- include: {
- user: {
- select: {
- name: true,
+ const questionCommentsData =
+ await ctx.prisma.questionsQuestionComment.findMany({
+ include: {
+ user: {
+ select: {
+ name: true,
+ },
+ },
+ votes: true,
},
- },
- votes: true,
- },
- orderBy: {
- createdAt: 'desc',
- },
- where: {
- ...input,
- },
- });
- return questionCommentsData.map((data) => {
- const votes:number = data.votes.reduce(
- (previousValue:number, currentValue) => {
- let result:number = previousValue;
-
- switch(currentValue.vote) {
- case Vote.UPVOTE:
- result += 1
- break;
- case Vote.DOWNVOTE:
- result -= 1
- break;
- }
- return result;
- },
- 0
+ orderBy: {
+ createdAt: 'desc',
+ },
+ where: {
+ ...input,
+ },
+ });
+ return questionCommentsData.map((data) => {
+ const votes: number = data.votes.reduce(
+ (previousValue: number, currentValue) => {
+ let result: number = previousValue;
+
+ switch (currentValue.vote) {
+ case Vote.UPVOTE:
+ result += 1;
+ break;
+ case Vote.DOWNVOTE:
+ result -= 1;
+ break;
+ }
+ return result;
+ },
+ 0,
);
- let userName = "";
-
- if (data.user) {
- userName = data.user.name!;
- }
-
- const questionComment: QuestionComment = {
- content: data.content,
- createdAt: data.createdAt,
- id: data.id,
- numVotes: votes,
- user: userName,
- };
- return questionComment;
- });
- }
+ const questionComment: QuestionComment = {
+ content: data.content,
+ createdAt: data.createdAt,
+ id: data.id,
+ numVotes: votes,
+ user: data.user?.name ?? '',
+ };
+ return questionComment;
+ });
+ },
})
.mutation('create', {
input: z.object({
@@ -87,11 +82,12 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const questionCommentToUpdate = await ctx.prisma.questionsQuestionComment.findUnique({
- where: {
- id: input.id,
- },
- });
+ const questionCommentToUpdate =
+ await ctx.prisma.questionsQuestionComment.findUnique({
+ where: {
+ id: input.id,
+ },
+ });
if (questionCommentToUpdate?.id !== userId) {
throw new TRPCError({
@@ -117,11 +113,12 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const questionCommentToDelete = await ctx.prisma.questionsQuestionComment.findUnique({
- where: {
- id: input.id,
- },
- });
+ const questionCommentToDelete =
+ await ctx.prisma.questionsQuestionComment.findUnique({
+ where: {
+ id: input.id,
+ },
+ });
if (questionCommentToDelete?.id !== userId) {
throw new TRPCError({
@@ -143,11 +140,11 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const {questionCommentId} = input
+ const { questionCommentId } = input;
return await ctx.prisma.questionsQuestionCommentVote.findUnique({
where: {
- questionCommentId_userId : {questionCommentId,userId },
+ questionCommentId_userId: { questionCommentId, userId },
},
});
},
@@ -175,13 +172,14 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const {id, vote} = input
+ const { id, vote } = input;
- const voteToUpdate = await ctx.prisma.questionsQuestionCommentVote.findUnique({
- where: {
- id: input.id,
- },
- });
+ const voteToUpdate =
+ await ctx.prisma.questionsQuestionCommentVote.findUnique({
+ where: {
+ id: input.id,
+ },
+ });
if (voteToUpdate?.id !== userId) {
throw new TRPCError({
@@ -207,10 +205,12 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const voteToDelete = await ctx.prisma.questionsQuestionCommentVote.findUnique({
- where: {
- id: input.id,
- },});
+ const voteToDelete =
+ await ctx.prisma.questionsQuestionCommentVote.findUnique({
+ where: {
+ id: input.id,
+ },
+ });
if (voteToDelete?.id !== userId) {
throw new TRPCError({
@@ -225,4 +225,4 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
},
});
},
- });
\ No newline at end of file
+ });
diff --git a/apps/portal/src/server/router/questions-question-router.ts b/apps/portal/src/server/router/questions-question-router.ts
index 8918f036..bd65474a 100644
--- a/apps/portal/src/server/router/questions-question-router.ts
+++ b/apps/portal/src/server/router/questions-question-router.ts
@@ -1,5 +1,5 @@
import { z } from 'zod';
-import {QuestionsQuestionType, Vote } from '@prisma/client';
+import { QuestionsQuestionType, Vote } from '@prisma/client';
import { TRPCError } from '@trpc/server';
import { createProtectedRouter } from './context';
@@ -17,28 +17,29 @@ export const questionsQuestionRouter = createProtectedRouter()
async resolve({ ctx, input }) {
const questionsData = await ctx.prisma.questionsQuestion.findMany({
include: {
- _count: {
- select: {
- answers: true,
- comments: true,
+ _count: {
+ select: {
+ answers: true,
+ comments: true,
+ },
},
- },
- encounters: {
- select: {
- company: true,
- location: true,
- role: true,
+ encounters: {
+ select: {
+ company: true,
+ location: true,
+ role: true,
+ seenAt: true,
+ },
},
- },
- user: {
- select: {
- name: true,
+ user: {
+ select: {
+ name: true,
+ },
},
- },
- votes: true,
+ votes: true,
},
orderBy: {
- createdAt: 'desc',
+ createdAt: 'desc',
},
where: {
questionType: input.questionType,
@@ -47,68 +48,159 @@ export const questionsQuestionRouter = createProtectedRouter()
return questionsData
.filter((data) => {
for (let i = 0; i < data.encounters.length; i++) {
- const encounter = data.encounters[i]
- const matchCompany = (!input.company || (encounter.company === input.company));
- const matchLocation = (!input.location || (encounter.location === input.location));
- const matchRole = (!input.company || (encounter.role === input.role));
- if (matchCompany && matchLocation && matchRole) {return true};
+ const encounter = data.encounters[i];
+ const matchCompany =
+ !input.company || encounter.company === input.company;
+ const matchLocation =
+ !input.location || encounter.location === input.location;
+ const matchRole = !input.company || encounter.role === input.role;
+ if (matchCompany && matchLocation && matchRole) {
+ return true;
+ }
}
return false;
})
.map((data) => {
- const votes:number = data.votes.reduce(
- (previousValue:number, currentValue) => {
- let result:number = previousValue;
+ const votes: number = data.votes.reduce(
+ (previousValue: number, currentValue) => {
+ let result: number = previousValue;
- switch(currentValue.vote) {
- case Vote.UPVOTE:
- result += 1
- break;
- case Vote.DOWNVOTE:
- result -= 1
- break;
+ switch (currentValue.vote) {
+ case Vote.UPVOTE:
+ result += 1;
+ break;
+ case Vote.DOWNVOTE:
+ result -= 1;
+ break;
}
return result;
},
- 0
- );
-
- let userName = "";
-
- if (data.user) {
- userName = data.user.name!;
- }
+ 0,
+ );
const question: Question = {
- company: "",
+ company: data.encounters[0].company,
content: data.content,
id: data.id,
- location: "",
+ location: data.encounters[0].location ?? 'Unknown location',
numAnswers: data._count.answers,
numComments: data._count.comments,
numVotes: votes,
- role: "",
+ role: data.encounters[0].role ?? 'Unknown role',
+ seenAt: data.encounters[0].seenAt,
+ type: data.questionType,
updatedAt: data.updatedAt,
- user: userName,
+ user: data.user?.name ?? '',
};
return question;
+ });
+ },
+ })
+ .query('getQuestionById', {
+ input: z.object({
+ id: z.string(),
+ }),
+ async resolve({ ctx, input }) {
+ const questionData = await ctx.prisma.questionsQuestion.findUnique({
+ include: {
+ _count: {
+ select: {
+ answers: true,
+ comments: true,
+ },
+ },
+ encounters: {
+ select: {
+ company: true,
+ location: true,
+ role: true,
+ seenAt: true,
+ },
+ },
+ user: {
+ select: {
+ name: true,
+ },
+ },
+ votes: true,
+ },
+ where: {
+ id: input.id,
+ },
});
- }
+ if (!questionData) {
+ throw new TRPCError({
+ code: 'NOT_FOUND',
+ message: 'Question not found',
+ });
+ }
+ const votes: number = questionData.votes.reduce(
+ (previousValue: number, currentValue) => {
+ let result: number = previousValue;
+
+ switch (currentValue.vote) {
+ case Vote.UPVOTE:
+ result += 1;
+ break;
+ case Vote.DOWNVOTE:
+ result -= 1;
+ break;
+ }
+ return result;
+ },
+ 0,
+ );
+
+ const question: Question = {
+ company: questionData.encounters[0].company,
+ content: questionData.content,
+ id: questionData.id,
+ location: questionData.encounters[0].location ?? 'Unknown location',
+ numAnswers: questionData._count.answers,
+ numComments: questionData._count.comments,
+ numVotes: votes,
+ role: questionData.encounters[0].role ?? 'Unknown role',
+ seenAt: questionData.encounters[0].seenAt,
+ type: questionData.questionType,
+ updatedAt: questionData.updatedAt,
+ user: questionData.user?.name ?? '',
+ };
+ return question;
+ },
})
.mutation('create', {
input: z.object({
+ company: z.string(),
content: z.string(),
+ location: z.string(),
questionType: z.nativeEnum(QuestionsQuestionType),
+ role: z.string().optional(),
+ seenAt: z.date(),
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- return await ctx.prisma.questionsQuestion.create({
+ const question = await ctx.prisma.questionsQuestion.create({
data: {
- ...input,
+ content: input.content,
+ questionType: input.questionType,
userId,
},
});
+
+ // Create question encounter
+ await ctx.prisma.questionsQuestionEncounter.create({
+ data: {
+ company: input.company,
+ location: input.location,
+ questionId: question.id,
+ role: input.role,
+ seenAt: input.seenAt,
+ userId,
+ },
+ });
+
+ return question;
},
})
.mutation('update', {
@@ -116,7 +208,6 @@ export const questionsQuestionRouter = createProtectedRouter()
content: z.string().optional(),
id: z.string(),
questionType: z.nativeEnum(QuestionsQuestionType).optional(),
-
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
@@ -179,11 +270,11 @@ export const questionsQuestionRouter = createProtectedRouter()
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const {questionId} = input
+ const { questionId } = input;
return await ctx.prisma.questionsQuestionVote.findUnique({
where: {
- questionId_userId : {questionId,userId }
+ questionId_userId: { questionId, userId },
},
});
},
@@ -211,7 +302,7 @@ export const questionsQuestionRouter = createProtectedRouter()
}),
async resolve({ ctx, input }) {
const userId = ctx.session?.user?.id;
- const {id, vote} = input
+ const { id, vote } = input;
const voteToUpdate = await ctx.prisma.questionsQuestionVote.findUnique({
where: {
@@ -246,7 +337,8 @@ export const questionsQuestionRouter = createProtectedRouter()
const voteToDelete = await ctx.prisma.questionsQuestionVote.findUnique({
where: {
id: input.id,
- },});
+ },
+ });
if (voteToDelete?.id !== userId) {
throw new TRPCError({
@@ -261,4 +353,4 @@ export const questionsQuestionRouter = createProtectedRouter()
},
});
},
- });
\ No newline at end of file
+ });
diff --git a/apps/portal/src/types/questions.d.ts b/apps/portal/src/types/questions.d.ts
index 0d60ca76..3797bf38 100644
--- a/apps/portal/src/types/questions.d.ts
+++ b/apps/portal/src/types/questions.d.ts
@@ -8,14 +8,19 @@ export type Question = {
numComments: number;
numVotes: number;
role: string;
+ seenAt: Date;
+ type: stringl;
updatedAt: Date;
user: string;
};
export type AnswerComment = {
content: string;
+ createdAt: Date;
id: string;
numVotes: number;
+ updatedAt: Date;
+ user: string;
};
export type Answer = {
@@ -24,6 +29,7 @@ export type Answer = {
id: string;
numComments: number;
numVotes: number;
+ user: string;
};
export type QuestionComment = {
diff --git a/apps/portal/src/utils/questions/constants.ts b/apps/portal/src/utils/questions/constants.ts
index 966e1a1f..155359d5 100644
--- a/apps/portal/src/utils/questions/constants.ts
+++ b/apps/portal/src/utils/questions/constants.ts
@@ -1,3 +1,5 @@
+import type { QuestionsQuestionType } from '@prisma/client';
+
import type { FilterChoices } from '~/components/questions/filter/FilterSection';
export const COMPANIES: FilterChoices = [
@@ -12,18 +14,18 @@ export const COMPANIES: FilterChoices = [
];
// Code, design, behavioral
-export const QUESTION_TYPES: FilterChoices = [
+export const QUESTION_TYPES: FilterChoices
= [
{
label: 'Coding',
- value: 'coding',
+ value: 'CODING',
},
{
label: 'Design',
- value: 'design',
+ value: 'SYSTEM_DESIGN',
},
{
label: 'Behavioral',
- value: 'behavioral',
+ value: 'BEHAVIORAL',
},
];
diff --git a/apps/portal/src/utils/questions/createSlug.ts b/apps/portal/src/utils/questions/createSlug.ts
new file mode 100644
index 00000000..9c8a81ae
--- /dev/null
+++ b/apps/portal/src/utils/questions/createSlug.ts
@@ -0,0 +1,7 @@
+export default function createSlug(content: string) {
+ return content
+ .toLowerCase()
+ .replace(/[^a-z0-9]+/g, '-')
+ .replace(/(^-|-$)+/g, '')
+ .substring(0, 100);
+}
diff --git a/apps/portal/src/utils/questions/useSearchFilter.ts b/apps/portal/src/utils/questions/useSearchFilter.ts
index 711f5ead..392a69c8 100644
--- a/apps/portal/src/utils/questions/useSearchFilter.ts
+++ b/apps/portal/src/utils/questions/useSearchFilter.ts
@@ -1,14 +1,14 @@
import { useRouter } from 'next/router';
import { useCallback, useEffect, useState } from 'react';
-export const useSearchFilter = (
+export const useSearchFilter = (
name: string,
- defaultValues?: Array,
+ defaultValues?: Array,
) => {
const [isInitialized, setIsInitialized] = useState(false);
const router = useRouter();
- const [filters, setFilters] = useState>(defaultValues || []);
+ const [filters, setFilters] = useState>(defaultValues || []);
useEffect(() => {
if (router.isReady && !isInitialized) {
@@ -16,7 +16,7 @@ export const useSearchFilter = (
const query = router.query[name];
if (query) {
const queryValues = Array.isArray(query) ? query : [query];
- setFilters(queryValues);
+ setFilters(queryValues as Array);
} else {
// Try to load from local storage
const localStorageValue = localStorage.getItem(name);
@@ -37,7 +37,7 @@ export const useSearchFilter = (
}, [isInitialized, name, router]);
const setFiltersCallback = useCallback(
- (newFilters: Array) => {
+ (newFilters: Array) => {
setFilters(newFilters);
localStorage.setItem(name, JSON.stringify(newFilters));
router.replace({
@@ -54,14 +54,17 @@ export const useSearchFilter = (
return [filters, setFiltersCallback, isInitialized] as const;
};
-export const useSearchFilterSingle = (name: string, defaultValue: string) => {
+export const useSearchFilterSingle = (
+ name: string,
+ defaultValue: Value,
+) => {
const [filters, setFilters, isInitialized] = useSearchFilter(name, [
defaultValue,
]);
return [
filters[0],
- (value: string) => {
+ (value: Value) => {
setFilters([value]);
},
isInitialized,