Skip to content

Commit

Permalink
feat :: 기업페이지 useQueryString 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
KANGYONGSU23 committed Nov 26, 2023
1 parent d4d5565 commit e653fce
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
30 changes: 14 additions & 16 deletions src/app/companies/page.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
"use client";

import Pagination from "@/components/common/Pagination";
import TextFiled from "@/components/common/TextFiled";
import useForm from "@/hook/useForm";
import { useEffect, useState } from "react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import CompanyCard from "@/components/company/CompanyCard";
import Pagination from "@/components/common/Pagination";
import useForm from "@/hook/useForm";
import { CompaniesQueryType } from "@/hook/useQueryString/type";
import { useQueryString } from "@/hook/useQueryString/useQueryString";

export default function CompanyListPage() {
const getParams = useSearchParams();
const [page, setPage] = useState(Number(getParams.get("page")));
const navigator = useRouter();
const pathname = usePathname();
const { getQueryString, setQueryString } = useQueryString<CompaniesQueryType>(
{
page: "1",
name: "",
}
);
const { state: searchState, onChange: onChangeSearch } = useForm<{
search: string | undefined;
}>({
search: getParams.get("name")?.toString(),
search: getQueryString("name"),
});

const onSearch = () => {
navigator.push(`${pathname}?page=${page}&name=${searchState.search}`);
};

useEffect(onSearch, [page]);

return (
<div className="w-full mt-[68px]">
<div className="flex items-center justify-between w-full py-5">
Expand All @@ -37,7 +33,9 @@ export default function CompanyListPage() {
onChange={onChangeSearch}
name="search"
customType="Search"
enterEvent={onSearch}
enterEvent={() => {
setQueryString({ name: searchState.search });
}}
/>
</div>
<CompanyCard />
Expand Down
1 change: 1 addition & 0 deletions src/components/common/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function Pagination() {
getQueryStringEntry("job_code"),
getQueryStringEntry("tech_code"),
getQueryStringEntry("name"),
getQueryStringEntry("winter_intern"),
]
.filter((item) => item)
.join("&");
Expand Down
19 changes: 9 additions & 10 deletions src/components/common/SearchDropDown.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
"use client";

import React, { useEffect, useState } from "react";
import { GetCode } from "@/apis/code";
import { useDropDown } from "@/hook/useDropDown";
import { Icon } from "@team-return/design-system";
import TextFiled from "./TextFiled";
import useForm from "@/hook/useForm";
import Chips from "./Chips";
import { GetCode } from "@/apis/code";
import { TechCodeResponensType } from "@/util/type";
import GhostBtn from "./Button/GhostBtn";
import { useQueryString } from "@/hook/useQueryString/useQueryString";
import {
RecruitmentsQueryType,
setQueryStringType,
RecruitmentsQueryType
} from "@/hook/useQueryString/type";
import { useQueryString } from "@/hook/useQueryString/useQueryString";
import { TechCodeResponensType } from "@/util/type";
import { Icon } from "@team-return/design-system";
import React, { useEffect, useState } from "react";
import GhostBtn from "./Button/GhostBtn";
import Chips from "./Chips";
import TextFiled from "./TextFiled";

interface PropsType {
title: string;
Expand Down
13 changes: 5 additions & 8 deletions src/hook/useQueryString/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ export interface RecruitmentsQueryType extends QueryStringType {
job_code: string;
tech_code: string;
name: string;
winter_intern: "true" | "false" | '';
winter_intern: "true" | "false" | "";
}

export type setQueryStringType = {
page?: string;
job_code?: string;
tech_code?: string;
name?: string;
winter_intern?: "true" | "false";
};
export interface CompaniesQueryType extends QueryStringType {
page: string;
name: string;
}

0 comments on commit e653fce

Please sign in to comment.