diff --git a/src/actions/job.action.ts b/src/actions/job.action.ts index f67bd786..2f946989 100644 --- a/src/actions/job.action.ts +++ b/src/actions/job.action.ts @@ -170,6 +170,7 @@ export const getRecommendedJobs = withServerActionAsyncCatcher< where: { category: category, id: { not: id }, + isVerifiedJob: true, expired: false, }, orderBy: { @@ -295,7 +296,10 @@ export const getCityFilters = async () => { export const getRecentJobs = async () => { try { const recentJobs = await prisma.job.findMany({ - where: { expired: false }, + where: { + isVerifiedJob: true, + expired: false, + }, orderBy: { postedAt: 'desc', }, diff --git a/src/hooks/useFilterCheck.ts b/src/hooks/useFilterCheck.ts new file mode 100644 index 00000000..d625754b --- /dev/null +++ b/src/hooks/useFilterCheck.ts @@ -0,0 +1,17 @@ +import { useMemo } from 'react'; +import { JobQuerySchemaType } from '@/lib/validators/jobs.validator'; + +export const useFilterCheck = (formValues: JobQuerySchemaType) => { + const isAnyFilterSelected = useMemo(() => { + return ['workmode', 'EmpType', 'salaryrange', 'city'].some((key) => { + const value = formValues[key as keyof JobQuerySchemaType]; + if (Array.isArray(value)) { + return value.length > 0; + } + // For non-array values, check if they're truthy + return !!value; + }); + }, [formValues]); + + return isAnyFilterSelected; +}; diff --git a/src/layouts/job-filters.tsx b/src/layouts/job-filters.tsx index 1e5ae10c..7826f7cf 100644 --- a/src/layouts/job-filters.tsx +++ b/src/layouts/job-filters.tsx @@ -30,7 +30,8 @@ import _ from 'lodash'; import { DEFAULT_PAGE } from '@/config/app.config'; import { getCityFilters } from '@/actions/job.action'; import { X } from 'lucide-react'; - +import { useFilterCheck } from '@/hooks/useFilterCheck'; +import { AnimatePresence, motion } from 'framer-motion'; const JobFilters = ({ searchParams }: { searchParams: JobQuerySchemaType }) => { const [cityFilters, setCityFilters] = useState([]); @@ -47,6 +48,7 @@ const JobFilters = ({ searchParams }: { searchParams: JobQuerySchemaType }) => { }); const formValues = form.watch(); + const isAnyFilterSelected = useFilterCheck(formValues); async function fetchCityFilters() { const cities = await getCityFilters(); @@ -82,12 +84,20 @@ const JobFilters = ({ searchParams }: { searchParams: JobQuerySchemaType }) => { >

All Filters

- + + {isAnyFilterSelected && ( + + Clear Filters + + )} +