-
+
+
+ {/* Hero section */}
+
+
+
+ Choosing offers
+
+ made easier
+
+
+
+ Analyze your offers using profiles from fellow software engineers.
+
+
- in
-
- setCompanyFilter(value)}
- />
+
+
+
+ {/* Alternating Feature Sections */}
+
+
+
+
+ }
+ imageAlt="Offer table page"
+ imageSrc="https://tailwindui.com/img/component-images/inbox-app-screenshot-1.jpg"
+ title="Choosing an offer needs context"
+ />
+
+
+
+ }
+ imageAlt="Customer profile user interface"
+ imageSrc="https://tailwindui.com/img/component-images/inbox-app-screenshot-2.jpg"
+ title="Better understand your offers"
+ />
+
+
+
+ }
+ imageAlt="Offer table page"
+ imageSrc="https://tailwindui.com/img/component-images/inbox-app-screenshot-1.jpg"
+ title="Stay informed of recent offers"
+ />
+
+
+
+ {/* Gradient Feature Section */}
+
+
+
+ Your privacy is our priority.
+
+
+ All offer profiles are anonymized and we do not store information
+ about your personal identity.
+
+
+ {features.map((feature) => (
+
+
+
+
+
+
+
+
+ {feature.name}
+
+
+ {feature.description}
+
+
+
+ ))}
+
+
+
+
+ {/* CTA Section */}
+
+
+
+ Ready to get started?
+
+ Create your own offer profile today.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ © 2022 Tech Interview Handbook Offer Profile Repository. All
+ rights reserved.
+
-
-
-
-
-
+
+
);
}
diff --git a/apps/portal/src/pages/offers/profile/[offerProfileId].tsx b/apps/portal/src/pages/offers/profile/[offerProfileId].tsx
index ae9956b0..8933112c 100644
--- a/apps/portal/src/pages/offers/profile/[offerProfileId].tsx
+++ b/apps/portal/src/pages/offers/profile/[offerProfileId].tsx
@@ -10,6 +10,9 @@ import type {
BackgroundDisplayData,
OfferDisplayData,
} from '~/components/offers/types';
+import { HOME_URL } from '~/components/offers/types';
+import type { JobTitleType } from '~/components/shared/JobTitles';
+import { getLabelForJobTitleType } from '~/components/shared/JobTitles';
import { useToast } from '~/../../../packages/ui/dist';
import { convertMoneyToString } from '~/utils/offers/currency';
@@ -44,7 +47,7 @@ export default function OfferProfile() {
enabled: typeof offerProfileId === 'string',
onSuccess: (data: Profile) => {
if (!data) {
- router.push('/offers');
+ router.push(HOME_URL);
}
// If the profile is not editable with a wrong token, redirect to the profile page
if (!data?.isEditable && token !== '') {
@@ -62,7 +65,9 @@ export default function OfferProfile() {
companyName: res.company.name,
id: res.offersFullTime.id,
jobLevel: res.offersFullTime.level,
- jobTitle: res.offersFullTime.title,
+ jobTitle: getLabelForJobTitleType(
+ res.offersFullTime.title as JobTitleType,
+ ),
location: res.location,
negotiationStrategy: res.negotiationStrategy,
otherComment: res.comments,
@@ -77,7 +82,9 @@ export default function OfferProfile() {
const filteredOffer: OfferDisplayData = {
companyName: res.company.name,
id: res.offersIntern!.id,
- jobTitle: res.offersIntern!.title,
+ jobTitle: getLabelForJobTitleType(
+ res.offersIntern!.title as JobTitleType,
+ ),
location: res.location,
monthlySalary: convertMoneyToString(
res.offersIntern!.monthlySalary,
@@ -107,7 +114,9 @@ export default function OfferProfile() {
companyName: experience.company?.name,
duration: experience.durationInMonths,
jobLevel: experience.level,
- jobTitle: experience.title,
+ jobTitle: experience.title
+ ? getLabelForJobTitleType(experience.title as JobTitleType)
+ : null,
monthlySalary: experience.monthlySalary
? convertMoneyToString(experience.monthlySalary)
: null,
@@ -140,7 +149,7 @@ export default function OfferProfile() {
},
onSuccess: () => {
trpcContext.invalidateQueries(['offers.profile.listOne']);
- router.push('/offers');
+ router.push(HOME_URL);
showToast({
title: `Offers profile successfully deleted!`,
variant: 'success',
diff --git a/apps/portal/src/pages/questions/browse.tsx b/apps/portal/src/pages/questions/browse.tsx
index 163d4842..cb895f27 100644
--- a/apps/portal/src/pages/questions/browse.tsx
+++ b/apps/portal/src/pages/questions/browse.tsx
@@ -5,24 +5,22 @@ import { useEffect, useMemo, useState } from 'react';
import { Bars3BottomLeftIcon } from '@heroicons/react/20/solid';
import { NoSymbolIcon } from '@heroicons/react/24/outline';
import type { QuestionsQuestionType } from '@prisma/client';
-import { Button, SlideOut, Typeahead } from '@tih/ui';
+import { Button, SlideOut } from '@tih/ui';
import QuestionOverviewCard from '~/components/questions/card/question/QuestionOverviewCard';
import ContributeQuestionCard from '~/components/questions/ContributeQuestionCard';
+import type { FilterOption } from '~/components/questions/filter/FilterSection';
import FilterSection from '~/components/questions/filter/FilterSection';
import QuestionSearchBar from '~/components/questions/QuestionSearchBar';
+import CompanyTypeahead from '~/components/questions/typeahead/CompanyTypeahead';
+import LocationTypeahead from '~/components/questions/typeahead/LocationTypeahead';
+import RoleTypeahead from '~/components/questions/typeahead/RoleTypeahead';
import type { QuestionAge } from '~/utils/questions/constants';
import { SORT_TYPES } from '~/utils/questions/constants';
import { SORT_ORDERS } from '~/utils/questions/constants';
import { APP_TITLE } from '~/utils/questions/constants';
-import { ROLES } from '~/utils/questions/constants';
-import {
- COMPANIES,
- LOCATIONS,
- QUESTION_AGES,
- QUESTION_TYPES,
-} from '~/utils/questions/constants';
+import { QUESTION_AGES, QUESTION_TYPES } from '~/utils/questions/constants';
import createSlug from '~/utils/questions/createSlug';
import {
useSearchParam,
@@ -148,12 +146,18 @@ export default function QuestionsBrowsePage() {
: undefined;
}, [selectedQuestionAge]);
- const { data: questions } = trpc.useQuery(
+ const {
+ data: questionsQueryData,
+ fetchNextPage,
+ hasNextPage,
+ isFetchingNextPage,
+ } = trpc.useInfiniteQuery(
[
'questions.questions.getQuestionsByFilter',
{
companyNames: selectedCompanies,
endDate: today,
+ limit: 10,
locations: selectedLocations,
questionTypes: selectedQuestionTypes,
roles: selectedRoles,
@@ -163,10 +167,21 @@ export default function QuestionsBrowsePage() {
},
],
{
+ getNextPageParam: (lastPage) => lastPage.nextCursor,
keepPreviousData: true,
},
);
+ const questionCount = useMemo(() => {
+ if (!questionsQueryData) {
+ return undefined;
+ }
+ return questionsQueryData.pages.reduce(
+ (acc, page) => acc + page.data.length,
+ 0,
+ );
+ }, [questionsQueryData]);
+
const utils = trpc.useContext();
const { mutate: createQuestion } = trpc.useMutation(
'questions.questions.create',
@@ -180,12 +195,17 @@ export default function QuestionsBrowsePage() {
const [loaded, setLoaded] = useState(false);
const [filterDrawerOpen, setFilterDrawerOpen] = useState(false);
- const companyFilterOptions = useMemo(() => {
- return COMPANIES.map((company) => ({
- ...company,
- checked: selectedCompanies.includes(company.value),
- }));
- }, [selectedCompanies]);
+ const [selectedCompanyOptions, setSelectedCompanyOptions] = useState<
+ Array
+ >([]);
+
+ const [selectedRoleOptions, setSelectedRoleOptions] = useState<
+ Array
+ >([]);
+
+ const [selectedLocationOptions, setSelectedLocationOptions] = useState<
+ Array
+ >([]);
const questionTypeFilterOptions = useMemo(() => {
return QUESTION_TYPES.map((questionType) => ({
@@ -201,20 +221,6 @@ export default function QuestionsBrowsePage() {
}));
}, [selectedQuestionAge]);
- const roleFilterOptions = useMemo(() => {
- return ROLES.map((role) => ({
- ...role,
- checked: selectedRoles.includes(role.value),
- }));
- }, [selectedRoles]);
-
- const locationFilterOptions = useMemo(() => {
- return LOCATIONS.map((location) => ({
- ...location,
- checked: selectedLocations.includes(location.value),
- }));
- }, [selectedLocations]);
-
const areSearchOptionsInitialized = useMemo(() => {
return (
areCompaniesInitialized &&
@@ -287,35 +293,89 @@ export default function QuestionsBrowsePage() {
setSelectedQuestionAge('all');
setSelectedRoles([]);
setSelectedLocations([]);
+ setSelectedCompanyOptions([]);
+ setSelectedRoleOptions([]);
+ setSelectedLocationOptions([]);
}}
/>
(
- (
+ {
+ return !selectedCompanyOptions.some((selectedOption) => {
+ return selectedOption.value === option.value;
+ });
+ }}
isLabelHidden={true}
- label="Companies"
- options={options}
placeholder="Search companies"
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- onQueryChange={() => {}}
- onSelect={({ value }) => {
- onOptionChange(value, true);
+ onSelect={(option) => {
+ onOptionChange({
+ ...option,
+ checked: true,
+ });
}}
/>
)}
- onOptionChange={(optionValue, checked) => {
- if (checked) {
- setSelectedCompanies([...selectedCompanies, optionValue]);
+ onOptionChange={(option) => {
+ if (option.checked) {
+ setSelectedCompanies([...selectedCompanies, option.label]);
+ setSelectedCompanyOptions((prevOptions) => [
+ ...prevOptions,
+ { ...option, checked: true },
+ ]);
} else {
setSelectedCompanies(
- selectedCompanies.filter((company) => company !== optionValue),
+ selectedCompanies.filter((company) => company !== option.label),
+ );
+ setSelectedCompanyOptions((prevOptions) =>
+ prevOptions.filter(
+ (prevOption) => prevOption.label !== option.label,
+ ),
+ );
+ }
+ }}
+ />
+ (
+ {
+ return !selectedRoleOptions.some((selectedOption) => {
+ return selectedOption.value === option.value;
+ });
+ }}
+ isLabelHidden={true}
+ placeholder="Search roles"
+ onSelect={(option) => {
+ onOptionChange({
+ ...option,
+ checked: true,
+ });
+ }}
+ />
+ )}
+ onOptionChange={(option) => {
+ if (option.checked) {
+ setSelectedRoles([...selectedRoles, option.value]);
+ setSelectedRoleOptions((prevOptions) => [
+ ...prevOptions,
+ { ...option, checked: true },
+ ]);
+ } else {
+ setSelectedRoles(
+ selectedCompanies.filter((role) => role !== option.value),
+ );
+ setSelectedRoleOptions((prevOptions) =>
+ prevOptions.filter(
+ (prevOption) => prevOption.value !== option.value,
+ ),
);
}
}}
@@ -324,13 +384,13 @@ export default function QuestionsBrowsePage() {
label="Question types"
options={questionTypeFilterOptions}
showAll={true}
- onOptionChange={(optionValue, checked) => {
- if (checked) {
- setSelectedQuestionTypes([...selectedQuestionTypes, optionValue]);
+ onOptionChange={(option) => {
+ if (option.checked) {
+ setSelectedQuestionTypes([...selectedQuestionTypes, option.value]);
} else {
setSelectedQuestionTypes(
selectedQuestionTypes.filter(
- (questionType) => questionType !== optionValue,
+ (questionType) => questionType !== option.value,
),
);
}
@@ -341,68 +401,47 @@ export default function QuestionsBrowsePage() {
label="Question age"
options={questionAgeFilterOptions}
showAll={true}
- onOptionChange={(optionValue) => {
- setSelectedQuestionAge(optionValue);
+ onOptionChange={({ value }) => {
+ setSelectedQuestionAge(value);
}}
/>
(
- (
+ {}}
- onSelect={({ value }) => {
- onOptionChange(value, true);
+ clearOnSelect={true}
+ filterOption={(option) => {
+ return !selectedLocationOptions.some((selectedOption) => {
+ return selectedOption.value === option.value;
+ });
}}
- />
- )}
- onOptionChange={(optionValue, checked) => {
- if (checked) {
- setSelectedRoles([...selectedRoles, optionValue]);
- } else {
- setSelectedRoles(
- selectedRoles.filter((role) => role !== optionValue),
- );
- }
- }}
- />
- (
- {}}
- onSelect={({ value }) => {
- onOptionChange(value, true);
+ onSelect={(option) => {
+ onOptionChange({
+ ...option,
+ checked: true,
+ });
}}
/>
)}
- onOptionChange={(optionValue, checked) => {
- if (checked) {
- setSelectedLocations([...selectedLocations, optionValue]);
+ onOptionChange={(option) => {
+ if (option.checked) {
+ setSelectedLocations([...selectedLocations, option.value]);
+ setSelectedLocationOptions((prevOptions) => [
+ ...prevOptions,
+ { ...option, checked: true },
+ ]);
} else {
setSelectedLocations(
- selectedLocations.filter((location) => location !== optionValue),
+ selectedLocations.filter((role) => role !== option.value),
+ );
+ setSelectedLocationOptions((prevOptions) =>
+ prevOptions.filter(
+ (prevOption) => prevOption.value !== option.value,
+ ),
);
}
}}
@@ -443,29 +482,50 @@ export default function QuestionsBrowsePage() {
onSortOrderChange={setSortOrder}
onSortTypeChange={setSortType}
/>
-
- {(questions ?? []).map((question) => (
-
- ))}
- {questions?.length === 0 && (
+
+ {(questionsQueryData?.pages ?? []).flatMap(
+ ({ data: questions }) =>
+ questions.map((question) => (
+
+ )),
+ )}
+
{
+ fetchNextPage();
+ }}
+ />
+ {questionCount === 0 && (
Nothing found.
diff --git a/apps/portal/src/pages/resumes/submit.tsx b/apps/portal/src/pages/resumes/submit.tsx
index c851cafa..7901056b 100644
--- a/apps/portal/src/pages/resumes/submit.tsx
+++ b/apps/portal/src/pages/resumes/submit.tsx
@@ -86,10 +86,16 @@ export default function SubmitResumeForm({
setValue,
reset,
watch,
+ clearErrors,
formState: { errors, isDirty, dirtyFields },
} = useForm
({
defaultValues: {
+ additionalInfo: '',
+ experience: '',
isChecked: false,
+ location: '',
+ role: '',
+ title: '',
...initFormDetails,
},
});
@@ -296,7 +302,7 @@ export default function SubmitResumeForm({
options={ROLES}
placeholder=" "
required={true}
- onChange={(val) => setValue('role', val)}
+ onChange={(val) => onValueChange('role', val)}
/>
setValue('experience', val)}
+ onChange={(val) => onValueChange('experience', val)}
/>
setValue('location', val)}
+ onChange={(val) => onValueChange('location', val)}
/>
{/* Upload resume form */}
{isNewForm && (
@@ -335,6 +341,16 @@ export default function SubmitResumeForm({
: 'border-slate-300',
'flex cursor-pointer justify-center rounded-md border-2 border-dashed bg-slate-100 py-4',
)}>
+
{resumeFile == null ? (
@@ -345,29 +361,15 @@ export default function SubmitResumeForm({
{resumeFile.name}
)}
-
-
- Drop file here
- or
-
- {resumeFile == null
- ? 'Select file'
- : 'Replace file'}
-
-
-
-
+
+ Drop file here
+ or
+
+ {resumeFile == null ? 'Select file' : 'Replace file'}
+
+
PDF up to {FILE_SIZE_LIMIT_MB}MB
@@ -394,8 +396,18 @@ export default function SubmitResumeForm({
setValue('isChecked', val)}
+ onChange={(val) => {
+ if (val) {
+ clearErrors('isChecked');
+ }
+ setValue('isChecked', val);
+ }}
/>
>
)}
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 75977b41..63a9ede4 100644
--- a/apps/portal/src/server/router/questions-answer-comment-router.ts
+++ b/apps/portal/src/server/router/questions-answer-comment-router.ts
@@ -166,13 +166,29 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
const { answerCommentId, vote } = input;
- return await ctx.prisma.questionsAnswerCommentVote.create({
- data: {
- answerCommentId,
- userId,
- vote,
- },
- });
+ const incrementValue = vote === Vote.UPVOTE ? 1 : -1;
+
+ const [answerCommentVote] = await ctx.prisma.$transaction([
+ ctx.prisma.questionsAnswerCommentVote.create({
+ data: {
+ answerCommentId,
+ userId,
+ vote,
+ },
+ }),
+ ctx.prisma.questionsAnswerComment.update({
+ data: {
+ upvotes: {
+ increment: incrementValue,
+ },
+ },
+ where: {
+ id: answerCommentId,
+ },
+ }),
+ ]);
+
+ return answerCommentVote;
},
})
.mutation('updateVote', {
@@ -198,14 +214,30 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
});
}
- return await ctx.prisma.questionsAnswerCommentVote.update({
- data: {
- vote,
- },
- where: {
- id,
- },
- });
+ const incrementValue = vote === Vote.UPVOTE ? 2 : -2;
+
+ const [answerCommentVote] = await ctx.prisma.$transaction([
+ ctx.prisma.questionsAnswerCommentVote.update({
+ data: {
+ vote,
+ },
+ where: {
+ id,
+ },
+ }),
+ ctx.prisma.questionsAnswerComment.update({
+ data: {
+ upvotes: {
+ increment: incrementValue,
+ },
+ },
+ where: {
+ id: voteToUpdate.answerCommentId,
+ },
+ }),
+ ]);
+
+ return answerCommentVote;
},
})
.mutation('deleteVote', {
@@ -229,10 +261,26 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
});
}
- return await ctx.prisma.questionsAnswerCommentVote.delete({
- where: {
- id: input.id,
- },
- });
+ const incrementValue = voteToDelete.vote === Vote.UPVOTE ? -1 : 1;
+
+ const [answerCommentVote] = await ctx.prisma.$transaction([
+ ctx.prisma.questionsAnswerCommentVote.delete({
+ where: {
+ id: input.id,
+ },
+ }),
+ ctx.prisma.questionsAnswerComment.update({
+ data: {
+ upvotes: {
+ increment: incrementValue,
+ },
+ },
+ where: {
+ id: voteToDelete.answerCommentId,
+ },
+ }),
+ ]);
+ return answerCommentVote;
+
},
});
diff --git a/apps/portal/src/server/router/questions-answer-router.ts b/apps/portal/src/server/router/questions-answer-router.ts
index 5d386854..e2318ba7 100644
--- a/apps/portal/src/server/router/questions-answer-router.ts
+++ b/apps/portal/src/server/router/questions-answer-router.ts
@@ -229,13 +229,28 @@ export const questionsAnswerRouter = createProtectedRouter()
const { answerId, vote } = input;
- return await ctx.prisma.questionsAnswerVote.create({
- data: {
- answerId,
- userId,
- vote,
- },
- });
+ const incrementValue = vote === Vote.UPVOTE ? 1 : -1;
+
+ const [answerVote] = await ctx.prisma.$transaction([
+ ctx.prisma.questionsAnswerVote.create({
+ data: {
+ answerId,
+ userId,
+ vote,
+ },
+ }),
+ ctx.prisma.questionsAnswer.update({
+ data: {
+ upvotes: {
+ increment: incrementValue,
+ },
+ },
+ where: {
+ id: answerId,
+ },
+ }),
+ ]);
+ return answerVote;
},
})
.mutation('updateVote', {
@@ -260,14 +275,30 @@ export const questionsAnswerRouter = createProtectedRouter()
});
}
- return await ctx.prisma.questionsAnswerVote.update({
- data: {
- vote,
- },
- where: {
- id,
- },
- });
+ const incrementValue = vote === Vote.UPVOTE ? 2 : -2;
+
+ const [questionsAnswerVote] = await ctx.prisma.$transaction([
+ ctx.prisma.questionsAnswerVote.update({
+ data: {
+ vote,
+ },
+ where: {
+ id,
+ },
+ }),
+ ctx.prisma.questionsAnswer.update({
+ data: {
+ upvotes: {
+ increment: incrementValue,
+ },
+ },
+ where: {
+ id: voteToUpdate.answerId,
+ },
+ }),
+ ]);
+
+ return questionsAnswerVote;
},
})
.mutation('deleteVote', {
@@ -290,10 +321,26 @@ export const questionsAnswerRouter = createProtectedRouter()
});
}
- return await ctx.prisma.questionsAnswerVote.delete({
- where: {
- id: input.id,
- },
- });
+ const incrementValue = voteToDelete.vote === Vote.UPVOTE ? -1 : 1;
+
+ const [questionsAnswerVote] = await ctx.prisma.$transaction([
+ ctx.prisma.questionsAnswerVote.delete({
+ where: {
+ id: input.id,
+ },
+ }),
+ ctx.prisma.questionsAnswer.update({
+ data: {
+ upvotes: {
+ increment: incrementValue,
+ },
+ },
+ where: {
+ id: voteToDelete.answerId,
+ },
+ }),
+ ]);
+ return questionsAnswerVote;
+
},
});
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 e2f786f9..28cf3b9d 100644
--- a/apps/portal/src/server/router/questions-question-comment-router.ts
+++ b/apps/portal/src/server/router/questions-question-comment-router.ts
@@ -166,13 +166,28 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
const userId = ctx.session?.user?.id;
const { questionCommentId, vote } = input;
- return await ctx.prisma.questionsQuestionCommentVote.create({
- data: {
- questionCommentId,
- userId,
- vote,
- },
- });
+ const incrementValue: number = vote === Vote.UPVOTE ? 1 : -1;
+
+ const [ questionCommentVote ] = await ctx.prisma.$transaction([
+ ctx.prisma.questionsQuestionCommentVote.create({
+ data: {
+ questionCommentId,
+ userId,
+ vote,
+ },
+ }),
+ ctx.prisma.questionsQuestionComment.update({
+ data: {
+ upvotes: {
+ increment: incrementValue,
+ },
+ },
+ where: {
+ id: questionCommentId,
+ },
+ }),
+ ]);
+ return questionCommentVote;
},
})
.mutation('updateVote', {
@@ -198,14 +213,30 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
});
}
- return await ctx.prisma.questionsQuestionCommentVote.update({
- data: {
- vote,
- },
- where: {
- id,
- },
- });
+ const incrementValue = vote === Vote.UPVOTE ? 2 : -2;
+
+ const [questionCommentVote] = await ctx.prisma.$transaction([
+ ctx.prisma.questionsQuestionCommentVote.update({
+ data: {
+ vote,
+ },
+ where: {
+ id,
+ },
+ }),
+ ctx.prisma.questionsQuestionComment.update({
+ data: {
+ upvotes: {
+ increment: incrementValue,
+ },
+ },
+ where: {
+ id: voteToUpdate.questionCommentId,
+ },
+ }),
+ ]);
+
+ return questionCommentVote;
},
})
.mutation('deleteVote', {
@@ -229,10 +260,25 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
});
}
- return await ctx.prisma.questionsQuestionCommentVote.delete({
- where: {
- id: input.id,
- },
- });
+ const incrementValue = voteToDelete.vote === Vote.UPVOTE ? -1 : 1;
+
+ const [questionCommentVote] = await ctx.prisma.$transaction([
+ ctx.prisma.questionsQuestionCommentVote.delete({
+ where: {
+ id: input.id,
+ },
+ }),
+ ctx.prisma.questionsQuestionComment.update({
+ data: {
+ upvotes: {
+ increment: incrementValue,
+ },
+ },
+ where: {
+ id: voteToDelete.questionCommentId,
+ },
+ }),
+ ]);
+ return questionCommentVote;
},
});
diff --git a/apps/portal/src/server/router/questions-question-encounter-router.ts b/apps/portal/src/server/router/questions-question-encounter-router.ts
index 1f328dc6..8fa4a0e4 100644
--- a/apps/portal/src/server/router/questions-question-encounter-router.ts
+++ b/apps/portal/src/server/router/questions-question-encounter-router.ts
@@ -25,9 +25,13 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
const locationCounts: Record = {};
const roleCounts: Record = {};
+ let latestSeenAt = questionEncountersData[0].seenAt;
+
for (let i = 0; i < questionEncountersData.length; i++) {
const encounter = questionEncountersData[i];
+ latestSeenAt = latestSeenAt < encounter.seenAt ? encounter.seenAt : latestSeenAt;
+
if (!(encounter.company!.name in companyCounts)) {
companyCounts[encounter.company!.name] = 1;
}
@@ -46,6 +50,7 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
const questionEncounter: AggregatedQuestionEncounter = {
companyCounts,
+ latestSeenAt,
locationCounts,
roleCounts,
};
@@ -72,7 +77,6 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
},
})
.mutation('update', {
- //
input: z.object({
companyId: z.string().optional(),
id: z.string(),
diff --git a/apps/portal/src/server/router/questions-question-router.ts b/apps/portal/src/server/router/questions-question-router.ts
index 3768b852..3ea33bce 100644
--- a/apps/portal/src/server/router/questions-question-router.ts
+++ b/apps/portal/src/server/router/questions-question-router.ts
@@ -11,9 +11,16 @@ export const questionsQuestionRouter = createProtectedRouter()
.query('getQuestionsByFilter', {
input: z.object({
companyNames: z.string().array(),
+ cursor: z
+ .object({
+ idCursor: z.string().optional(),
+ lastSeenCursor: z.date().nullish().optional(),
+ upvoteCursor: z.number().optional(),
+ })
+ .nullish(),
endDate: z.date().default(new Date()),
+ limit: z.number().min(1).default(50),
locations: z.string().array(),
- pageSize: z.number().default(50),
questionTypes: z.nativeEnum(QuestionsQuestionType).array(),
roles: z.string().array(),
sortOrder: z.nativeEnum(SortOrder),
@@ -21,16 +28,34 @@ export const questionsQuestionRouter = createProtectedRouter()
startDate: z.date().optional(),
}),
async resolve({ ctx, input }) {
+ const { cursor } = input;
+
const sortCondition =
input.sortType === SortType.TOP
- ? {
- upvotes: input.sortOrder,
- }
- : {
- lastSeenAt: input.sortOrder,
- };
+ ? [
+ {
+ upvotes: input.sortOrder,
+ },
+ {
+ id: input.sortOrder,
+ },
+ ]
+ : [
+ {
+ lastSeenAt: input.sortOrder,
+ },
+ {
+ id: input.sortOrder,
+ },
+ ];
const questionsData = await ctx.prisma.questionsQuestion.findMany({
+ cursor:
+ cursor !== undefined
+ ? {
+ id: cursor ? cursor!.idCursor : undefined,
+ }
+ : undefined,
include: {
_count: {
select: {
@@ -53,9 +78,8 @@ export const questionsQuestionRouter = createProtectedRouter()
},
votes: true,
},
- orderBy: {
- ...sortCondition,
- },
+ orderBy: sortCondition,
+ take: input.limit + 1,
where: {
...(input.questionTypes.length > 0
? {
@@ -98,7 +122,7 @@ export const questionsQuestionRouter = createProtectedRouter()
},
});
- return questionsData.map((data) => {
+ const processedQuestionsData = questionsData.map((data) => {
const votes: number = data.votes.reduce(
(previousValue: number, currentValue) => {
let result: number = previousValue;
@@ -116,23 +140,78 @@ export const questionsQuestionRouter = createProtectedRouter()
0,
);
+ const companyCounts: Record = {};
+ const locationCounts: Record = {};
+ const roleCounts: Record = {};
+
+ let latestSeenAt = data.encounters[0].seenAt;
+
+ for (let i = 0; i < data.encounters.length; i++) {
+ const encounter = data.encounters[i];
+
+ latestSeenAt =
+ latestSeenAt < encounter.seenAt ? encounter.seenAt : latestSeenAt;
+
+ if (!(encounter.company!.name in companyCounts)) {
+ companyCounts[encounter.company!.name] = 1;
+ }
+ companyCounts[encounter.company!.name] += 1;
+
+ if (!(encounter.location in locationCounts)) {
+ locationCounts[encounter.location] = 1;
+ }
+ locationCounts[encounter.location] += 1;
+
+ if (!(encounter.role in roleCounts)) {
+ roleCounts[encounter.role] = 1;
+ }
+ roleCounts[encounter.role] += 1;
+ }
+
const question: Question = {
- company: data.encounters[0].company!.name ?? 'Unknown company',
+ aggregatedQuestionEncounters: {
+ companyCounts,
+ latestSeenAt,
+ locationCounts,
+ roleCounts,
+ },
content: data.content,
id: data.id,
- location: data.encounters[0].location ?? 'Unknown location',
numAnswers: data._count.answers,
numComments: data._count.comments,
numVotes: votes,
receivedCount: data.encounters.length,
- role: data.encounters[0].role ?? 'Unknown role',
- seenAt: data.encounters[0].seenAt,
+ seenAt: latestSeenAt,
type: data.questionType,
updatedAt: data.updatedAt,
user: data.user?.name ?? '',
};
return question;
});
+
+ let nextCursor: typeof cursor | undefined = undefined;
+
+ if (questionsData.length > input.limit) {
+ const nextItem = questionsData.pop()!;
+ processedQuestionsData.pop();
+
+ const nextIdCursor: string | undefined = nextItem.id;
+ const nextLastSeenCursor =
+ input.sortType === SortType.NEW ? nextItem.lastSeenAt : undefined;
+ const nextUpvoteCursor =
+ input.sortType === SortType.TOP ? nextItem.upvotes : undefined;
+
+ nextCursor = {
+ idCursor: nextIdCursor,
+ lastSeenCursor: nextLastSeenCursor,
+ upvoteCursor: nextUpvoteCursor,
+ };
+ }
+
+ return {
+ data: processedQuestionsData,
+ nextCursor,
+ };
},
})
.query('getQuestionById', {
@@ -190,16 +269,45 @@ export const questionsQuestionRouter = createProtectedRouter()
0,
);
+ const companyCounts: Record = {};
+ const locationCounts: Record = {};
+ const roleCounts: Record = {};
+
+ let latestSeenAt = questionData.encounters[0].seenAt;
+
+ for (const encounter of questionData.encounters) {
+ latestSeenAt =
+ latestSeenAt < encounter.seenAt ? encounter.seenAt : latestSeenAt;
+
+ if (!(encounter.company!.name in companyCounts)) {
+ companyCounts[encounter.company!.name] = 1;
+ }
+ companyCounts[encounter.company!.name] += 1;
+
+ if (!(encounter.location in locationCounts)) {
+ locationCounts[encounter.location] = 1;
+ }
+ locationCounts[encounter.location] += 1;
+
+ if (!(encounter.role in roleCounts)) {
+ roleCounts[encounter.role] = 1;
+ }
+ roleCounts[encounter.role] += 1;
+ }
+
const question: Question = {
- company: questionData.encounters[0].company!.name ?? 'Unknown company',
+ aggregatedQuestionEncounters: {
+ companyCounts,
+ latestSeenAt,
+ locationCounts,
+ roleCounts,
+ },
content: questionData.content,
id: questionData.id,
- location: questionData.encounters[0].location ?? 'Unknown location',
numAnswers: questionData._count.answers,
numComments: questionData._count.comments,
numVotes: votes,
receivedCount: questionData.encounters.length,
- role: questionData.encounters[0].role ?? 'Unknown role',
seenAt: questionData.encounters[0].seenAt,
type: questionData.questionType,
updatedAt: questionData.updatedAt,
diff --git a/apps/portal/src/types/questions.d.ts b/apps/portal/src/types/questions.d.ts
index 4157eb37..aea8d31e 100644
--- a/apps/portal/src/types/questions.d.ts
+++ b/apps/portal/src/types/questions.d.ts
@@ -1,16 +1,13 @@
import type { QuestionsQuestionType } from '@prisma/client';
export type Question = {
- // TODO: company, location, role maps
- company: string;
+ aggregatedQuestionEncounters: AggregatedQuestionEncounter;
content: string;
id: string;
- location: string;
numAnswers: number;
numComments: number;
numVotes: number;
receivedCount: number;
- role: string;
seenAt: Date;
type: QuestionsQuestionType;
updatedAt: Date;
@@ -19,6 +16,7 @@ export type Question = {
export type AggregatedQuestionEncounter = {
companyCounts: Record;
+ latestSeenAt: Date;
locationCounts: Record;
roleCounts: Record;
};
diff --git a/apps/portal/src/utils/offers/time.tsx b/apps/portal/src/utils/offers/time.tsx
index 4f68adeb..ffa3c545 100644
--- a/apps/portal/src/utils/offers/time.tsx
+++ b/apps/portal/src/utils/offers/time.tsx
@@ -25,9 +25,11 @@ export function timeSinceNow(date: Date | number | string) {
}
interval = seconds / 60;
if (interval > 1) {
- return `${Math.floor(interval)} minutes`;
+ const time: number = Math.floor(interval);
+ return time === 1 ? `${time} minute` : `${time} minutes`;
}
- return `${Math.floor(interval)} seconds`;
+ const time: number = Math.floor(interval);
+ return time === 1 ? `${time} second` : `${time} seconds`;
}
export function formatDate(value: Date | number | string) {
diff --git a/packages/ui/src/CheckboxInput/CheckboxInput.tsx b/packages/ui/src/CheckboxInput/CheckboxInput.tsx
index edeb9d3a..fec43b7e 100644
--- a/packages/ui/src/CheckboxInput/CheckboxInput.tsx
+++ b/packages/ui/src/CheckboxInput/CheckboxInput.tsx
@@ -7,6 +7,7 @@ type Props = Readonly<{
defaultValue?: boolean;
description?: string;
disabled?: boolean;
+ errorMessage?: string;
label: string;
name?: string;
onChange?: (
@@ -21,6 +22,7 @@ function CheckboxInput(
defaultValue,
description,
disabled = false,
+ errorMessage,
label,
name,
value,
@@ -30,59 +32,67 @@ function CheckboxInput(
) {
const id = useId();
const descriptionId = useId();
+ const errorId = useId();
return (
-
-
- {
- onChange?.(event.target.checked, event);
- }
- : undefined
- }
- />
-
-
-
- {label}
-
- {description && (
-
+
+
+
- {description}
-
- )}
+ defaultChecked={defaultValue}
+ disabled={disabled}
+ id={id}
+ name={name}
+ type="checkbox"
+ onChange={(event) => {
+ if (!onChange) {
+ return;
+ }
+
+ onChange(event.target.checked, event);
+ }}
+ />
+
+
+
+ {label}
+
+ {description && (
+
+ {description}
+
+ )}
+
+ {errorMessage && (
+
+ {errorMessage}
+
+ )}
);
}