mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-15 02:33:50 +08:00
[questions][fix] fix landing page company param (#477)
This commit is contained in:
@ -3,6 +3,7 @@ import { ArrowSmallRightIcon } from '@heroicons/react/24/outline';
|
|||||||
import type { QuestionsQuestionType } from '@prisma/client';
|
import type { QuestionsQuestionType } from '@prisma/client';
|
||||||
import { Button, Select } from '@tih/ui';
|
import { Button, Select } from '@tih/ui';
|
||||||
|
|
||||||
|
import { companyOptionToSlug } from '~/utils/questions/companySlug';
|
||||||
import { QUESTION_TYPES } from '~/utils/questions/constants';
|
import { QUESTION_TYPES } from '~/utils/questions/constants';
|
||||||
import useDefaultCompany from '~/utils/questions/useDefaultCompany';
|
import useDefaultCompany from '~/utils/questions/useDefaultCompany';
|
||||||
import useDefaultLocation from '~/utils/questions/useDefaultLocation';
|
import useDefaultLocation from '~/utils/questions/useDefaultLocation';
|
||||||
@ -12,7 +13,7 @@ import CompanyTypeahead from './typeahead/CompanyTypeahead';
|
|||||||
import LocationTypeahead from './typeahead/LocationTypeahead';
|
import LocationTypeahead from './typeahead/LocationTypeahead';
|
||||||
|
|
||||||
export type LandingQueryData = {
|
export type LandingQueryData = {
|
||||||
company: string;
|
companySlug: string;
|
||||||
location: string;
|
location: string;
|
||||||
questionType: QuestionsQuestionType;
|
questionType: QuestionsQuestionType;
|
||||||
};
|
};
|
||||||
@ -71,7 +72,7 @@ export default function LandingComponent({
|
|||||||
className="h-40 w-40"
|
className="h-40 w-40"
|
||||||
src="/bank-logo.png"
|
src="/bank-logo.png"
|
||||||
/>
|
/>
|
||||||
<h1 className="text-4xl font-bold text-slate-900 text-center">
|
<h1 className="text-center text-4xl font-bold text-slate-900">
|
||||||
Tech Interview Question Bank
|
Tech Interview Question Bank
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
@ -124,7 +125,7 @@ export default function LandingComponent({
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (company !== undefined && location !== undefined) {
|
if (company !== undefined && location !== undefined) {
|
||||||
return handleLandingQuery({
|
return handleLandingQuery({
|
||||||
company: company.label,
|
companySlug: companyOptionToSlug(company),
|
||||||
location: location.value,
|
location: location.value,
|
||||||
questionType,
|
questionType,
|
||||||
});
|
});
|
||||||
|
@ -18,6 +18,10 @@ import LocationTypeahead from '~/components/questions/typeahead/LocationTypeahea
|
|||||||
import RoleTypeahead from '~/components/questions/typeahead/RoleTypeahead';
|
import RoleTypeahead from '~/components/questions/typeahead/RoleTypeahead';
|
||||||
import { JobTitleLabels } from '~/components/shared/JobTitles';
|
import { JobTitleLabels } from '~/components/shared/JobTitles';
|
||||||
|
|
||||||
|
import {
|
||||||
|
companyOptionToSlug,
|
||||||
|
slugToCompanyOption,
|
||||||
|
} from '~/utils/questions/companySlug';
|
||||||
import type { QuestionAge } from '~/utils/questions/constants';
|
import type { QuestionAge } from '~/utils/questions/constants';
|
||||||
import { APP_TITLE } from '~/utils/questions/constants';
|
import { APP_TITLE } from '~/utils/questions/constants';
|
||||||
import { QUESTION_AGES, QUESTION_TYPES } from '~/utils/questions/constants';
|
import { QUESTION_AGES, QUESTION_TYPES } from '~/utils/questions/constants';
|
||||||
@ -288,15 +292,7 @@ export default function QuestionsBrowsePage() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const selectedCompanyOptions = useMemo(() => {
|
const selectedCompanyOptions = useMemo(() => {
|
||||||
return selectedCompanySlugs.map((company) => {
|
return selectedCompanySlugs.map(slugToCompanyOption);
|
||||||
const [id, label] = company.split('_');
|
|
||||||
return {
|
|
||||||
checked: true,
|
|
||||||
id,
|
|
||||||
label,
|
|
||||||
value: id,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}, [selectedCompanySlugs]);
|
}, [selectedCompanySlugs]);
|
||||||
|
|
||||||
const selectedRoleOptions = useMemo(() => {
|
const selectedRoleOptions = useMemo(() => {
|
||||||
@ -363,12 +359,12 @@ export default function QuestionsBrowsePage() {
|
|||||||
if (option.checked) {
|
if (option.checked) {
|
||||||
setSelectedCompanySlugs([
|
setSelectedCompanySlugs([
|
||||||
...selectedCompanySlugs,
|
...selectedCompanySlugs,
|
||||||
`${option.id}_${option.label}`,
|
companyOptionToSlug(option),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
setSelectedCompanySlugs(
|
setSelectedCompanySlugs(
|
||||||
selectedCompanySlugs.filter(
|
selectedCompanySlugs.filter(
|
||||||
(companySlug) => companySlug !== `${option.id}_${option.label}`,
|
(companySlug) => companySlug !== companyOptionToSlug(option),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,13 @@ export default function QuestionsHomePage() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const handleLandingQuery = async (data: LandingQueryData) => {
|
const handleLandingQuery = async (data: LandingQueryData) => {
|
||||||
const { company, location, questionType } = data;
|
const { companySlug, location, questionType } = data;
|
||||||
|
|
||||||
// Go to browse page
|
// Go to browse page
|
||||||
router.push({
|
router.push({
|
||||||
pathname: '/questions/browse',
|
pathname: '/questions/browse',
|
||||||
query: {
|
query: {
|
||||||
companies: [company],
|
companies: [companySlug],
|
||||||
locations: [location],
|
locations: [location],
|
||||||
questionTypes: [questionType],
|
questionTypes: [questionType],
|
||||||
},
|
},
|
||||||
|
18
apps/portal/src/utils/questions/companySlug.ts
Normal file
18
apps/portal/src/utils/questions/companySlug.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import type {
|
||||||
|
FilterChoice,
|
||||||
|
FilterOption,
|
||||||
|
} from '~/components/questions/filter/FilterSection';
|
||||||
|
|
||||||
|
export function companyOptionToSlug(option: FilterChoice): string {
|
||||||
|
return `${option.id}_${option.label}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function slugToCompanyOption(slug: string): FilterOption {
|
||||||
|
const [id, label] = slug.split('_');
|
||||||
|
return {
|
||||||
|
checked: true,
|
||||||
|
id,
|
||||||
|
label,
|
||||||
|
value: id,
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue
Block a user